From de8c7ea235a0e8f0cefa6b6520e6789b7d011251 Mon Sep 17 00:00:00 2001 From: Steven Knipe Date: Mon, 18 Sep 2023 05:48:36 -0700 Subject: [PATCH] Update cast spell name check to use characteristics --- .../src/mage/cards/a/AlhammarretHighArbiter.java | 14 ++++++++------ Mage.Sets/src/mage/cards/a/AshioksErasure.java | 5 ++++- Mage.Sets/src/mage/cards/c/CorneredMarket.java | 8 ++++++-- Mage.Sets/src/mage/cards/e/ExclusionRitual.java | 16 +++++++++------- .../src/mage/cards/g/GideonsIntervention.java | 8 ++++++-- Mage.Sets/src/mage/cards/i/IxalansBinding.java | 10 ++++++++-- Mage.Sets/src/mage/cards/m/ManaMaze.java | 15 +++++++-------- Mage.Sets/src/mage/cards/m/MeddlingMage.java | 11 +++++++---- Mage.Sets/src/mage/cards/r/ReflectorMage.java | 16 ++++++---------- .../main/java/mage/abilities/SpellAbility.java | 2 +- ...ponentsCantCastChosenUntilNextTurnEffect.java | 13 ++++++++----- .../mage/constants/SpellAbilityCastMode.java | 5 +++++ 12 files changed, 75 insertions(+), 48 deletions(-) diff --git a/Mage.Sets/src/mage/cards/a/AlhammarretHighArbiter.java b/Mage.Sets/src/mage/cards/a/AlhammarretHighArbiter.java index f2436efc4e6..60ff82a4a2f 100644 --- a/Mage.Sets/src/mage/cards/a/AlhammarretHighArbiter.java +++ b/Mage.Sets/src/mage/cards/a/AlhammarretHighArbiter.java @@ -1,10 +1,10 @@ package mage.cards.a; -import java.util.UUID; import mage.MageInt; import mage.MageObject; import mage.abilities.Ability; +import mage.abilities.SpellAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.abilities.effects.EntersBattlefieldEffect; @@ -15,13 +15,14 @@ import mage.constants.*; import mage.filter.common.FilterNonlandCard; import mage.game.Game; import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.TargetCard; import mage.util.CardUtil; import mage.util.GameLog; +import java.util.UUID; + /** * * @author LevelX2 @@ -153,10 +154,11 @@ class AlhammarretHighArbiterCantCastEffect extends ContinuousRuleModifyingEffect @Override public boolean applies(GameEvent event, Ability source, Game game) { if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { - MageObject object = game.getObject(event.getSourceId()); - if (object != null && object.getName().equals(cardName)) { - return true; - } + SpellAbility spellAbility = SpellAbility.getSpellAbilityFromEvent(event, game); + if (spellAbility == null) { return false;} + Card card = spellAbility.getCharacteristics(game); + if (card == null) { return false;} + return CardUtil.haveSameNames(card, cardName, game); } return false; } diff --git a/Mage.Sets/src/mage/cards/a/AshioksErasure.java b/Mage.Sets/src/mage/cards/a/AshioksErasure.java index db295cb0fe1..d5fabcf4189 100644 --- a/Mage.Sets/src/mage/cards/a/AshioksErasure.java +++ b/Mage.Sets/src/mage/cards/a/AshioksErasure.java @@ -2,6 +2,7 @@ package mage.cards.a; import mage.MageObject; import mage.abilities.Ability; +import mage.abilities.SpellAbility; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.LeavesBattlefieldTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; @@ -116,7 +117,9 @@ class AshioksErasureReplacementEffect extends ContinuousRuleModifyingEffectImpl if (event.getPlayerId().equals(source.getControllerId())) { return false; } - Card card = game.getCard(event.getSourceId()); + SpellAbility spellAbility = SpellAbility.getSpellAbilityFromEvent(event, game); + if (spellAbility == null) { return false;} + Card card = spellAbility.getCharacteristics(game); if (sourcePermanent == null || card == null) { return false; diff --git a/Mage.Sets/src/mage/cards/c/CorneredMarket.java b/Mage.Sets/src/mage/cards/c/CorneredMarket.java index c8dbc0e399f..e7d600cbcc4 100644 --- a/Mage.Sets/src/mage/cards/c/CorneredMarket.java +++ b/Mage.Sets/src/mage/cards/c/CorneredMarket.java @@ -1,7 +1,7 @@ package mage.cards.c; -import java.util.UUID; import mage.abilities.Ability; +import mage.abilities.SpellAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.cards.Card; @@ -19,6 +19,8 @@ import mage.game.permanent.Permanent; import mage.game.stack.Spell; import mage.util.CardUtil; +import java.util.UUID; + /** * * @author jeffwadsworth @@ -70,7 +72,9 @@ class CorneredMarketReplacementEffect extends ContinuousRuleModifyingEffectImpl @Override public boolean applies(GameEvent event, Ability source, Game game) { - Card card = game.getCard(event.getSourceId()); + SpellAbility spellAbility = SpellAbility.getSpellAbilityFromEvent(event, game); + if (spellAbility == null) { return false;} + Card card = spellAbility.getCharacteristics(game); if (card != null) { Spell spell = game.getState().getStack().getSpell(event.getSourceId()); // Face Down cast spell (Morph creature) has no name diff --git a/Mage.Sets/src/mage/cards/e/ExclusionRitual.java b/Mage.Sets/src/mage/cards/e/ExclusionRitual.java index a2f4d721833..80ae97f97f2 100644 --- a/Mage.Sets/src/mage/cards/e/ExclusionRitual.java +++ b/Mage.Sets/src/mage/cards/e/ExclusionRitual.java @@ -1,6 +1,7 @@ package mage.cards.e; import mage.abilities.Ability; +import mage.abilities.SpellAbility; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; @@ -100,13 +101,14 @@ class ExclusionRitualReplacementEffect extends ContinuousRuleModifyingEffectImpl @Override public boolean applies(GameEvent event, Ability source, Game game) { Permanent sourcePermanent = game.getPermanent(source.getSourceId()); - Card card = game.getCard(event.getSourceId()); - if (sourcePermanent != null && card != null) { - if (!sourcePermanent.getImprinted().isEmpty()) { - Card imprintedCard = game.getCard(sourcePermanent.getImprinted().get(0)); - if (imprintedCard != null) { - return CardUtil.haveSameNames(card, imprintedCard); - } + SpellAbility spellAbility = SpellAbility.getSpellAbilityFromEvent(event, game); + if (spellAbility == null) { return false;} + Card card = spellAbility.getCharacteristics(game); + if (card == null) { return false;} + if (sourcePermanent != null && !sourcePermanent.getImprinted().isEmpty()) { + Card imprintedCard = game.getCard(sourcePermanent.getImprinted().get(0)); + if (imprintedCard != null) { + return CardUtil.haveSameNames(spellAbility.getCharacteristics(game), imprintedCard); } } return false; diff --git a/Mage.Sets/src/mage/cards/g/GideonsIntervention.java b/Mage.Sets/src/mage/cards/g/GideonsIntervention.java index b460be33935..234d34e835c 100644 --- a/Mage.Sets/src/mage/cards/g/GideonsIntervention.java +++ b/Mage.Sets/src/mage/cards/g/GideonsIntervention.java @@ -2,12 +2,14 @@ package mage.cards.g; import mage.MageObject; import mage.abilities.Ability; +import mage.abilities.SpellAbility; import mage.abilities.common.AsEntersBattlefieldAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.abilities.effects.Effect; import mage.abilities.effects.PreventionEffectImpl; import mage.abilities.effects.common.ChooseACardNameEffect; +import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; @@ -90,8 +92,10 @@ class GideonsInterventionCantCastEffect extends ContinuousRuleModifyingEffectImp public boolean applies(GameEvent event, Ability source, Game game) { String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { - MageObject object = game.getObject(event.getSourceId()); - return object != null && object.getName().equals(cardName); + SpellAbility spellAbility = SpellAbility.getSpellAbilityFromEvent(event, game); + if (spellAbility == null) { return false;} + Card card = spellAbility.getCharacteristics(game); + return card != null && CardUtil.haveSameNames(card, cardName, game); } return false; } diff --git a/Mage.Sets/src/mage/cards/i/IxalansBinding.java b/Mage.Sets/src/mage/cards/i/IxalansBinding.java index cc036f3601a..c5bad08a050 100644 --- a/Mage.Sets/src/mage/cards/i/IxalansBinding.java +++ b/Mage.Sets/src/mage/cards/i/IxalansBinding.java @@ -1,6 +1,7 @@ package mage.cards.i; import mage.abilities.Ability; +import mage.abilities.SpellAbility; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; @@ -8,7 +9,10 @@ import mage.abilities.effects.common.ExileUntilSourceLeavesEffect; import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.*; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.constants.Zone; import mage.filter.StaticFilters; import mage.game.ExileZone; import mage.game.Game; @@ -68,7 +72,9 @@ class IxalansBindingReplacementEffect extends ContinuousRuleModifyingEffectImpl if (event.getPlayerId().equals(source.getControllerId())) { return false; } - Card card = game.getCard(event.getSourceId()); + SpellAbility spellAbility = SpellAbility.getSpellAbilityFromEvent(event, game); + if (spellAbility == null) { return false;} + Card card = spellAbility.getCharacteristics(game); if (sourcePermanent != null && card != null) { UUID exileZone = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()); if (exileZone != null) { diff --git a/Mage.Sets/src/mage/cards/m/ManaMaze.java b/Mage.Sets/src/mage/cards/m/ManaMaze.java index 5e5b1145fbe..923cffae7d5 100644 --- a/Mage.Sets/src/mage/cards/m/ManaMaze.java +++ b/Mage.Sets/src/mage/cards/m/ManaMaze.java @@ -1,25 +1,22 @@ package mage.cards.m; -import java.util.UUID; import mage.MageObject; import mage.abilities.Ability; +import mage.abilities.SpellAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.CardType; -import mage.constants.Duration; -import mage.constants.Outcome; -import mage.constants.WatcherScope; -import mage.constants.Zone; +import mage.constants.*; import mage.game.Game; import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; import mage.game.stack.Spell; import mage.watchers.Watcher; +import java.util.UUID; + /** * * @author jeffwadsworth @@ -61,7 +58,9 @@ class ManaMazeEffect extends ContinuousRuleModifyingEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { - Card card = game.getCard(event.getSourceId()); + SpellAbility spellAbility = SpellAbility.getSpellAbilityFromEvent(event, game); + if (spellAbility == null) { return false;} + Card card = spellAbility.getCharacteristics(game); if (card != null) { LastSpellCastWatcher watcher = game.getState().getWatcher(LastSpellCastWatcher.class); if (watcher != null && watcher.getLastSpellCast() != null) { diff --git a/Mage.Sets/src/mage/cards/m/MeddlingMage.java b/Mage.Sets/src/mage/cards/m/MeddlingMage.java index 5980927439f..b7d6af8141a 100644 --- a/Mage.Sets/src/mage/cards/m/MeddlingMage.java +++ b/Mage.Sets/src/mage/cards/m/MeddlingMage.java @@ -3,16 +3,17 @@ package mage.cards.m; import mage.MageInt; import mage.MageObject; import mage.abilities.Ability; +import mage.abilities.SpellAbility; import mage.abilities.common.AsEntersBattlefieldAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.abilities.effects.common.ChooseACardNameEffect; +import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.*; import mage.game.Game; import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; import mage.util.CardUtil; import java.util.UUID; @@ -84,9 +85,11 @@ class MeddlingMageReplacementEffect extends ContinuousRuleModifyingEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { - MageObject object = game.getObject(event.getSourceId()); + SpellAbility spellAbility = SpellAbility.getSpellAbilityFromEvent(event, game); + if (spellAbility == null) { return false;} + Card card = spellAbility.getCharacteristics(game); + if (card == null) { return false;} String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); - return object != null - && CardUtil.haveSameNames(object, cardName, game); + return CardUtil.haveSameNames(card, cardName, game); } } diff --git a/Mage.Sets/src/mage/cards/r/ReflectorMage.java b/Mage.Sets/src/mage/cards/r/ReflectorMage.java index 0d95e2fef06..1e5074f0be6 100644 --- a/Mage.Sets/src/mage/cards/r/ReflectorMage.java +++ b/Mage.Sets/src/mage/cards/r/ReflectorMage.java @@ -2,6 +2,7 @@ package mage.cards.r; import mage.MageInt; import mage.abilities.Ability; +import mage.abilities.SpellAbility; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.abilities.effects.OneShotEffect; @@ -13,7 +14,6 @@ import mage.filter.common.FilterCreaturePermanent; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.permanent.Permanent; -import mage.game.stack.Spell; import mage.players.Player; import mage.target.common.TargetCreaturePermanent; import mage.util.CardUtil; @@ -113,15 +113,11 @@ class ExclusionRitualReplacementEffect extends ContinuousRuleModifyingEffectImpl @Override public boolean applies(GameEvent event, Ability source, Game game) { - Card card = game.getCard(event.getSourceId()); - if (card != null) { - Spell spell = game.getState().getStack().getSpell(event.getSourceId()); - if (spell != null && spell.isFaceDown(game)) { - return false; // Face Down cast spell (Morph creature) has no name - } - return CardUtil.haveSameNames(card, creatureName, game) && Objects.equals(ownerId, card.getOwnerId()); - } - return false; + SpellAbility spellAbility = SpellAbility.getSpellAbilityFromEvent(event, game); + if (spellAbility == null) { return false;} + Card card = spellAbility.getCharacteristics(game); + if (card == null) { return false;} + return CardUtil.haveSameNames(card, creatureName, game) && Objects.equals(ownerId, card.getOwnerId()); } @Override diff --git a/Mage/src/main/java/mage/abilities/SpellAbility.java b/Mage/src/main/java/mage/abilities/SpellAbility.java index 0ff4861dda1..01453c5825c 100644 --- a/Mage/src/main/java/mage/abilities/SpellAbility.java +++ b/Mage/src/main/java/mage/abilities/SpellAbility.java @@ -306,7 +306,7 @@ public class SpellAbility extends ActivatedAbilityImpl { } public static SpellAbility getSpellAbilityFromEvent(GameEvent event, Game game) { - if (event.getType() != GameEvent.EventType.CAST_SPELL) { + if (event.getType() != GameEvent.EventType.CAST_SPELL && event.getType() != GameEvent.EventType.CAST_SPELL_LATE) { return null; } diff --git a/Mage/src/main/java/mage/abilities/effects/common/OpponentsCantCastChosenUntilNextTurnEffect.java b/Mage/src/main/java/mage/abilities/effects/common/OpponentsCantCastChosenUntilNextTurnEffect.java index b9411849ca3..304fbd5c24f 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/OpponentsCantCastChosenUntilNextTurnEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/OpponentsCantCastChosenUntilNextTurnEffect.java @@ -2,7 +2,9 @@ package mage.abilities.effects.common; import mage.MageObject; import mage.abilities.Ability; +import mage.abilities.SpellAbility; import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; +import mage.cards.Card; import mage.constants.Duration; import mage.constants.Outcome; import mage.game.Game; @@ -45,11 +47,12 @@ public class OpponentsCantCastChosenUntilNextTurnEffect extends ContinuousRuleMo @Override public boolean applies(GameEvent event, Ability source, Game game) { + if (!game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { return false; } + SpellAbility spellAbility = SpellAbility.getSpellAbilityFromEvent(event, game); + if (spellAbility == null) { return false; } + Card card = spellAbility.getCharacteristics(game); + if (card == null) { return false; } String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); - if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { - MageObject object = game.getObject(event.getSourceId()); - return object != null && CardUtil.haveSameNames(object, cardName, game); - } - return false; + return CardUtil.haveSameNames(card, cardName, game); } } diff --git a/Mage/src/main/java/mage/constants/SpellAbilityCastMode.java b/Mage/src/main/java/mage/constants/SpellAbilityCastMode.java index 2cb0e2cd909..905794d0336 100644 --- a/Mage/src/main/java/mage/constants/SpellAbilityCastMode.java +++ b/Mage/src/main/java/mage/constants/SpellAbilityCastMode.java @@ -4,6 +4,7 @@ import mage.abilities.keyword.BestowAbility; import mage.abilities.keyword.MorphAbility; import mage.cards.Card; import mage.game.Game; +import mage.game.stack.Spell; /** * @author LevelX2 @@ -53,6 +54,10 @@ public enum SpellAbilityCastMode { } } if (this.equals(MORPH)) { + if (cardCopy instanceof Spell) { + //Spell doesn't support setName, so make a copy of the card (we're blowing it away anyway) + cardCopy = ((Spell) cardCopy).getCard().copy(); + } MorphAbility.setCardToFaceDownCreature(cardCopy); } return cardCopy;