Fixed some unlean code. Added CardUtil method to get card and ZoneChangeCounter specific exileId.

This commit is contained in:
LevelX2 2013-06-19 16:15:58 +02:00
parent 80beadbee2
commit fcff65ca34
3 changed files with 37 additions and 15 deletions

View file

@ -28,14 +28,13 @@
package mage.sets.innistrad;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.filter.common.FilterNonlandCard;
import mage.game.Game;
@ -98,7 +97,7 @@ class NightTerrorsEffect extends OneShotEffect<NightTerrorsEffect> {
if (player.choose(Outcome.Exile, targetPlayer.getHand(), target, game)) {
Card card = targetPlayer.getHand().get(target.getFirstTarget(), game);
if (card != null) {
card.moveToExile(null, "", source.getId(), game);
card.moveToExile(null, "", source.getSourceId(), game);
}
}

View file

@ -28,11 +28,6 @@
package mage.sets.returntoravnica;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.LeavesBattlefieldTriggeredAbility;
@ -41,6 +36,10 @@ import mage.abilities.effects.OneShotEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.filter.common.FilterCreatureCard;
import mage.filter.common.FilterCreaturePermanent;
@ -52,6 +51,7 @@ import mage.game.permanent.Permanent;
import mage.target.Target;
import mage.target.common.TargetCardInGraveyard;
import mage.target.common.TargetCreaturePermanent;
import mage.util.CardUtil;
/**
*
@ -156,7 +156,7 @@ class AngelOfSerenityEnterEffect extends OneShotEffect<AngelOfSerenityEnterEffec
for (UUID permanentId : target.getTargets()) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null) {
result |= permanent.moveToExile(source.getSourceId(), "Angel of Serenity", source.getId(), game);
result |= permanent.moveToExile(CardUtil.getCardExileZoneId(game, source), "Angel of Serenity", source.getSourceId(), game);
}
}
@ -164,7 +164,7 @@ class AngelOfSerenityEnterEffect extends OneShotEffect<AngelOfSerenityEnterEffec
for (UUID cardId : target.getTargets()) {
Card card = game.getCard(cardId);
if (card != null) {
result |= card.moveToExile(source.getSourceId(), "Angel of Serenity", source.getId(), game);
result |= card.moveToExile(CardUtil.getCardExileZoneId(game, source), "Angel of Serenity", source.getSourceId(), game);
}
}
}
@ -192,15 +192,15 @@ class AngelOfSerenityLeaveEffect extends OneShotEffect<AngelOfSerenityLeaveEffec
@Override
public boolean apply(Game game, Ability source) {
ExileZone exZone = game.getExile().getExileZone(source.getSourceId());
ExileZone exZone = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source));
if (exZone != null) {
for (Card card : exZone.getCards(game)) {
if (card != null) {
card.moveToZone(Zone.HAND, source.getId(), game, false);
card.moveToZone(Zone.HAND, source.getSourceId(), game, false);
}
}
return true;
}
return false;
}
}
}

View file

@ -29,6 +29,7 @@
package mage.util;
import java.util.Iterator;
import java.util.UUID;
import mage.Mana;
import mage.abilities.Ability;
@ -43,6 +44,7 @@ import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.costs.mana.VariableManaCost;
import mage.cards.Card;
import mage.constants.CardType;
import mage.game.Game;
import mage.game.permanent.token.Token;
import mage.util.functions.CopyFunction;
import mage.util.functions.CopyTokenFunction;
@ -365,4 +367,25 @@ public class CardUtil {
}
return true;
}
/**
* Creates and saves a (card + zoneChangeCounter) specific exileId.
*
*
* @param game
* @param source - source ability
* @return - the specific UUID
*/
public static UUID getCardExileZoneId(Game game, Ability source) {
UUID exileId = null;
Card card = game.getCard(source.getSourceId());
if (card != null) {
exileId = (UUID) game.getState().getValue(new StringBuilder("SourceExileZone").append(source.getSourceId()).append(card.getZoneChangeCounter()).toString());
if (exileId == null) {
exileId = UUID.randomUUID();
game.getState().setValue(new StringBuilder("SourceExileZone").append(source.getSourceId()).append(card.getZoneChangeCounter()).toString(), exileId);
}
}
return exileId;
}
}