From 4f7631f0f0dd4e4cae182582f09838129b848596 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Mon, 22 Feb 2021 08:03:27 +0400 Subject: [PATCH] * Haldan, Avid Arcanist - fixed rollback error on usage without partner; --- .../src/mage/cards/h/HaldanAvidArcanist.java | 40 +++++++++---------- .../src/mage/cards/p/PakoArcaneRetriever.java | 30 ++++++++------ 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/Mage.Sets/src/mage/cards/h/HaldanAvidArcanist.java b/Mage.Sets/src/mage/cards/h/HaldanAvidArcanist.java index afe3f25b4a0..45662193deb 100644 --- a/Mage.Sets/src/mage/cards/h/HaldanAvidArcanist.java +++ b/Mage.Sets/src/mage/cards/h/HaldanAvidArcanist.java @@ -38,7 +38,7 @@ public final class HaldanAvidArcanist extends CardImpl { // exiled them, and you may spend mana as though it were mana of any color to cast those spells. Ability ability = new SimpleStaticAbility(new HaldanAvidArcanistCastFromExileEffect()); ability.addEffect(new HaldanAvidArcanistSpendAnyManaEffect()); - this.addAbility(ability); + this.addAbility(ability, PakoArcaneRetriever.createWatcher()); } private HaldanAvidArcanist(final HaldanAvidArcanist card) { @@ -48,7 +48,7 @@ public final class HaldanAvidArcanist extends CardImpl { @Override public HaldanAvidArcanist copy() { return new HaldanAvidArcanist(this); - } + } } class HaldanAvidArcanistCastFromExileEffect extends AsThoughEffectImpl { @@ -74,13 +74,13 @@ class HaldanAvidArcanistCastFromExileEffect extends AsThoughEffectImpl { @Override public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) { - Card card = game.getCard(sourceId); - if (card == null || !source.isControlledBy(affectedControllerId) - || game.getState().getZone(sourceId) != Zone.EXILED - || !PakoArcaneRetriever.checkWatcher(affectedControllerId, card, game)) { - return false; - } - return !card.isCreature() && card.getCounters(game).containsKey(CounterType.FETCH); + Card card = game.getCard(sourceId); + if (card == null || !source.isControlledBy(affectedControllerId) + || game.getState().getZone(sourceId) != Zone.EXILED + || !PakoArcaneRetriever.checkWatcher(affectedControllerId, card, game)) { + return false; + } + return !card.isCreature() && card.getCounters(game).containsKey(CounterType.FETCH); } } @@ -107,17 +107,17 @@ class HaldanAvidArcanistSpendAnyManaEffect extends AsThoughEffectImpl implements @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - // The card may be on the stack, in which case it will not have a fetch counter - // on it. In this case, we will have to rely on the watcher to tell us whether - // or not it is a valid card to apply the effect to. - Zone zone; - Card card = game.getCard(objectId); - if (card == null || !source.isControlledBy(affectedControllerId) - || (zone = game.getState().getZone(objectId)) != Zone.EXILED && zone != Zone.STACK - || !PakoArcaneRetriever.checkWatcher(affectedControllerId, card, game)) { - return false; - } - return !card.isCreature() && (card.getCounters(game).containsKey(CounterType.FETCH) || zone == Zone.STACK); + // The card may be on the stack, in which case it will not have a fetch counter + // on it. In this case, we will have to rely on the watcher to tell us whether + // or not it is a valid card to apply the effect to. + Zone zone; + Card card = game.getCard(objectId); + if (card == null || !source.isControlledBy(affectedControllerId) + || (zone = game.getState().getZone(objectId)) != Zone.EXILED && zone != Zone.STACK + || !PakoArcaneRetriever.checkWatcher(affectedControllerId, card, game)) { + return false; + } + return !card.isCreature() && (card.getCounters(game).containsKey(CounterType.FETCH) || zone == Zone.STACK); } @Override diff --git a/Mage.Sets/src/mage/cards/p/PakoArcaneRetriever.java b/Mage.Sets/src/mage/cards/p/PakoArcaneRetriever.java index 44f8123327c..805c31fa51b 100644 --- a/Mage.Sets/src/mage/cards/p/PakoArcaneRetriever.java +++ b/Mage.Sets/src/mage/cards/p/PakoArcaneRetriever.java @@ -58,6 +58,10 @@ public final class PakoArcaneRetriever extends CardImpl { PakoArcaneRetrieverWatcher watcher = game.getState().getWatcher(PakoArcaneRetrieverWatcher.class); return watcher != null && watcher.checkCard(playerId, card, game); } + + public static Watcher createWatcher() { + return new PakoArcaneRetrieverWatcher(); + } } class PakoArcaneRetrieverEffect extends OneShotEffect { @@ -124,23 +128,23 @@ class PakoArcaneRetrieverWatcher extends Watcher { } void addCard(UUID playerId, Card card, Game game) { - playerMap.computeIfAbsent(playerId, u -> new HashSet()) - .add(new MageObjectReference(card, game)); + playerMap.computeIfAbsent(playerId, u -> new HashSet()) + .add(new MageObjectReference(card, game)); } boolean checkCard(UUID playerId, Card card, Game game) { - if (card == null) - return false; + if (card == null) + return false; - // If the card has been moved onto the stack (e.g. by attempting to cast), the - // number of zone change counters will be 1 more than when the pako effect - // exiled it and the watcher took a reference. - // https://github.com/magefree/mage/issues/7585 - final int zoneChangeDifference = game.getState().getZone(card.getId()) == Zone.STACK ? 1 : 0; - return playerMap.computeIfAbsent(playerId, u -> new HashSet()) + // If the card has been moved onto the stack (e.g. by attempting to cast), the + // number of zone change counters will be 1 more than when the pako effect + // exiled it and the watcher took a reference. + // https://github.com/magefree/mage/issues/7585 + final int zoneChangeDifference = game.getState().getZone(card.getId()) == Zone.STACK ? 1 : 0; + return playerMap.computeIfAbsent(playerId, u -> new HashSet()) .stream() - .anyMatch(ref -> ref.getSourceId().equals(card.getId()) - && ref.getZoneChangeCounter() == (game.getState().getZoneChangeCounter(card.getId()) - - zoneChangeDifference)); + .anyMatch(ref -> ref.getSourceId().equals(card.getId()) + && ref.getZoneChangeCounter() == (game.getState().getZoneChangeCounter(card.getId()) + - zoneChangeDifference)); } }