mirror of
https://github.com/correl/mage.git
synced 2024-11-15 19:19:33 +00:00
Handle tokens correctly in the new zone change code.
This commit is contained in:
parent
377a0edec9
commit
17d4d6c190
4 changed files with 93 additions and 129 deletions
|
@ -83,79 +83,78 @@ 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;
|
||||
if (targetCard instanceof MeldCard) {
|
||||
cards = ((MeldCard) targetCard).getHalves();
|
||||
} else {
|
||||
cards = new CardsImpl(targetCard);
|
||||
}
|
||||
Player owner = game.getPlayer(targetCard.getOwnerId());
|
||||
switch (toZone) {
|
||||
case HAND:
|
||||
for (Card card : cards.getCards(game)) {
|
||||
game.getPlayer(card.getOwnerId()).getHand().add(card);
|
||||
}
|
||||
break;
|
||||
case GRAVEYARD:
|
||||
for (Card card : chooseOrder(
|
||||
"order to put in graveyard (last chosen will be on top)", cards, owner, game)) {
|
||||
game.getPlayer(card.getOwnerId()).getGraveyard().add(card);
|
||||
}
|
||||
break;
|
||||
case LIBRARY:
|
||||
if (info instanceof ZoneChangeInfo.Library && ((ZoneChangeInfo.Library) info).top) {
|
||||
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 {
|
||||
cards = new CardsImpl(targetCard);
|
||||
}
|
||||
Player owner = game.getPlayer(targetCard.getOwnerId());
|
||||
switch (toZone) {
|
||||
case HAND:
|
||||
for (Card card : cards.getCards(game)) {
|
||||
game.getPlayer(card.getOwnerId()).getHand().add(card);
|
||||
}
|
||||
break;
|
||||
case GRAVEYARD:
|
||||
for (Card card : chooseOrder(
|
||||
"order to put on top of library (last chosen will be topmost)", cards, owner, game)) {
|
||||
game.getPlayer(card.getOwnerId()).getLibrary().putOnTop(card, game);
|
||||
"order to put in graveyard (last chosen will be on top)", cards, owner, game)) {
|
||||
game.getPlayer(card.getOwnerId()).getGraveyard().add(card);
|
||||
}
|
||||
} else {
|
||||
for (Card card : chooseOrder(
|
||||
"order to put on bottom of library (last chosen will be bottommost)", cards, owner, game)) {
|
||||
game.getPlayer(card.getOwnerId()).getLibrary().putOnBottom(card, game);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EXILED:
|
||||
for (Card card : cards.getCards(game)) {
|
||||
if (info instanceof ZoneChangeInfo.Exile && ((ZoneChangeInfo.Exile) info).id != null) {
|
||||
ZoneChangeInfo.Exile exileInfo = (ZoneChangeInfo.Exile) info;
|
||||
game.getExile().createZone(exileInfo.id, exileInfo.name).add(card);
|
||||
break;
|
||||
case LIBRARY:
|
||||
if (info instanceof ZoneChangeInfo.Library && ((ZoneChangeInfo.Library) info).top) {
|
||||
for (Card card : chooseOrder(
|
||||
"order to put on top of library (last chosen will be topmost)", cards, owner, game)) {
|
||||
game.getPlayer(card.getOwnerId()).getLibrary().putOnTop(card, game);
|
||||
}
|
||||
} else {
|
||||
game.getExile().getPermanentExile().add(card);
|
||||
for (Card card : chooseOrder(
|
||||
"order to put on bottom of library (last chosen will be bottommost)", cards, owner, game)) {
|
||||
game.getPlayer(card.getOwnerId()).getLibrary().putOnBottom(card, game);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case COMMAND:
|
||||
// There should never be more than one card here.
|
||||
for (Card card : cards.getCards(game)) {
|
||||
game.addCommander(new Commander(card));
|
||||
}
|
||||
break;
|
||||
case STACK:
|
||||
// There should never be more than one card here.
|
||||
for (Card card : cards.getCards(game)) {
|
||||
if (info instanceof ZoneChangeInfo.Stack && ((ZoneChangeInfo.Stack) info).spell != null) {
|
||||
game.getStack().push(((ZoneChangeInfo.Stack) info).spell);
|
||||
} else {
|
||||
game.getStack().push(
|
||||
new Spell(card, card.getSpellAbility().copy(), card.getOwnerId(), event.getFromZone()));
|
||||
break;
|
||||
case EXILED:
|
||||
for (Card card : cards.getCards(game)) {
|
||||
if (info instanceof ZoneChangeInfo.Exile && ((ZoneChangeInfo.Exile) info).id != null) {
|
||||
ZoneChangeInfo.Exile exileInfo = (ZoneChangeInfo.Exile) info;
|
||||
game.getExile().createZone(exileInfo.id, exileInfo.name).add(card);
|
||||
} else {
|
||||
game.getExile().getPermanentExile().add(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BATTLEFIELD:
|
||||
Permanent permanent = event.getTarget();
|
||||
game.addPermanent(permanent);
|
||||
game.getPermanentsEntering().remove(permanent.getId());
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException("to Zone" + toZone.toString() + " not supported yet");
|
||||
break;
|
||||
case COMMAND:
|
||||
// There should never be more than one card here.
|
||||
for (Card card : cards.getCards(game)) {
|
||||
game.addCommander(new Commander(card));
|
||||
}
|
||||
break;
|
||||
case STACK:
|
||||
// There should never be more than one card here.
|
||||
for (Card card : cards.getCards(game)) {
|
||||
if (info instanceof ZoneChangeInfo.Stack && ((ZoneChangeInfo.Stack) info).spell != null) {
|
||||
game.getStack().push(((ZoneChangeInfo.Stack) info).spell);
|
||||
} else {
|
||||
game.getStack().push(
|
||||
new Spell(card, card.getSpellAbility().copy(), card.getOwnerId(), event.getFromZone()));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BATTLEFIELD:
|
||||
Permanent permanent = event.getTarget();
|
||||
game.addPermanent(permanent);
|
||||
game.getPermanentsEntering().remove(permanent.getId());
|
||||
break;
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue