From da67a67eaaf6a4e7522d7fb18da412416bd5ee2f Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sun, 6 Nov 2016 14:04:43 +0100 Subject: [PATCH] * Ephara, God of the Polis - Fixed its watcher not able to handle copies of it correctly. --- .../src/mage/cards/e/EpharaGodOfThePolis.java | 56 ++++--------------- .../PermanentsEnteredBattlefieldWatcher.java | 15 +++++ 2 files changed, 25 insertions(+), 46 deletions(-) diff --git a/Mage.Sets/src/mage/cards/e/EpharaGodOfThePolis.java b/Mage.Sets/src/mage/cards/e/EpharaGodOfThePolis.java index f13405ddeb8..4bbee99f28d 100644 --- a/Mage.Sets/src/mage/cards/e/EpharaGodOfThePolis.java +++ b/Mage.Sets/src/mage/cards/e/EpharaGodOfThePolis.java @@ -44,12 +44,10 @@ import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.ColoredManaSymbol; import mage.constants.TargetController; -import mage.constants.WatcherScope; import mage.constants.Zone; import mage.game.Game; -import mage.game.events.GameEvent; import mage.game.permanent.Permanent; -import mage.watchers.Watcher; +import mage.watchers.common.PermanentsEnteredBattlefieldWatcher; /** * @@ -58,7 +56,7 @@ import mage.watchers.Watcher; public class EpharaGodOfThePolis extends CardImpl { public EpharaGodOfThePolis(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT,CardType.CREATURE},"{2}{W}{U}"); + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT, CardType.CREATURE}, "{2}{W}{U}"); this.supertype.add("Legendary"); this.subtype.add("God"); @@ -75,8 +73,8 @@ public class EpharaGodOfThePolis extends CardImpl { this.addAbility(new ConditionalTriggeredAbility( new BeginningOfUpkeepTriggeredAbility(Zone.BATTLEFIELD, new DrawCardSourceControllerEffect(1), TargetController.ANY, false), HadAnotherCreatureEnterTheBattlefieldCondition.getInstance(), - "At the beginning of each upkeep, if you had another creature enter the battlefield under your control last turn, draw a card."), - new CreatureEnteredBattlefieldLastTurnWatcher()); + "At the beginning of each upkeep, if you had another creature enter the battlefield under your control last turn, draw a card."), + new PermanentsEnteredBattlefieldWatcher()); } @@ -92,7 +90,7 @@ public class EpharaGodOfThePolis extends CardImpl { class HadAnotherCreatureEnterTheBattlefieldCondition implements Condition { - private static HadAnotherCreatureEnterTheBattlefieldCondition fInstance = new HadAnotherCreatureEnterTheBattlefieldCondition(); + private final static HadAnotherCreatureEnterTheBattlefieldCondition fInstance = new HadAnotherCreatureEnterTheBattlefieldCondition(); public static HadAnotherCreatureEnterTheBattlefieldCondition getInstance() { return fInstance; @@ -100,44 +98,10 @@ class HadAnotherCreatureEnterTheBattlefieldCondition implements Condition { @Override public boolean apply(Game game, Ability source) { - Watcher watcher = game.getState().getWatchers().get("CreatureEnteredBattlefieldLastTurnWatcher", source.getSourceId()); - return watcher != null && watcher.conditionMet(); - } -} - -class CreatureEnteredBattlefieldLastTurnWatcher extends Watcher { - - private boolean anotherCreatureEntered = false; - - public CreatureEnteredBattlefieldLastTurnWatcher() { - super("CreatureEnteredBattlefieldLastTurnWatcher", WatcherScope.CARD); - } - - public CreatureEnteredBattlefieldLastTurnWatcher(final CreatureEnteredBattlefieldLastTurnWatcher watcher) { - super(watcher); - this.anotherCreatureEntered = watcher.anotherCreatureEntered; - } - - @Override - public void watch(GameEvent event, Game game) { - if (!anotherCreatureEntered && event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) { - if (!event.getTargetId().equals(this.getSourceId()) && event.getPlayerId().equals(this.getControllerId())) { - Permanent permanent = game.getPermanent(event.getTargetId()); - if (permanent != null && permanent.getCardType().contains(CardType.CREATURE)) { - anotherCreatureEntered = true; - } - } - } - } - - @Override - public void reset() { - condition = anotherCreatureEntered; - anotherCreatureEntered = false; - } - - @Override - public CreatureEnteredBattlefieldLastTurnWatcher copy() { - return new CreatureEnteredBattlefieldLastTurnWatcher(this); + Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId()); + PermanentsEnteredBattlefieldWatcher watcher = (PermanentsEnteredBattlefieldWatcher) game.getState().getWatchers().get(PermanentsEnteredBattlefieldWatcher.class.getName()); + return sourcePermanent != null + && watcher != null + && watcher.AnotherCreatureEnteredBattlefieldUnderPlayersControlLastTurn(sourcePermanent, game); } } diff --git a/Mage/src/main/java/mage/watchers/common/PermanentsEnteredBattlefieldWatcher.java b/Mage/src/main/java/mage/watchers/common/PermanentsEnteredBattlefieldWatcher.java index a15d0aa3983..b037b6da705 100644 --- a/Mage/src/main/java/mage/watchers/common/PermanentsEnteredBattlefieldWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/PermanentsEnteredBattlefieldWatcher.java @@ -22,6 +22,7 @@ import mage.watchers.Watcher; public class PermanentsEnteredBattlefieldWatcher extends Watcher { private final HashMap> enteringBattlefield = new HashMap<>(); + private final HashMap> enteringBattlefieldLastTurn = new HashMap<>(); public PermanentsEnteredBattlefieldWatcher() { super(PermanentsEnteredBattlefieldWatcher.class.getName(), WatcherScope.GAME); @@ -29,6 +30,8 @@ public class PermanentsEnteredBattlefieldWatcher extends Watcher { public PermanentsEnteredBattlefieldWatcher(final PermanentsEnteredBattlefieldWatcher watcher) { super(watcher); + this.enteringBattlefield.putAll(watcher.enteringBattlefield); + this.enteringBattlefieldLastTurn.putAll(watcher.enteringBattlefieldLastTurn); } @Override @@ -56,10 +59,22 @@ public class PermanentsEnteredBattlefieldWatcher extends Watcher { @Override public void reset() { super.reset(); + enteringBattlefieldLastTurn.clear(); + enteringBattlefieldLastTurn.putAll(enteringBattlefield); enteringBattlefield.clear(); } public List getThisTurnEnteringPermanents(UUID playerId) { return enteringBattlefield.get(playerId); } + + public boolean AnotherCreatureEnteredBattlefieldUnderPlayersControlLastTurn(Permanent sourcePermanent, Game game) { + for (Permanent permanent : enteringBattlefield.get(sourcePermanent.getControllerId())) { + if (!permanent.getId().equals(sourcePermanent.getId()) + || permanent.getZoneChangeCounter(game) != sourcePermanent.getZoneChangeCounter(game)) { + return true; + } + } + return false; + } }