* 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.Entry;
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.costs.AlternativeCostImpl;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.OneShotEffect;
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.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.stack.Spell;
import mage.players.Player;
import mage.target.TargetSpell;
import mage.watchers.Watcher;
@ -84,7 +86,7 @@ public class MindbreakTrap extends CardImpl {
class MindbreakTrapWatcher extends Watcher {
private Map<UUID, Integer> counts = new HashMap<UUID, Integer>();
private Map<UUID, Integer> counts = new HashMap<>();
public MindbreakTrapWatcher() {
super("opponent cast three or more spells", WatcherScope.PLAYER);
@ -112,8 +114,9 @@ class MindbreakTrapWatcher extends Watcher {
int count = 1;
if (counts.containsKey(event.getPlayerId())) {
count += counts.get(event.getPlayerId());
if (count >= 3)
if (count >= 3) {
condition = true;
}
}
counts.put(event.getPlayerId(), count);
}
@ -130,7 +133,7 @@ class MindbreakTrapWatcher extends Watcher {
class MindbreakTrapAlternativeCost extends AlternativeCostImpl {
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));
}
@ -154,7 +157,7 @@ class MindbreakTrapAlternativeCost extends AlternativeCostImpl {
@Override
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,17 +174,21 @@ class MindbreakEffect extends OneShotEffect{
@Override
public boolean apply(Game game, Ability source) {
int affectedTargets = 0;
if (targetPointer.getTargets(game, source).size() > 0) {
for (UUID spellId : targetPointer.getTargets(game, source)) {
Spell spell = game.getStack().getSpell(spellId);
if (spell != null) {
spell.moveToExile(null, null, source.getSourceId(), game);
affectedTargets++;
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int affectedTargets = 0;
if (targetPointer.getTargets(game, source).size() > 0) {
for (UUID spellId : targetPointer.getTargets(game, source)) {
Spell spell = game.getStack().getSpell(spellId);
if (spell != null) {
controller.moveCardToExileWithInfo(spell, null, "", source.getSourceId(), game, Zone.STACK);
affectedTargets++;
}
}
}
return affectedTargets > 0;
}
return affectedTargets > 0;
return false;
}
@Override
@ -189,4 +196,4 @@ class MindbreakEffect extends OneShotEffect{
return new MindbreakEffect(this);
}
}
}

View file

@ -38,6 +38,7 @@ import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.game.stack.Spell;
import mage.players.Player;
/**
@ -88,13 +89,21 @@ public class CommanderReplacementEffect extends ReplacementEffectImpl {
}
}
} else {
Card card = game.getCard(event.getTargetId());
Card 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());
if (player != null && player.chooseUse(Outcome.Benefit, "Move commander to command zone?", game)){
boolean result = card.moveToZone(Zone.COMMAND, source.getSourceId(), game, false);
return result;
game.informPlayers(player.getName() + " moved his commander to the command zone instead");
return card.moveToZone(Zone.COMMAND, source.getSourceId(), game, false);
}
}
}
@ -104,8 +113,18 @@ public class CommanderReplacementEffect extends ReplacementEffectImpl {
@Override
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(commanderId != null && commanderId.equals(event.getTargetId())){
return true;
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;
}
}
}
if(commanderId.equals(event.getTargetId())){
return true;
}
}
}
return false;

View file

@ -64,6 +64,7 @@ import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.PermanentCard;
import mage.game.stack.Spell;
import mage.game.stack.StackObject;
import mage.watchers.Watcher;
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));
break;
case STACK:
StackObject stackObject = game.getStack().getStackObject(getId());
if (stackObject != null) {
game.getStack().remove(stackObject);
}
break;
case PICK:
case BATTLEFIELD: // for sacrificing permanents
break;