From 2f72726a7fb7ea966e4a5addd782ec9dfe885853 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Mon, 24 Jun 2019 19:20:03 -0400 Subject: [PATCH] fixed implementation of Embodiment of Agonies, added a test --- .../src/mage/cards/e/EmbodimentOfAgonies.java | 31 ++++-- .../cards/single/EmbodimentOfAgoniesTest.java | 100 ++++++++++++++++++ 2 files changed, 123 insertions(+), 8 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/single/EmbodimentOfAgoniesTest.java diff --git a/Mage.Sets/src/mage/cards/e/EmbodimentOfAgonies.java b/Mage.Sets/src/mage/cards/e/EmbodimentOfAgonies.java index 7420ba45077..dec776690b9 100644 --- a/Mage.Sets/src/mage/cards/e/EmbodimentOfAgonies.java +++ b/Mage.Sets/src/mage/cards/e/EmbodimentOfAgonies.java @@ -3,6 +3,8 @@ package mage.cards.e; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldAbility; +import mage.abilities.costs.mana.ManaCost; +import mage.abilities.costs.mana.ManaCosts; import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.effects.Effect; import mage.abilities.effects.common.counter.AddCountersSourceEffect; @@ -16,9 +18,7 @@ import mage.counters.CounterType; import mage.game.Game; import mage.players.Player; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; +import java.util.*; /** * @author TheElk801 @@ -68,11 +68,7 @@ enum EmbodimentOfAgoniesValue implements DynamicValue { .getCards(game) .stream() .filter(card -> !card.isLand()) - .forEach(card -> card - .getManaCost() - .stream() - .forEach(manaCost -> stringSet.add(manaCost.getText())) - ); + .forEach(card -> stringSet.add(getCosts(card.getManaCost()))); stringSet.removeIf(s -> s == null || s.equals("")); return stringSet.size(); } @@ -86,4 +82,23 @@ enum EmbodimentOfAgoniesValue implements DynamicValue { public String getMessage() { return ""; } + + private static String getCosts(ManaCosts costs) { + List newList = new ArrayList(); + int generic = 0; + boolean hasGeneric = false; + for (String s : costs.getSymbols()) { + if (s.matches("\\{\\d*\\}")) { + generic += Integer.parseInt(s.substring(1, s.length() - 1)); + hasGeneric = true; + } else { + newList.add(s); + } + } + Collections.sort(newList); + if (hasGeneric) { + newList.add("{" + generic + "}"); + } + return String.join("", newList); + } } \ No newline at end of file diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/EmbodimentOfAgoniesTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/EmbodimentOfAgoniesTest.java new file mode 100644 index 00000000000..eac8239cd63 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/EmbodimentOfAgoniesTest.java @@ -0,0 +1,100 @@ +package org.mage.test.cards.single; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * @author TheElk801 + */ +public class EmbodimentOfAgoniesTest extends CardTestPlayerBase { + + @Test + public void testCard() { + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 3); + addCard(Zone.HAND, playerA, "Embodiment of Agonies"); + addCard(Zone.GRAVEYARD, playerA, "Rakdos Cackler"); // Mana Cost: {B/R} + addCard(Zone.GRAVEYARD, playerA, "Surgical Extraction"); // Mana Cost: {B/P} + addCard(Zone.GRAVEYARD, playerA, "Tormented Soul"); // Mana Cost: {B} + addCard(Zone.GRAVEYARD, playerA, "Gut Shot"); // Mana Cost: {R/P} + addCard(Zone.GRAVEYARD, playerA, "Lightning Bolt"); // Mana Cost: {R} + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Embodiment of Agonies"); + + setStopAt(1, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + + // Creature should be 5/5 as there are 5 distinct mana costs in graveyard + assertPowerToughness(playerA, "Embodiment of Agonies", 5, 5); + } + + @Test + public void testCard2() { + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 3); + addCard(Zone.HAND, playerA, "Embodiment of Agonies"); + addCard(Zone.GRAVEYARD, playerA, "Turn // Burn"); // Mana Cost: {3}{U}{R} + addCard(Zone.GRAVEYARD, playerA, "Prophetic Bolt"); // Mana Cost: {3}{U}{R} + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Embodiment of Agonies"); + + setStopAt(1, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + + // Creature should be 1/1 as there 1 distinct mana cost in graveyard + assertPowerToughness(playerA, "Embodiment of Agonies", 1, 1); + } + + @Test + public void testCard3() { + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 3); + addCard(Zone.HAND, playerA, "Embodiment of Agonies"); + addCard(Zone.GRAVEYARD, playerA, "Turn // Burn"); // Mana Cost: {3}{U}{R} + addCard(Zone.GRAVEYARD, playerA, "Divination"); // Mana Cost: {2}{U} + addCard(Zone.GRAVEYARD, playerA, "Magma Jet"); // Mana Cost: {1}{R} + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Embodiment of Agonies"); + + setStopAt(1, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + + // Creature should be 3/3 as there are 3 distinct mana costs in graveyard + assertPowerToughness(playerA, "Embodiment of Agonies", 3, 3); + } + + @Test + public void testCard4() { + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 3); + addCard(Zone.HAND, playerA, "Embodiment of Agonies"); + addCard(Zone.GRAVEYARD, playerA, "Ancestral Vision"); // No Mana Cost + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Embodiment of Agonies"); + + setStopAt(1, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + + // Creature should be dead as there are no mana costs in graveyards + assertGraveyardCount(playerA, "Embodiment of Agonies", 1); + } + + @Test + public void testCard5() { + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 3); + addCard(Zone.HAND, playerA, "Embodiment of Agonies"); + addCard(Zone.GRAVEYARD, playerA, "Lightning Bolt"); // Mana Cost: {R} + addCard(Zone.GRAVEYARD, playerA, "Fireball"); // Mana Cost: {X}{R} + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Embodiment of Agonies"); + + setStopAt(1, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + + // Creature should be dead as there are no mana costs in graveyards + assertGraveyardCount(playerA, "Embodiment of Agonies", 1); + } +}