Handle tokens correctly in the new zone change code.

This commit is contained in:
Samuel Sandeen 2016-09-15 19:44:32 -04:00
parent 377a0edec9
commit 17d4d6c190
4 changed files with 93 additions and 129 deletions

View file

@ -83,11 +83,9 @@ public class ZonesHandler {
ZoneChangeEvent event = info.event;
Zone toZone = event.getToZone();
Card targetCard = getTargetCard(game, event.getTargetId());
if (targetCard == null) {
// This should never happen.
return;
}
Cards cards;
Cards cards = null;
// If we're moving a token it shouldn't be put into any zone as an object.
if (!(targetCard instanceof Permanent) && targetCard != null) {
if (targetCard instanceof MeldCard) {
cards = ((MeldCard) targetCard).getHalves();
} else {
@ -154,8 +152,9 @@ public class ZonesHandler {
default:
throw new UnsupportedOperationException("to Zone" + toZone.toString() + " not supported yet");
}
}
game.setZone(event.getTargetId(), event.getToZone());
if (targetCard instanceof MeldCard) {
if (targetCard instanceof MeldCard && cards != null) {
if (event.getToZone() != Zone.BATTLEFIELD) {
((MeldCard) targetCard).setMelded(false);
}

View file

@ -27,7 +27,6 @@
*/
package mage.game.permanent;
import java.util.ArrayList;
import java.util.UUID;
import mage.abilities.Abilities;
import mage.abilities.Ability;
@ -36,12 +35,8 @@ import mage.abilities.costs.mana.ManaCosts;
import mage.abilities.keyword.TransformAbility;
import mage.cards.Card;
import mage.cards.LevelerCard;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.ZoneChangeInfo;
import mage.game.ZonesHandler;
import mage.game.events.ZoneChangeEvent;
import mage.players.Player;
/**
* @author BetaSteward_at_googlemail.com
@ -147,31 +142,6 @@ public class PermanentCard extends PermanentImpl {
return card;
}
@Override
public boolean moveToZone(Zone toZone, UUID sourceId, Game game, boolean flag, ArrayList<UUID> appliedEffects) {
Zone fromZone = game.getState().getZone(objectId);
Player controller = game.getPlayer(controllerId);
if (controller != null) {
ZoneChangeEvent event = new ZoneChangeEvent(this, sourceId, controllerId, fromZone, toZone, appliedEffects);
ZoneChangeInfo zoneChangeInfo;
if (toZone == Zone.LIBRARY) {
zoneChangeInfo = new ZoneChangeInfo.Library(event, flag /* put on top */);
} else {
zoneChangeInfo = new ZoneChangeInfo(event);
}
return ZonesHandler.moveCard(zoneChangeInfo, game);
}
return false;
}
@Override
public boolean moveToExile(UUID exileId, String name, UUID sourceId, Game game, ArrayList<UUID> appliedEffects) {
Zone fromZone = game.getState().getZone(objectId);
ZoneChangeEvent event = new ZoneChangeEvent(this, sourceId, ownerId, fromZone, Zone.EXILED, appliedEffects);
ZoneChangeInfo.Exile info = new ZoneChangeInfo.Exile(event, exileId, name);
return ZonesHandler.moveCard(info, game);
}
@Override
public PermanentCard copy() {
return new PermanentCard(this);

View file

@ -66,13 +66,10 @@ import mage.counters.CounterType;
import mage.counters.Counters;
import mage.game.Game;
import mage.game.GameState;
import mage.game.ZoneChangeInfo;
import mage.game.ZonesHandler;
import mage.game.command.CommandObject;
import mage.game.events.DamageCreatureEvent;
import mage.game.events.DamagePlaneswalkerEvent;
import mage.game.events.DamagedCreatureEvent;
import mage.game.events.DamagedPlaneswalkerEvent;
import mage.game.events.EntersTheBattlefieldEvent;
import mage.game.events.GameEvent;
import mage.game.events.*;
import mage.game.events.GameEvent.EventType;
import mage.game.stack.Spell;
import mage.game.stack.StackObject;
@ -1377,4 +1374,29 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
return color;
}
@Override
public boolean moveToZone(Zone toZone, UUID sourceId, Game game, boolean flag, ArrayList<UUID> appliedEffects) {
Zone fromZone = game.getState().getZone(objectId);
Player controller = game.getPlayer(controllerId);
if (controller != null) {
ZoneChangeEvent event = new ZoneChangeEvent(this, sourceId, controllerId, fromZone, toZone, appliedEffects);
ZoneChangeInfo zoneChangeInfo;
if (toZone == Zone.LIBRARY) {
zoneChangeInfo = new ZoneChangeInfo.Library(event, flag /* put on top */);
} else {
zoneChangeInfo = new ZoneChangeInfo(event);
}
return ZonesHandler.moveCard(zoneChangeInfo, game);
}
return false;
}
@Override
public boolean moveToExile(UUID exileId, String name, UUID sourceId, Game game, ArrayList<UUID> appliedEffects) {
Zone fromZone = game.getState().getZone(objectId);
ZoneChangeEvent event = new ZoneChangeEvent(this, sourceId, ownerId, fromZone, Zone.EXILED, appliedEffects);
ZoneChangeInfo.Exile info = new ZoneChangeInfo.Exile(event, exileId, name);
return ZonesHandler.moveCard(info, game);
}
}

View file

@ -30,9 +30,7 @@ package mage.game.permanent;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.costs.mana.ManaCost;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.token.Token;
/**
@ -94,31 +92,6 @@ public class PermanentToken extends PermanentImpl {
this.tokenDescriptor = token.getTokenDescriptor();
}
@Override
public boolean moveToZone(Zone zone, UUID sourceId, Game game, boolean flag) {
if (!game.replaceEvent(new ZoneChangeEvent(this, this.getControllerId(), Zone.BATTLEFIELD, zone))) {
game.rememberLKI(objectId, Zone.BATTLEFIELD, this);
if (game.getPlayer(controllerId).removeFromBattlefield(this, game)) {
game.setZone(objectId, zone); // needed for triggered dies abilities
game.addSimultaneousEvent(new ZoneChangeEvent(this, this.getControllerId(), Zone.BATTLEFIELD, zone));
return true;
}
}
return false;
}
@Override
public boolean moveToExile(UUID exileId, String name, UUID sourceId, Game game) {
if (!game.replaceEvent(new ZoneChangeEvent(this, sourceId, this.getControllerId(), Zone.BATTLEFIELD, Zone.EXILED))) {
game.rememberLKI(objectId, Zone.BATTLEFIELD, this);
if (game.getPlayer(controllerId).removeFromBattlefield(this, game)) {
game.addSimultaneousEvent(new ZoneChangeEvent(this, sourceId, this.getControllerId(), Zone.BATTLEFIELD, Zone.EXILED));
return true;
}
}
return false;
}
public Token getToken() {
return token;
}