From 339779c8bd7828e93da178fa69b5535ed960e464 Mon Sep 17 00:00:00 2001 From: dilnu Date: Sun, 29 Jul 2018 07:49:24 -0400 Subject: [PATCH 1/4] 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; } From 988b64866ce27f5e0819ff5aba2e48b6e9abcc30 Mon Sep 17 00:00:00 2001 From: dilnu Date: Sun, 29 Jul 2018 11:19:51 -0400 Subject: [PATCH 2/4] Fix a bug with Animar's cost reduction effect. --- .../mage/cards/a/AnimarSoulOfElements.java | 3 +- .../modification/CostModificationTest.java | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Mage.Sets/src/mage/cards/a/AnimarSoulOfElements.java b/Mage.Sets/src/mage/cards/a/AnimarSoulOfElements.java index 89381973065..c6bcf721ec7 100644 --- a/Mage.Sets/src/mage/cards/a/AnimarSoulOfElements.java +++ b/Mage.Sets/src/mage/cards/a/AnimarSoulOfElements.java @@ -11,6 +11,7 @@ import mage.abilities.common.SpellCastControllerTriggeredAbility; import mage.abilities.effects.common.cost.CostModificationEffectImpl; import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.abilities.keyword.ProtectionAbility; +import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.*; @@ -85,7 +86,7 @@ class AnimarCostReductionEffect extends CostModificationEffectImpl { public boolean applies(Ability abilityToModify, Ability source, Game game) { if (abilityToModify instanceof SpellAbility) { if (abilityToModify.isControlledBy(source.getControllerId())) { - Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId()); + Card spell = ((SpellAbility) abilityToModify).getCharachteristics(game); if (spell != null) { return spell.isCreature(); } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/cost/modification/CostModificationTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/cost/modification/CostModificationTest.java index a682ccc2b3f..c6ad81be4b1 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/cost/modification/CostModificationTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/cost/modification/CostModificationTest.java @@ -217,4 +217,34 @@ public class CostModificationTest extends CardTestPlayerBase { assertTappedCount("Plains", false, 2); // 2 for 1st Lion 1 for 2nd lion and only 1 mana needed to cast face down Zoetic } + + /** + * Zoetic Cavern's cast as creature cost is not modified as Animar, Soul of + * Elements gains counters. + */ + @Test + public void AnimarSoulOfElementsTest() { + + // Protection from white and from black + // Whenever you cast a creature spell, put a +1/+1 counter on Animar, Soul of Elements. + // Creature spells you cast cost {1} less to cast for each +1/+1 counter on Animar. + addCard(Zone.BATTLEFIELD, playerA, "Animar, Soul of Elements"); + + addCard(Zone.HAND, playerA, "Silvercoat Lion", 2); + addCard(Zone.BATTLEFIELD, playerA, "Plains", 3); + + addCard(Zone.HAND, playerA, "Zoetic Cavern"); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Silvercoat Lion"); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Silvercoat Lion"); + + setStopAt(1, PhaseStep.END_TURN); + execute(); + + assertPermanentCount(playerA, "Silvercoat Lion", 2); + assertCounterCount(playerA, "Animar, Soul of Elements", CounterType.P1P1, 2); + + assertTappedCount("Plains", true, 3); + + } } From 3e0a92fed8b940847877d30745ab3559f49eebdb Mon Sep 17 00:00:00 2001 From: dilnu Date: Sat, 4 Aug 2018 22:42:22 -0400 Subject: [PATCH 3/4] Fix a typo --- Mage.Sets/src/mage/cards/a/AnimarSoulOfElements.java | 3 +-- Mage/src/main/java/mage/abilities/SpellAbility.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Mage.Sets/src/mage/cards/a/AnimarSoulOfElements.java b/Mage.Sets/src/mage/cards/a/AnimarSoulOfElements.java index c6bcf721ec7..f7291fa1123 100644 --- a/Mage.Sets/src/mage/cards/a/AnimarSoulOfElements.java +++ b/Mage.Sets/src/mage/cards/a/AnimarSoulOfElements.java @@ -19,7 +19,6 @@ import mage.counters.CounterType; import mage.filter.StaticFilters; import mage.game.Game; import mage.game.permanent.Permanent; -import mage.game.stack.Spell; import mage.util.CardUtil; /** @@ -86,7 +85,7 @@ class AnimarCostReductionEffect extends CostModificationEffectImpl { public boolean applies(Ability abilityToModify, Ability source, Game game) { if (abilityToModify instanceof SpellAbility) { if (abilityToModify.isControlledBy(source.getControllerId())) { - Card spell = ((SpellAbility) abilityToModify).getCharachteristics(game); + Card spell = ((SpellAbility) abilityToModify).getCharacteristics(game); if (spell != null) { return spell.isCreature(); } diff --git a/Mage/src/main/java/mage/abilities/SpellAbility.java b/Mage/src/main/java/mage/abilities/SpellAbility.java index 83f63ce5f84..201d2deb349 100644 --- a/Mage/src/main/java/mage/abilities/SpellAbility.java +++ b/Mage/src/main/java/mage/abilities/SpellAbility.java @@ -212,7 +212,7 @@ public class SpellAbility extends ActivatedAbilityImpl { return this; } - public Card getCharachteristics(Game game) { + public Card getCharacteristics(Game game) { Spell spell = game.getSpell(this.getId()); if (spell != null) { return spell; From c4a68f23eccd3db99815b23912622091f77d11be Mon Sep 17 00:00:00 2001 From: dilnu Date: Tue, 14 Aug 2018 21:26:44 -0400 Subject: [PATCH 4/4] Update a comment. --- .../test/cards/cost/modification/CostModificationTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/cost/modification/CostModificationTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/cost/modification/CostModificationTest.java index c6ad81be4b1..40ffdc079f8 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/cost/modification/CostModificationTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/cost/modification/CostModificationTest.java @@ -219,8 +219,7 @@ public class CostModificationTest extends CardTestPlayerBase { } /** - * Zoetic Cavern's cast as creature cost is not modified as Animar, Soul of - * Elements gains counters. + * Confirm that Animar's cost reduction allows you to play spells that you wouldn't have enough mana for without it. */ @Test public void AnimarSoulOfElementsTest() {