fix #10403 (Maestros Ascendancy)

This commit is contained in:
xenohedron 2024-03-23 16:19:54 -04:00
parent 6820aa5ee1
commit 0d5ae6b704
2 changed files with 14 additions and 10 deletions

View file

@ -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<Cost> 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));
}
}

View file

@ -57,10 +57,12 @@ public class MageObjectReference implements Comparable<MageObjectReference>, 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;