* Cavern of Souls - Fixed a bug where spells cast with first ability can't be countered.

This commit is contained in:
LevelX2 2015-04-14 16:31:11 +02:00
parent 7529d6f207
commit e747b48b41
4 changed files with 53 additions and 21 deletions

View file

@ -34,6 +34,7 @@ import mage.ConditionalMana;
import mage.MageObject;
import mage.Mana;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.common.AsEntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.common.TapSourceCost;
@ -80,8 +81,9 @@ public class CavernOfSouls extends CardImpl {
this.addAbility(new ColorlessManaAbility());
// {T}: Add one mana of any color to your mana pool. Spend this mana only to cast a creature spell of the chosen type, and that spell can't be countered.
this.addAbility(new ConditionalAnyColorManaAbility(new TapSourceCost(), 1, new CavernOfSoulsManaBuilder(), true), new CavernOfSoulsWatcher());
this.addAbility(new SimpleStaticAbility(Zone.ALL, new CavernOfSoulsCantCounterEffect()));
Ability ability = new ConditionalAnyColorManaAbility(new TapSourceCost(), 1, new CavernOfSoulsManaBuilder(), true);
this.addAbility(ability, new CavernOfSoulsWatcher(ability.getOriginalId()));
this.addAbility(new SimpleStaticAbility(Zone.ALL, new CavernOfSoulsCantCounterEffect()));
}
public CavernOfSouls(final CavernOfSouls card) {
@ -146,14 +148,12 @@ class CavernOfSoulsManaBuilder extends ConditionalManaBuilder {
if (controller != null && sourceObject != null) {
game.informPlayers(controller.getName() + " produces " + mana.toString() + " with " + sourceObject.getLogName() +
" (can only be spend to cast for creatures of type " + creatureType + " and that spell can't be countered)");
}
}
return super.setMana(mana, source, game);
}
@Override
public ConditionalMana build(Object... options) {
this.mana.setFlag(true); // indicates that the mana is from second ability
return new CavernOfSoulsConditionalMana(this.mana, creatureType);
}
@ -196,15 +196,18 @@ class CavernOfSoulsManaCondition extends CreatureCastManaCondition {
class CavernOfSoulsWatcher extends Watcher {
public List<UUID> spells = new ArrayList<>();
public CavernOfSoulsWatcher() {
super("ManaPaidFromCavernOfSoulsWatcher", WatcherScope.GAME);
private List<UUID> spells = new ArrayList<>();
private final String originalId;
public CavernOfSoulsWatcher(UUID originalId) {
super("ManaPaidFromCavernOfSoulsWatcher", WatcherScope.CARD);
this.originalId = originalId.toString();
}
public CavernOfSoulsWatcher(final CavernOfSoulsWatcher watcher) {
super(watcher);
this.spells.addAll(watcher.spells);
this.originalId = watcher.originalId;
}
@Override
@ -215,13 +218,15 @@ class CavernOfSoulsWatcher extends Watcher {
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.MANA_PAYED) {
MageObject object = game.getObject(event.getSourceId());
// TODO: Replace identification by name by better method that also works if ability is copied from other land with other name
if (object != null && object.getName().equals("Cavern of Souls") && event.getFlag()) {
if (event.getData() != null && event.getData().equals(originalId)) {
spells.add(event.getTargetId());
}
}
}
public boolean spellCantBeCountered(UUID spellId) {
return spells.contains(spellId);
}
@Override
public void reset() {
@ -267,8 +272,8 @@ class CavernOfSoulsCantCounterEffect extends ContinuousRuleModifyingEffectImpl {
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
CavernOfSoulsWatcher watcher = (CavernOfSoulsWatcher) game.getState().getWatchers().get("ManaPaidFromCavernOfSoulsWatcher");
CavernOfSoulsWatcher watcher = (CavernOfSoulsWatcher) game.getState().getWatchers().get("ManaPaidFromCavernOfSoulsWatcher", source.getSourceId());
Spell spell = game.getStack().getSpell(event.getTargetId());
return spell != null && watcher.spells.contains(spell.getId());
return spell != null && watcher != null && watcher.spellCantBeCountered(spell.getId());
}
}

View file

@ -66,16 +66,22 @@ public class ConditionalMana extends Mana implements Serializable {
*/
private UUID manaProducerId;
/**
* UUID originalId of source ability for mana.
*/
private UUID manaProducerOriginalId;
public ConditionalMana(Mana mana) {
super(mana);
}
public ConditionalMana(ConditionalMana conditionalMana) {
public ConditionalMana(final ConditionalMana conditionalMana) {
super(conditionalMana);
conditions = conditionalMana.conditions;
scope = conditionalMana.scope;
staticText = conditionalMana.staticText;
manaProducerId = conditionalMana.manaProducerId;
manaProducerOriginalId = conditionalMana.manaProducerOriginalId;
}
public void addCondition(Condition condition) {
@ -154,6 +160,14 @@ public class ConditionalMana extends Mana implements Serializable {
public void setManaProducerId(UUID manaProducerId) {
this.manaProducerId = manaProducerId;
}
public UUID getManaProducerOriginalId() {
return manaProducerOriginalId;
}
public void setManaProducerOriginalId(UUID manaProducerOriginalId) {
this.manaProducerOriginalId = manaProducerOriginalId;
}
public void clear(ManaType manaType) {
switch(manaType) {

View file

@ -120,7 +120,9 @@ public class ManaPool implements Serializable {
}
boolean spendAnyMana = spendAnyMana(ability, game);
if (mana.get(manaType) > 0 || (spendAnyMana && mana.count() > 0)) {
game.fireEvent(new GameEvent(GameEvent.EventType.MANA_PAYED, ability.getId(), mana.getSourceId(), ability.getControllerId(), 0, mana.getFlag()));
GameEvent event = new GameEvent(GameEvent.EventType.MANA_PAYED, ability.getId(), mana.getSourceId(), ability.getControllerId(), 0, mana.getFlag());
event.setData(mana.getOriginalId().toString());
game.fireEvent(event);
if (spendAnyMana) {
mana.removeAny();
} else {
@ -354,13 +356,13 @@ public class ManaPool implements Serializable {
Mana mana = manaToAdd.copy();
if (!game.replaceEvent(new ManaEvent(EventType.ADD_MANA, source.getId(), source.getSourceId(), source.getControllerId(), mana))) {
if (mana instanceof ConditionalMana) {
ManaPoolItem item = new ManaPoolItem((ConditionalMana)mana, source.getSourceId());
ManaPoolItem item = new ManaPoolItem((ConditionalMana)mana, source.getSourceId(), source.getOriginalId());
if (emptyOnTurnsEnd) {
item.setDuration(Duration.EndOfTurn);
}
this.manaItems.add(item);
} else {
ManaPoolItem item = new ManaPoolItem(mana.getRed(), mana.getGreen(), mana.getBlue(), mana.getWhite(), mana.getBlack(), mana.getColorless(), source.getSourceId(), mana.getFlag());
ManaPoolItem item = new ManaPoolItem(mana.getRed(), mana.getGreen(), mana.getBlue(), mana.getWhite(), mana.getBlack(), mana.getColorless(), source.getSourceId(), source.getOriginalId(), mana.getFlag());
if (emptyOnTurnsEnd) {
item.setDuration(Duration.EndOfTurn);
}
@ -398,7 +400,9 @@ public class ManaPool implements Serializable {
for (ConditionalMana mana : getConditionalMana()) {
if (mana.get(manaType) > 0 && mana.apply(ability, game, mana.getManaProducerId())) {
mana.set(manaType, mana.get(manaType) - 1);
game.fireEvent(new GameEvent(GameEvent.EventType.MANA_PAYED, ability.getId(), mana.getManaProducerId(), ability.getControllerId(), 0, mana.getFlag()));
GameEvent event = new GameEvent(GameEvent.EventType.MANA_PAYED, ability.getId(), mana.getManaProducerId(), ability.getControllerId(), 0, mana.getFlag());
event.setData(mana.getManaProducerOriginalId().toString());
game.fireEvent(event);
break;
}
}

View file

@ -48,12 +48,13 @@ public class ManaPoolItem implements Serializable {
private int colorless = 0;
private ConditionalMana conditionalMana;
private UUID sourceId;
private UUID originalId; // originalId of the mana producing ability
private boolean flag = false;
private Duration duration;
public ManaPoolItem() {}
public ManaPoolItem(int red, int green, int blue, int white, int black, int colorless, UUID sourceId, boolean flag) {
public ManaPoolItem(int red, int green, int blue, int white, int black, int colorless, UUID sourceId, UUID originalId, boolean flag) {
this.red = red;
this.green = green;
this.blue = blue;
@ -61,14 +62,17 @@ public class ManaPoolItem implements Serializable {
this.black = black;
this.colorless = colorless;
this.sourceId = sourceId;
this.originalId = originalId;
this.flag = flag;
this.duration = Duration.EndOfStep;
}
public ManaPoolItem(ConditionalMana conditionalMana, UUID sourceId) {
public ManaPoolItem(ConditionalMana conditionalMana, UUID sourceId, UUID originalId) {
this.conditionalMana = conditionalMana;
this.sourceId = sourceId;
this.originalId = originalId;
this.conditionalMana.setManaProducerId(sourceId);
this.conditionalMana.setManaProducerOriginalId(originalId);
this.flag = conditionalMana.getFlag();
this.duration = Duration.EndOfStep;
}
@ -84,6 +88,7 @@ public class ManaPoolItem implements Serializable {
this.conditionalMana = item.conditionalMana.copy();
}
this.sourceId = item.sourceId;
this.originalId = item.originalId;
this.flag = item.flag;
this.duration = item.duration;
}
@ -96,6 +101,10 @@ public class ManaPoolItem implements Serializable {
return sourceId;
}
public UUID getOriginalId() {
return originalId;
}
public boolean getFlag() {
return flag;
}