From 70b040473bbe4075c8ec5960bcf91fe692509930 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Tue, 27 Jul 2021 20:53:43 -0400 Subject: [PATCH] updated ManaSpentToCastCount, added tests --- .../conditional/ManaWasSpentToCastTest.java | 36 +++++++++++++++++++ .../common/ManaSpentToCastCount.java | 19 ++-------- .../common/ManaPaidSourceWatcher.java | 7 ++++ 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/conditional/ManaWasSpentToCastTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/conditional/ManaWasSpentToCastTest.java index 95fe8dc984..2e55043b6e 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/conditional/ManaWasSpentToCastTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/conditional/ManaWasSpentToCastTest.java @@ -5,6 +5,7 @@ import mage.abilities.keyword.FirstStrikeAbility; import mage.abilities.keyword.HasteAbility; import mage.constants.PhaseStep; import mage.constants.Zone; +import mage.counters.CounterType; import org.junit.Test; import org.mage.test.serverside.base.CardTestPlayerBase; @@ -136,4 +137,39 @@ public class ManaWasSpentToCastTest extends CardTestPlayerBase { assertAbility(playerA, "Jaded Sell-Sword", FirstStrikeAbility.getInstance(), false); assertAbility(playerA, "Jaded Sell-Sword", HasteAbility.getInstance(), false); } + + @Test + public void testVerazol() { + addCard(Zone.BATTLEFIELD, playerA, "Island", 2); + addCard(Zone.BATTLEFIELD, playerA, "Forest", 2); + addCard(Zone.HAND, playerA, "Verazol, the Split Current"); + + setChoice(playerA, "X=2"); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Verazol, the Split Current"); + + setStopAt(1, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + + assertCounterCount(playerA, "Verazol, the Split Current", CounterType.P1P1, 4); + assertPowerToughness(playerA, "Verazol, the Split Current", 4, 4); + } + + @Test + public void testProssh() { + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2); + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2); + addCard(Zone.BATTLEFIELD, playerA, "Forest", 2); + addCard(Zone.BATTLEFIELD, playerA, "Wastes"); + addCard(Zone.BATTLEFIELD, playerA, "Sphere of Resistance"); + addCard(Zone.HAND, playerA, "Prossh, Skyraider of Kher"); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Prossh, Skyraider of Kher"); + + setStopAt(1, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + + assertPermanentCount(playerA, "Kobolds of Kher Keep", 7); + } } diff --git a/Mage/src/main/java/mage/abilities/dynamicvalue/common/ManaSpentToCastCount.java b/Mage/src/main/java/mage/abilities/dynamicvalue/common/ManaSpentToCastCount.java index 7bf9db05fa..76b707b71a 100644 --- a/Mage/src/main/java/mage/abilities/dynamicvalue/common/ManaSpentToCastCount.java +++ b/Mage/src/main/java/mage/abilities/dynamicvalue/common/ManaSpentToCastCount.java @@ -1,13 +1,10 @@ - package mage.abilities.dynamicvalue.common; -import mage.MageObject; import mage.abilities.Ability; import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.effects.Effect; -import mage.constants.Zone; import mage.game.Game; -import mage.game.stack.Spell; +import mage.watchers.common.ManaPaidSourceWatcher; /** * @author LevelX2 @@ -17,18 +14,7 @@ public enum ManaSpentToCastCount implements DynamicValue { @Override public int calculate(Game game, Ability sourceAbility, Effect effect) { - Spell spell = game.getStack().getSpell(sourceAbility.getSourceId()); - if (spell == null) { - MageObject mageObject = game.getLastKnownInformation(sourceAbility.getSourceId(), Zone.STACK); - if (mageObject instanceof Spell) { - spell = (Spell) mageObject; - } - } - if (spell != null) { - // NOT the cmc of the spell on the stack - return spell.getSpellAbility().getManaCostsToPay().manaValue(); - } - return 0; + return ManaPaidSourceWatcher.getTotalPaid(sourceAbility.getSourceId(), game); } @Override @@ -45,5 +31,4 @@ public enum ManaSpentToCastCount implements DynamicValue { public String getMessage() { return "the amount of mana spent to cast it"; } - } diff --git a/Mage/src/main/java/mage/watchers/common/ManaPaidSourceWatcher.java b/Mage/src/main/java/mage/watchers/common/ManaPaidSourceWatcher.java index f08c20e10e..bc501dc91b 100644 --- a/Mage/src/main/java/mage/watchers/common/ManaPaidSourceWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/ManaPaidSourceWatcher.java @@ -26,6 +26,7 @@ import java.util.UUID; public class ManaPaidSourceWatcher extends Watcher { private static final class ManaPaidTracker implements Serializable { + private int total = 0; private int whiteSnow = 0; private int blueSnow = 0; private int blackSnow = 0; @@ -35,6 +36,7 @@ public class ManaPaidSourceWatcher extends Watcher { private int treasure = 0; private void increment(MageObject sourceObject, ManaType manaType, Game game) { + total++; if (sourceObject.hasSubtype(SubType.TREASURE, game)) { treasure++; } @@ -108,6 +110,11 @@ public class ManaPaidSourceWatcher extends Watcher { manaMap.clear(); } + public static int getTotalPaid(UUID sourceId, Game game) { + ManaPaidSourceWatcher watcher = game.getState().getWatcher(ManaPaidSourceWatcher.class); + return watcher == null ? 0 : watcher.manaMap.getOrDefault(sourceId, emptyTracker).total; + } + public static int getTreasurePaid(UUID sourceId, Game game) { ManaPaidSourceWatcher watcher = game.getState().getWatcher(ManaPaidSourceWatcher.class); return watcher == null ? 0 : watcher.manaMap.getOrDefault(sourceId, emptyTracker).treasure;