From bf9e25fc34c5493bb11b24fcca7792296aadba5d Mon Sep 17 00:00:00 2001 From: BetaSteward Date: Sat, 4 Feb 2012 17:05:48 -0500 Subject: [PATCH] other fixes --- .../dynamicvalue/common/CountersCount.java | 5 ++- .../abilities/effects/ContinuousEffects.java | 2 + Mage/src/mage/game/GameImpl.java | 6 +-- .../mage/game/permanent/PermanentCard.java | 43 ++++++++++++++++++- .../mage/game/permanent/PermanentImpl.java | 5 ++- .../mage/game/permanent/PermanentToken.java | 7 ++- 6 files changed, 56 insertions(+), 12 deletions(-) diff --git a/Mage/src/mage/abilities/dynamicvalue/common/CountersCount.java b/Mage/src/mage/abilities/dynamicvalue/common/CountersCount.java index 061ca5bd2b2..34458e87447 100644 --- a/Mage/src/mage/abilities/dynamicvalue/common/CountersCount.java +++ b/Mage/src/mage/abilities/dynamicvalue/common/CountersCount.java @@ -1,6 +1,7 @@ package mage.abilities.dynamicvalue.common; import mage.Constants; +import mage.MageObject; import mage.abilities.Ability; import mage.abilities.dynamicvalue.DynamicValue; import mage.counters.CounterType; @@ -23,7 +24,9 @@ public class CountersCount implements DynamicValue { Permanent p = game.getPermanent(sourceAbility.getSourceId()); // if permanent already leaves the battlefield, try to find counters count via last known information if (p == null) { - p = (Permanent) game.getLastKnownInformation(sourceAbility.getSourceId(), Constants.Zone.BATTLEFIELD); + MageObject o = game.getLastKnownInformation(sourceAbility.getSourceId(), Constants.Zone.BATTLEFIELD); + if (o instanceof Permanent) + p = (Permanent) o; } if (p != null) { return p.getCounters().getCount(counter); diff --git a/Mage/src/mage/abilities/effects/ContinuousEffects.java b/Mage/src/mage/abilities/effects/ContinuousEffects.java index f2bbf5f166c..58f3b928dbe 100644 --- a/Mage/src/mage/abilities/effects/ContinuousEffects.java +++ b/Mage/src/mage/abilities/effects/ContinuousEffects.java @@ -202,6 +202,8 @@ public class ContinuousEffects implements Serializable { private boolean isInactive(ContinuousEffect effect, Game game) { Ability ability = abilityMap.get(effect.getId()); + if (ability == null) + return true; switch(effect.getDuration()) { case WhileOnBattlefield: if (game.getObject(ability.getSourceId()) == null) diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index 3714b82d055..0095cbfab3b 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -229,15 +229,15 @@ public abstract class GameImpl> implements Game, Serializa state.setZone(objectId, Zone.BATTLEFIELD); return object; } - object = getCard(objectId); - if (object != null) - return object; for (StackObject item: state.getStack()) { if (item.getId().equals(objectId)) { state.setZone(objectId, Zone.STACK); return item; } } + object = getCard(objectId); + if (object != null) + return object; return null; } diff --git a/Mage/src/mage/game/permanent/PermanentCard.java b/Mage/src/mage/game/permanent/PermanentCard.java index 58f05c70eee..4555adc99b7 100644 --- a/Mage/src/mage/game/permanent/PermanentCard.java +++ b/Mage/src/mage/game/permanent/PermanentCard.java @@ -87,10 +87,10 @@ public class PermanentCard extends PermanentImpl { public void reset(Game game) { // when the permanent is reset copy all original values from the card // must copy card each reset so that the original values don't get modified - copyFromCard(card); + copyFromCard(card, game); super.reset(game); } - + protected void copyFromCard(Card card) { this.name = card.getName(); this.abilities.clear(); @@ -130,6 +130,45 @@ public class PermanentCard extends PermanentImpl { } } + protected void copyFromCard(Card card, Game game) { + this.name = card.getName(); + this.abilities.clear(); + this.abilities.addAll(card.getAbilities()); + this.abilities.setControllerId(this.controllerId); + this.cardType.clear(); + this.cardType.addAll(card.getCardType()); + this.color = card.getColor().copy(); + this.manaCost = card.getManaCost().copy(); + this.power = card.getPower().copy(); + this.toughness = card.getToughness().copy(); + if (card instanceof LevelerCard) { + LevelAbility level = ((LevelerCard) card).getLevel(this.getCounters().getCount(CounterType.LEVEL)); + if (level != null) { + this.power.setValue(level.getPower()); + this.toughness.setValue(level.getToughness()); + for (Ability ability : level.getAbilities()) { + this.addAbility(ability, game); + } + } + } + if (card instanceof PermanentCard) { + this.maxLevelCounters = ((PermanentCard) card).maxLevelCounters; + } + this.subtype.clear(); + this.subtype.addAll(card.getSubtype()); + this.supertype.clear(); + this.supertype.addAll(card.getSupertype()); + this.expansionSetCode = card.getExpansionSetCode(); + this.rarity = card.getRarity(); + this.cardNumber = card.getCardNumber(); + + canTransform = card.canTransform(); + if (canTransform) { + secondSideCard = card.getSecondCardFace(); + nightCard = card.isNightCard(); + } + } + // public void checkPermanentOnlyTriggers(ZoneChangeEvent event, Game game) { // // we only want to trigger abilities that are not on the underlying card ie. have been added by another effect // // or we want to trigger abilities that only trigger on leaving the battlefield diff --git a/Mage/src/mage/game/permanent/PermanentImpl.java b/Mage/src/mage/game/permanent/PermanentImpl.java index e41aa27f7c6..f75160722bf 100644 --- a/Mage/src/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/mage/game/permanent/PermanentImpl.java @@ -159,14 +159,15 @@ public abstract class PermanentImpl> extends CardImpl } @Override + @Deprecated public void addAbility(Ability ability) { throw new UnsupportedOperationException("Unsupported operation: use addAbility(Ability ability, Game game) instead"); } @Override public void addAbility(Ability ability, Game game) { - Ability copy = ability.copy(); - if (!abilities.containsKey(copy.getId())) { + if (!abilities.containsKey(ability.getId())) { + Ability copy = ability.copy(); copy.setControllerId(controllerId); copy.setSourceId(objectId); game.getState().addAbility(copy); diff --git a/Mage/src/mage/game/permanent/PermanentToken.java b/Mage/src/mage/game/permanent/PermanentToken.java index 541b95a19f5..004ec8dc70c 100644 --- a/Mage/src/mage/game/permanent/PermanentToken.java +++ b/Mage/src/mage/game/permanent/PermanentToken.java @@ -49,7 +49,6 @@ public class PermanentToken extends PermanentImpl { super(controllerId, controllerId, token.getName()); this.token = token; this.expansionSetCode = expansionSetCode; - copyFromToken(token); } public PermanentToken(final PermanentToken permanent) { @@ -61,15 +60,15 @@ public class PermanentToken extends PermanentImpl { @Override public void reset(Game game) { Token copy = token.copy(); - copyFromToken(copy); + copyFromToken(copy, game); super.reset(game); } - protected void copyFromToken(Token token) { + protected void copyFromToken(Token token, Game game) { this.name = token.getName(); this.abilities.clear(); for (Ability ability: token.getAbilities()) { - this.addAbility(ability); + this.addAbility(ability, game); } this.cardType = token.getCardType(); this.color = token.getColor();