From cdbe09890db6093c0997e0627f2e8bacff909678 Mon Sep 17 00:00:00 2001 From: Quercitron Date: Fri, 15 Aug 2014 02:41:49 +0400 Subject: [PATCH] Add testThatCardIsHandledAsNewInstanceAfterCloudshift (issue with reference to object after multiple zone changing) --- .../abilities/flicker/CloudshiftTest.java | 20 +++++++++++++++++++ .../cards/abilities/keywords/PersistTest.java | 2 +- .../java/org/mage/test/player/TestPlayer.java | 20 ++++++++++++++++--- .../base/impl/CardTestPlayerAPIImpl.java | 11 ++++++++++ 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/flicker/CloudshiftTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/flicker/CloudshiftTest.java index 11f66246ea..7d6ac1c47f 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/flicker/CloudshiftTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/flicker/CloudshiftTest.java @@ -125,4 +125,24 @@ public class CloudshiftTest extends CardTestPlayerBase { } + @Test + public void testThatCardIsHandledAsNewInstanceAfterCloudshift() { + addCard(Zone.BATTLEFIELD, playerA, "Trostani, Selesnya's Voice"); + addCard(Zone.BATTLEFIELD, playerA, "Forest", 4); + addCard(Zone.BATTLEFIELD, playerA, "Plains", 4); + addCard(Zone.HAND, playerA, "Grizzly Bears"); + addCard(Zone.HAND, playerA, "Giant Growth"); + addCard(Zone.HAND, playerA, "Cloudshift"); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Grizzly Bears"); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Giant Growth", "Grizzly Bears", "you gain life equal to that creature's toughness"); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cloudshift", "Grizzly Bears", null, "you gain life equal to that creature's toughness"); + + setStopAt(1, PhaseStep.POSTCOMBAT_MAIN); + + execute(); + + assertLife(playerA, 27); + } + } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/PersistTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/PersistTest.java index 7d96541cfe..d0d3e2ff57 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/PersistTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/PersistTest.java @@ -119,7 +119,7 @@ public class PersistTest extends CardTestPlayerBase { castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerB, "Lightning Bolt", "Safehold Elite"); // choose triggered ability order playerA.addChoice("When enchanted creature dies, put X 1/1 red and white Soldier creature token with haste onto the battlefield, where X is its power."); - castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerB, "Lightning Bolt", "Safehold Elite", "When enchanted creature dies, put X 1/1 red and white Soldier creature token with haste onto the battlefield, where X is its power"); + //castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerB, "Lightning Bolt", "Safehold Elite", "When enchanted creature dies, put X 1/1 red and white Soldier creature token with haste onto the battlefield, where X is its power"); setStopAt(1, PhaseStep.END_TURN); execute(); diff --git a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java index 24b7d5d0fb..d18d751a5d 100644 --- a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java +++ b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java @@ -115,7 +115,7 @@ public class TestPlayer extends ComputerPlayer { String command = action.getAction(); command = command.substring(command.indexOf("activate:") + 9); String[] groups = command.split(";"); - if (!checkSpellOnStackCondition(groups, game)) { + if (!checkSpellOnStackCondition(groups, game) || !checkSpellOnTopOfStackCondition(groups, game)) { break; } for (Ability ability: this.getPlayable(game, true)) { @@ -371,7 +371,21 @@ public class TestPlayer extends ComputerPlayer { if (groups.length > 2 && groups[2].startsWith("spellOnStack=")) { String spellOnStack = groups[2].substring(13); for (StackObject stackObject: game.getStack()) { - if (stackObject.getStackAbility().toString().equals(spellOnStack)) { + if (stackObject.getStackAbility().toString().indexOf(spellOnStack) >= 0) { + return true; + } + } + return false; + } + return true; + } + + private boolean checkSpellOnTopOfStackCondition(String[] groups, Game game) { + if (groups.length > 2 && groups[2].startsWith("spellOnTopOfStack=")) { + String spellOnTopOFStack = groups[2].substring(18); + if (game.getStack().size() > 0) { + StackObject stackObject = game.getStack().getFirst(); + if (stackObject != null && stackObject.getStackAbility().toString().indexOf(spellOnTopOFStack) >= 0) { return true; } } @@ -384,7 +398,7 @@ public class TestPlayer extends ComputerPlayer { boolean result = true; for (int i = 1; i < groups.length; i++) { String group = groups[i]; - if (group.startsWith("spellOnStack")) { + if (group.startsWith("spellOnStack") || group.startsWith("spellOnTopOfStack")) { break; } if (ability instanceof SpellAbility && ((SpellAbility) ability).getSpellAbilityType().equals(SpellAbilityType.SPLIT_FUSED)) { diff --git a/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestPlayerAPIImpl.java b/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestPlayerAPIImpl.java index bcb986c593..325b9060d5 100644 --- a/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestPlayerAPIImpl.java +++ b/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestPlayerAPIImpl.java @@ -671,6 +671,17 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement player.addAction(turnNum, step, "activate:Cast " + cardName + ";target=" + targetName + ";spellOnStack=" + spellOnStack); } + public void castSpell(int turnNum, PhaseStep step, TestPlayer player, String cardName, String targetName, String spellOnStack, String spellOnTopOfStack) { + String action = "activate:Cast " + cardName + ";target=" + targetName; + if (spellOnStack != null && !spellOnStack.isEmpty()) { + action += ";spellOnStack=" + spellOnStack; + } + if (spellOnTopOfStack != null && !spellOnTopOfStack.isEmpty()) { + action += ";spellOnTopOfStack=" + spellOnTopOfStack; + } + player.addAction(turnNum, step, action); + } + public void activateAbility(int turnNum, PhaseStep step, TestPlayer player, String ability) { player.addAction(turnNum, step, "activate:" + ability); }