* Commander - Fixed that the commander replacement effect did not work if the commander spell on the stack was exiled.

This commit is contained in:
LevelX2 2014-09-21 11:29:39 +02:00
parent 898f111533
commit 100decf7ce
3 changed files with 55 additions and 23 deletions

View file

@ -31,20 +31,22 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.WatcherScope;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.costs.AlternativeCostImpl; import mage.abilities.costs.AlternativeCostImpl;
import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.WatcherScope;
import mage.constants.Zone;
import mage.filter.FilterSpell; import mage.filter.FilterSpell;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType; import mage.game.events.GameEvent.EventType;
import mage.game.stack.Spell; import mage.game.stack.Spell;
import mage.players.Player;
import mage.target.TargetSpell; import mage.target.TargetSpell;
import mage.watchers.Watcher; import mage.watchers.Watcher;
@ -84,7 +86,7 @@ public class MindbreakTrap extends CardImpl {
class MindbreakTrapWatcher extends Watcher { class MindbreakTrapWatcher extends Watcher {
private Map<UUID, Integer> counts = new HashMap<UUID, Integer>(); private Map<UUID, Integer> counts = new HashMap<>();
public MindbreakTrapWatcher() { public MindbreakTrapWatcher() {
super("opponent cast three or more spells", WatcherScope.PLAYER); super("opponent cast three or more spells", WatcherScope.PLAYER);
@ -112,9 +114,10 @@ class MindbreakTrapWatcher extends Watcher {
int count = 1; int count = 1;
if (counts.containsKey(event.getPlayerId())) { if (counts.containsKey(event.getPlayerId())) {
count += counts.get(event.getPlayerId()); count += counts.get(event.getPlayerId());
if (count >= 3) if (count >= 3) {
condition = true; condition = true;
} }
}
counts.put(event.getPlayerId(), count); counts.put(event.getPlayerId(), count);
} }
} }
@ -130,7 +133,7 @@ class MindbreakTrapWatcher extends Watcher {
class MindbreakTrapAlternativeCost extends AlternativeCostImpl { class MindbreakTrapAlternativeCost extends AlternativeCostImpl {
public MindbreakTrapAlternativeCost() { public MindbreakTrapAlternativeCost() {
super("you may pay {0} rather than pay Mindbreak Trap's mana cost"); super("you may pay {0} rather than pay {this}'s mana cost");
this.add(new GenericManaCost(0)); this.add(new GenericManaCost(0));
} }
@ -154,7 +157,7 @@ class MindbreakTrapAlternativeCost extends AlternativeCostImpl {
@Override @Override
public String getText() { public String getText() {
return "If an opponent cast three or more spells this turn, you may pay {0} rather than pay Mindbreak Trap's mana cost"; return "If an opponent cast three or more spells this turn, you may pay {0} rather than pay {this}'s mana cost";
} }
} }
@ -171,18 +174,22 @@ class MindbreakEffect extends OneShotEffect{
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int affectedTargets = 0; int affectedTargets = 0;
if (targetPointer.getTargets(game, source).size() > 0) { if (targetPointer.getTargets(game, source).size() > 0) {
for (UUID spellId : targetPointer.getTargets(game, source)) { for (UUID spellId : targetPointer.getTargets(game, source)) {
Spell spell = game.getStack().getSpell(spellId); Spell spell = game.getStack().getSpell(spellId);
if (spell != null) { if (spell != null) {
spell.moveToExile(null, null, source.getSourceId(), game); controller.moveCardToExileWithInfo(spell, null, "", source.getSourceId(), game, Zone.STACK);
affectedTargets++; affectedTargets++;
} }
} }
} }
return affectedTargets > 0; return affectedTargets > 0;
} }
return false;
}
@Override @Override
public MindbreakEffect copy() { public MindbreakEffect copy() {

View file

@ -38,6 +38,7 @@ import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent; import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.game.stack.Spell;
import mage.players.Player; import mage.players.Player;
/** /**
@ -88,13 +89,21 @@ public class CommanderReplacementEffect extends ReplacementEffectImpl {
} }
} }
} else { } else {
Card card = game.getCard(event.getTargetId()); Card card = null;
if (card != null) { if (((ZoneChangeEvent)event).getFromZone().equals(Zone.STACK)) {
Spell spell = game.getStack().getSpell(event.getTargetId());
if (spell != null) {
card = game.getCard(spell.getSourceId());
}
} else {
card = game.getCard(event.getTargetId());
}
if (card != null) {
Player player = game.getPlayer(card.getOwnerId()); Player player = game.getPlayer(card.getOwnerId());
if (player != null && player.chooseUse(Outcome.Benefit, "Move commander to command zone?", game)){ if (player != null && player.chooseUse(Outcome.Benefit, "Move commander to command zone?", game)){
boolean result = card.moveToZone(Zone.COMMAND, source.getSourceId(), game, false); game.informPlayers(player.getName() + " moved his commander to the command zone instead");
return result; return card.moveToZone(Zone.COMMAND, source.getSourceId(), game, false);
} }
} }
} }
@ -104,10 +113,20 @@ public class CommanderReplacementEffect extends ReplacementEffectImpl {
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.ZONE_CHANGE && (((ZoneChangeEvent)event).getToZone() == Zone.GRAVEYARD || ((ZoneChangeEvent)event).getToZone() == Zone.EXILED)) { if (event.getType() == GameEvent.EventType.ZONE_CHANGE && (((ZoneChangeEvent)event).getToZone() == Zone.GRAVEYARD || ((ZoneChangeEvent)event).getToZone() == Zone.EXILED)) {
if(commanderId != null && commanderId.equals(event.getTargetId())){ if (commanderId != null) {
if (((ZoneChangeEvent)event).getFromZone().equals(Zone.STACK)) {
Spell spell = game.getStack().getSpell(event.getTargetId());
if (spell != null) {
if (commanderId.equals(spell.getSourceId())) {
return true; return true;
} }
} }
}
if(commanderId.equals(event.getTargetId())){
return true;
}
}
}
return false; return false;
} }

View file

@ -64,6 +64,7 @@ import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent; import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.PermanentCard; import mage.game.permanent.PermanentCard;
import mage.game.stack.Spell; import mage.game.stack.Spell;
import mage.game.stack.StackObject;
import mage.watchers.Watcher; import mage.watchers.Watcher;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -325,6 +326,11 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
game.getState().getCommand().remove((Commander)game.getObject(objectId)); game.getState().getCommand().remove((Commander)game.getObject(objectId));
break; break;
case STACK: case STACK:
StackObject stackObject = game.getStack().getStackObject(getId());
if (stackObject != null) {
game.getStack().remove(stackObject);
}
break;
case PICK: case PICK:
case BATTLEFIELD: // for sacrificing permanents case BATTLEFIELD: // for sacrificing permanents
break; break;