From 0d5ae6b704c5db2e3ee4da4edb5bfa3b15a15af7 Mon Sep 17 00:00:00 2001 From: xenohedron Date: Sat, 23 Mar 2024 16:19:54 -0400 Subject: [PATCH] fix #10403 (Maestros Ascendancy) --- .../src/mage/cards/m/MaestrosAscendancy.java | 22 ++++++++++--------- .../main/java/mage/MageObjectReference.java | 2 ++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Mage.Sets/src/mage/cards/m/MaestrosAscendancy.java b/Mage.Sets/src/mage/cards/m/MaestrosAscendancy.java index 7458014e2c7..6989af5719d 100644 --- a/Mage.Sets/src/mage/cards/m/MaestrosAscendancy.java +++ b/Mage.Sets/src/mage/cards/m/MaestrosAscendancy.java @@ -18,6 +18,7 @@ import mage.filter.StaticFilters; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.events.ZoneChangeEvent; +import mage.game.stack.Spell; import mage.players.Player; import mage.watchers.Watcher; @@ -83,7 +84,7 @@ class MaestrosAscendancyCastEffect extends AsThoughEffectImpl { || !card.isOwnedBy(affectedControllerId) || !card.isInstantOrSorcery(game) || !game.getState().getZone(objectId).match(Zone.GRAVEYARD) - || !MaestrosAscendancyWatcher.checkPlayer(source, game)) { + || MaestrosAscendancyWatcher.checkPlayer(source, game)) { return false; } Costs newCosts = new CostsImpl<>(); @@ -115,10 +116,8 @@ class MaestrosAscendancyExileEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - Player controller = game.getPlayer(source.getControllerId()); - Card card = game.getCard(event.getTargetId()); - return controller != null && card != null - && controller.moveCards(card, Zone.EXILED, source, game); + ((ZoneChangeEvent) event).setToZone(Zone.EXILED); + return false; } @Override @@ -129,8 +128,10 @@ class MaestrosAscendancyExileEffect extends ReplacementEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { ZoneChangeEvent zEvent = (ZoneChangeEvent) event; + Spell spell = game.getSpellOrLKIStack(zEvent.getTargetId()); return zEvent.getToZone() == Zone.GRAVEYARD - && MaestrosAscendancyWatcher.checkSpell(zEvent.getTargetId(), source, game); + && spell != null + && MaestrosAscendancyWatcher.checkSpell(spell, source, game); } } @@ -146,6 +147,7 @@ class MaestrosAscendancyWatcher extends Watcher { @Override public void watch(GameEvent event, Game game) { if (event.getType() == GameEvent.EventType.SPELL_CAST + && event.hasApprovingIdentifier(MageIdentifier.MaestrosAscendencyAlternateCast) && event.getAdditionalReference() != null) { playerMap.computeIfAbsent( event.getAdditionalReference() @@ -172,16 +174,16 @@ class MaestrosAscendancyWatcher extends Watcher { .getState() .getWatcher(MaestrosAscendancyWatcher.class) .playerMap - .getOrDefault(new MageObjectReference(source), Collections.emptySet()) + .getOrDefault(new MageObjectReference(source.getSourcePermanentIfItStillExists(game), game), Collections.emptySet()) .contains(source.getControllerId()); } - static boolean checkSpell(UUID id, Ability source, Game game) { + static boolean checkSpell(Spell spell, Ability source, Game game) { return game .getState() .getWatcher(MaestrosAscendancyWatcher.class) .spellMap - .getOrDefault(new MageObjectReference(source), Collections.emptySet()) - .contains(new MageObjectReference(id, game)); + .getOrDefault(new MageObjectReference(source.getSourcePermanentOrLKI(game), game), Collections.emptySet()) + .contains(new MageObjectReference(spell, game)); } } diff --git a/Mage/src/main/java/mage/MageObjectReference.java b/Mage/src/main/java/mage/MageObjectReference.java index 22fdf83d15e..17cb40cf71f 100644 --- a/Mage/src/main/java/mage/MageObjectReference.java +++ b/Mage/src/main/java/mage/MageObjectReference.java @@ -57,10 +57,12 @@ public class MageObjectReference implements Comparable, Ser this.zoneChangeCounter = -1; } + @Deprecated // cause of many bugs, see issue #10479 public MageObjectReference(Ability source) { this(source, 0); } + @Deprecated // cause of many bugs, see issue #10479 public MageObjectReference(Ability source, int modifier) { this.sourceId = source.getSourceId(); this.zoneChangeCounter = source.getSourceObjectZoneChangeCounter() + modifier;