From 0d290a24310cb61b799ef18557add03928755d99 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sat, 29 Mar 2014 17:48:09 +0100 Subject: [PATCH] Tests - Added the possibility to attack planeswalker in tests- Added attack planeswalker test. --- .../counterspell/CrypticCommandTest.java | 4 +- .../test/combat/AttackPlaneswalkerTest.java | 98 +++++++++++++++++++ .../java/org/mage/test/player/TestPlayer.java | 27 ++++- .../base/impl/CardTestPlayerAPIImpl.java | 32 ++++-- 4 files changed, 147 insertions(+), 14 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/combat/AttackPlaneswalkerTest.java diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/counterspell/CrypticCommandTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/counterspell/CrypticCommandTest.java index e6c5b812a59..95c4286a157 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/counterspell/CrypticCommandTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/counterspell/CrypticCommandTest.java @@ -59,8 +59,8 @@ public class CrypticCommandTest extends CardTestPlayerBase { castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Thoughtseize", playerB); castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Cryptic Command", "Thoughtseize"); - setModeChoice(playerB, "0"); // Counter target spell - setModeChoice(playerB, "3"); // Draw a card + setModeChoice(playerB, "1"); // Counter target spell + setModeChoice(playerB, "4"); // Draw a card castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Remand", "Thoughtseize", "Cryptic Command"); diff --git a/Mage.Tests/src/test/java/org/mage/test/combat/AttackPlaneswalkerTest.java b/Mage.Tests/src/test/java/org/mage/test/combat/AttackPlaneswalkerTest.java new file mode 100644 index 00000000000..bc12728c631 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/combat/AttackPlaneswalkerTest.java @@ -0,0 +1,98 @@ +/* +* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are +* permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, this list of +* conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, this list +* of conditions and the following disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +* The views and conclusions contained in the software and documentation are those of the +* authors and should not be interpreted as representing official policies, either expressed +* or implied, of BetaSteward_at_googlemail.com. +*/ + + +package org.mage.test.combat; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import mage.counters.CounterType; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * Check if attacking a planswalker and removing loyality counter from damage works + * + * @author LevelX2 + */ +public class AttackPlaneswalkerTest extends CardTestPlayerBase { + + @Test + public void testAttackPlaneswalker() { + addCard(Zone.BATTLEFIELD, playerA, "Kiora, the Crashing Wave"); + addCard(Zone.BATTLEFIELD, playerB, "Giant Tortoise"); + + attack(2, playerB, "Giant Tortoise", "Kiora, the Crashing Wave"); + + setStopAt(2, PhaseStep.END_TURN); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + assertPermanentCount(playerA, "Kiora, the Crashing Wave", 1); + assertPermanentCount(playerB, "Giant Tortoise", 1); + assertCounterCount("Kiora, the Crashing Wave", CounterType.LOYALTY, 1); + } + + /** + * Tests that giving a planeswalker hexproof does not prevent opponent from attacking it + */ + @Test + public void testAttackPlaneswalkerWithHexproof() { + /* + Simic Charm English + Instant, UG + Choose one — Target creature gets +3/+3 until end of turn; + or permanents you control gain hexproof until end of turn; + or return target creature to its owner's hand. + */ + addCard(Zone.HAND, playerA, "Simic Charm"); + addCard(Zone.BATTLEFIELD, playerA, "Island"); + addCard(Zone.BATTLEFIELD, playerA, "Forest"); + addCard(Zone.BATTLEFIELD, playerA, "Kiora, the Crashing Wave"); + + addCard(Zone.BATTLEFIELD, playerB, "Giant Tortoise"); + + castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerA, "Simic Charm"); + setModeChoice(playerA, "2"); + + attack(2, playerB, "Giant Tortoise", "Kiora, the Crashing Wave"); + + setStopAt(2, PhaseStep.END_TURN); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + assertPermanentCount(playerA, "Kiora, the Crashing Wave", 1); + assertPermanentCount(playerB, "Giant Tortoise", 1); + assertCounterCount("Kiora, the Crashing Wave", CounterType.LOYALTY, 1); + } + +} 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 e9b95fe1964..3e65d839195 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 @@ -57,6 +57,7 @@ import java.util.UUID; import mage.abilities.Mode; import mage.abilities.Modes; import mage.filter.common.FilterCreatureForCombatBlock; +import mage.filter.common.FilterPlaneswalkerPermanent; import mage.game.stack.StackObject; /** @@ -147,16 +148,34 @@ public class TestPlayer extends ComputerPlayer { @Override public void selectAttackers(Game game, UUID attackingPlayerId) { - UUID opponentId = game.getCombat().getDefenders().iterator().next(); + UUID defenderId = null; for (PlayerAction action: actions) { if (action.getTurnNum() == game.getTurnNum() && action.getAction().startsWith("attack:")) { + for (UUID uuid: game.getCombat().getDefenders()) { + Player defender = game.getPlayer(uuid); + if (defender != null) { + defenderId = uuid; + } + } String command = action.getAction(); command = command.substring(command.indexOf("attack:") + 7); + String[] groups = command.split(";"); + for (int i = 1; i < groups.length; i++) { + String group = groups[i]; + if (group.startsWith("planeswalker=")) { + String planeswalkerName = group.substring(group.indexOf("planeswalker=") + 13); + for (Permanent permanent :game.getBattlefield().getAllActivePermanents(new FilterPlaneswalkerPermanent(), game)) { + if (permanent.getName().equals(planeswalkerName)) { + defenderId = permanent.getId(); + } + } + } + } FilterCreatureForCombat filter = new FilterCreatureForCombat(); - filter.add(new NamePredicate(command)); + filter.add(new NamePredicate(groups[0])); Permanent attacker = findPermanent(filter, playerId, game); if (attacker != null && attacker.canAttack(game)) { - this.declareAttacker(attacker.getId(), opponentId, game); + this.declareAttacker(attacker.getId(), defenderId, game); } } } @@ -189,7 +208,7 @@ public class TestPlayer extends ComputerPlayer { public Mode chooseMode(Modes modes, Ability source, Game game) { if (!modesSet.isEmpty() && modes.getMaxModes() > modes.getSelectedModes().size()) { int selectedMode = Integer.parseInt(modesSet.get(0)); - int i = 0; + int i = 1; for (Mode mode: modes.values()) { if (i == selectedMode) { modesSet.remove(0); 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 86c3ff5c4b2..43dcec4b9af 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 @@ -256,18 +256,24 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement public void assertResult(Player player, GameResult result) throws AssertionError { if (player.equals(playerA)) { GameResult actual = CardTestAPI.GameResult.DRAW; - if (currentGame.getWinner().equals("Player PlayerA is the winner")) { - actual = CardTestAPI.GameResult.WON; - } else if (currentGame.getWinner().equals("Player PlayerB is the winner")) { - actual = CardTestAPI.GameResult.LOST; + switch (currentGame.getWinner()) { + case "Player PlayerA is the winner": + actual = CardTestAPI.GameResult.WON; + break; + case "Player PlayerB is the winner": + actual = CardTestAPI.GameResult.LOST; + break; } Assert.assertEquals("Game results are not equal", result, actual); } else if (player.equals(playerB)) { GameResult actual = CardTestAPI.GameResult.DRAW; - if (currentGame.getWinner().equals("Player PlayerB is the winner")) { - actual = CardTestAPI.GameResult.WON; - } else if (currentGame.getWinner().equals("Player PlayerA is the winner")) { - actual = CardTestAPI.GameResult.LOST; + switch (currentGame.getWinner()) { + case "Player PlayerB is the winner": + actual = CardTestAPI.GameResult.WON; + break; + case "Player PlayerA is the winner": + actual = CardTestAPI.GameResult.LOST; + break; } Assert.assertEquals("Game results are not equal", result, actual); } @@ -668,6 +674,10 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement player.addAction(turnNum, PhaseStep.DECLARE_ATTACKERS, "attack:"+attacker); } + public void attack(int turnNum, TestPlayer player, String attacker, String planeswalker) { + player.addAction(turnNum, PhaseStep.DECLARE_ATTACKERS, new StringBuilder("attack:").append(attacker).append(";planeswalker=").append(planeswalker).toString()); + } + public void block(int turnNum, TestPlayer player, String blocker, String attacker) { player.addAction(turnNum, PhaseStep.DECLARE_BLOCKERS, "block:"+blocker+";"+attacker); } @@ -676,6 +686,12 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement player.addChoice(choice); } + /** + * Set the modes for modal spells + * + * @param player + * @param choice starting with "1" for mode 1, "2" for mode 2 and so on (to set multiple modes call the command multiple times) + */ public void setModeChoice(TestPlayer player, String choice) { player.addModeChoice(choice); }