From d167808dc8fe4e3ddca73abdf62080b28d106d5d Mon Sep 17 00:00:00 2001 From: Alexander Novotny Date: Tue, 16 Feb 2021 17:03:11 -0800 Subject: [PATCH] [C20] Fixed Haldan, Avid Arcanist's ability applying to all spells (magefree/mage#7585) (#7589) --- .../src/mage/cards/h/HaldanAvidArcanist.java | 34 +++++++++++-------- .../src/mage/cards/p/PakoArcaneRetriever.java | 18 +++++++--- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/Mage.Sets/src/mage/cards/h/HaldanAvidArcanist.java b/Mage.Sets/src/mage/cards/h/HaldanAvidArcanist.java index ef1cb70e8ca..afe3f25b4a0 100644 --- a/Mage.Sets/src/mage/cards/h/HaldanAvidArcanist.java +++ b/Mage.Sets/src/mage/cards/h/HaldanAvidArcanist.java @@ -48,19 +48,7 @@ public final class HaldanAvidArcanist extends CardImpl { @Override public HaldanAvidArcanist copy() { return new HaldanAvidArcanist(this); - } - - static boolean checkCard(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - if (!PakoArcaneRetriever.checkWatcher(affectedControllerId, game.getCard(objectId), game) - || !source.isControlledBy(affectedControllerId) - || game.getState().getZone(objectId) != Zone.EXILED) { - return false; - } - Card card = game.getCard(objectId); - return card != null - && !card.isCreature() - && card.getCounters(game).containsKey(CounterType.FETCH); - } + } } class HaldanAvidArcanistCastFromExileEffect extends AsThoughEffectImpl { @@ -86,7 +74,13 @@ class HaldanAvidArcanistCastFromExileEffect extends AsThoughEffectImpl { @Override public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) { - return HaldanAvidArcanist.checkCard(sourceId, source, affectedControllerId, 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); } } @@ -113,7 +107,17 @@ class HaldanAvidArcanistSpendAnyManaEffect extends AsThoughEffectImpl implements @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - return true; + // 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 154b97c78ec..44f8123327c 100644 --- a/Mage.Sets/src/mage/cards/p/PakoArcaneRetriever.java +++ b/Mage.Sets/src/mage/cards/p/PakoArcaneRetriever.java @@ -124,13 +124,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) { - return card != null && playerMap - .computeIfAbsent(playerId, u -> new HashSet<>()) + 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()) .stream() - .anyMatch(mageObjectReference -> mageObjectReference.refersTo(card.getId(), game)); + .anyMatch(ref -> ref.getSourceId().equals(card.getId()) + && ref.getZoneChangeCounter() == (game.getState().getZoneChangeCounter(card.getId()) + - zoneChangeDifference)); } }