From 339779c8bd7828e93da178fa69b5535ed960e464 Mon Sep 17 00:00:00 2001 From: dilnu Date: Sun, 29 Jul 2018 07:49:24 -0400 Subject: [PATCH] Add methods to get information about spells that have not yet been cast. --- .../java/mage/abilities/SpellAbility.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Mage/src/main/java/mage/abilities/SpellAbility.java b/Mage/src/main/java/mage/abilities/SpellAbility.java index 04e9d0cbc77..83f63ce5f84 100644 --- a/Mage/src/main/java/mage/abilities/SpellAbility.java +++ b/Mage/src/main/java/mage/abilities/SpellAbility.java @@ -1,6 +1,7 @@ package mage.abilities; +import java.util.Optional; import java.util.UUID; import mage.MageObject; import mage.MageObjectReference; @@ -19,6 +20,7 @@ import mage.constants.TimingRule; import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; +import mage.game.stack.Spell; import mage.players.Player; /** @@ -210,6 +212,26 @@ public class SpellAbility extends ActivatedAbilityImpl { return this; } + public Card getCharachteristics(Game game) { + Spell spell = game.getSpell(this.getId()); + if (spell != null) { + return spell; + } + return game.getCard(this.getSourceId()); + } + + public static SpellAbility getSpellAbilityFromEvent(GameEvent event, Game game) { + if (event.getType() != GameEvent.EventType.CAST_SPELL) { + return null; + } + Card card = game.getCard(event.getSourceId()); + Optional ability = card.getAbilities(game).get(event.getTargetId()); + if (ability.isPresent() && ability.get() instanceof SpellAbility) { + return (SpellAbility) ability.get(); + } + return card.getSpellAbility(); + } + public void setId(UUID idToUse) { this.id = idToUse; }