diff --git a/Mage.Sets/src/mage/sets/darkascension/HuntmasterOfTheFells.java b/Mage.Sets/src/mage/sets/darkascension/HuntmasterOfTheFells.java index 9abcbef1eb5..d9e31790878 100644 --- a/Mage.Sets/src/mage/sets/darkascension/HuntmasterOfTheFells.java +++ b/Mage.Sets/src/mage/sets/darkascension/HuntmasterOfTheFells.java @@ -132,7 +132,7 @@ class HuntmasterOfTheFellsAbility extends TriggeredAbilityImpl { @Override public Set possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) { Set availablePossibleTargets = super.possibleTargets(sourceId, sourceControllerId, game); - Set possibleTargets = new HashSet(); + Set possibleTargets = new HashSet<>(); MageObject object = game.getObject(sourceId); for (StackObject item: game.getState().getStack()) { 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 4d59fea2ffe..f78d2cf631e 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 @@ -55,7 +55,7 @@ public class CloudshiftTest extends CardTestPlayerBase { castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Clone"); setChoice(playerA, "Knight of Meadowgrain"); - castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Cloudshift", "Clone"); + castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Cloudshift", "Knight of Meadowgrain"); // clone has name of copied permanent setChoice(playerA, "Heirs of Stromkirk"); setStopAt(1, PhaseStep.END_TURN); diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/counterspell/SecondGuessTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/counterspell/SecondGuessTest.java index 583976c74b5..df49bc6bd3d 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/counterspell/SecondGuessTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/counterspell/SecondGuessTest.java @@ -11,6 +11,9 @@ import org.mage.test.serverside.base.CardTestPlayerBase; */ public class SecondGuessTest extends CardTestPlayerBase { + /** + * Counter target spell that's the second spell cast this turn. + */ @Test public void testCounterFirstSpell() { addCard(Zone.HAND, playerA, "Lightning Bolt"); @@ -36,11 +39,12 @@ public class SecondGuessTest extends CardTestPlayerBase { addCard(Zone.HAND, playerA, "Shock", 1); addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2); addCard(Zone.BATTLEFIELD, playerA, "Island", 2); + addCard(Zone.HAND, playerA, "Second Guess"); castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB); castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Shock", playerB); - castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Second Guess", "Lightning Bolt"); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Second Guess", "Shock"); setStopAt(1, PhaseStep.END_TURN); execute(); @@ -56,14 +60,14 @@ public class SecondGuessTest extends CardTestPlayerBase { public void testCounterThirdSpell() { addCard(Zone.HAND, playerA, "Lightning Bolt", 2); addCard(Zone.HAND, playerA, "Shock", 1); - addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3); + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3); addCard(Zone.BATTLEFIELD, playerA, "Island", 2); addCard(Zone.HAND, playerA, "Second Guess"); castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB); castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB); castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Shock", playerB); - castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Second Guess", "Shock"); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Second Guess", "Shock"); // can't be cast (no valid target), so Secon Guess spell stays on hand setStopAt(1, PhaseStep.END_TURN); execute(); @@ -71,8 +75,8 @@ public class SecondGuessTest extends CardTestPlayerBase { assertLife(playerA, 20); assertLife(playerB, 12); - assertHandCount(playerA, 0); - assertGraveyardCount(playerA, 4); + assertHandCount(playerA, 1); + assertGraveyardCount(playerA, 3); } /** diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/copy/PhantasmalImageTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/copy/PhantasmalImageTest.java index c4db153102f..1612018a176 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/copy/PhantasmalImageTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/copy/PhantasmalImageTest.java @@ -129,14 +129,16 @@ public class PhantasmalImageTest extends CardTestPlayerBase { addCard(Zone.BATTLEFIELD, playerB, "Forest", 2); addCard(Zone.HAND, playerB, "Phantasmal Image"); addCard(Zone.HAND, playerB, "Titanic Growth"); + addCard(Zone.BATTLEFIELD, playerA, "Huntmaster of the Fells"); castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Phantasmal Image"); - castSpell(2, PhaseStep.POSTCOMBAT_MAIN, playerB, "Titanic Growth", "Ravager of the Fells-M12"); + castSpell(2, PhaseStep.POSTCOMBAT_MAIN, playerB, "Titanic Growth", "Ravager of the Fells"); setStopAt(2, PhaseStep.END_TURN); execute(); + assertLife(playerB, 18); // check opponent's creature wasn't chosen as a target for Titanic Growth assertPowerToughness(playerA, "Ravager of the Fells", 4, 4); // check playerA's creature was sacrificed diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/FaithsShieldTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/FaithsShieldTest.java index 26743357944..de3b0b0dd85 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/single/FaithsShieldTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/FaithsShieldTest.java @@ -30,7 +30,7 @@ public class FaithsShieldTest extends CardTestPlayerBase { execute(); assertLife(playerA, 20); - assertLife(playerB, 17); + assertLife(playerB, 20); assertPermanentCount(playerA, "White Knight", 1); } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/IncreasingCardsTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/IncreasingCardsTest.java index b7a70b17677..9824db3d497 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/single/IncreasingCardsTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/IncreasingCardsTest.java @@ -14,6 +14,14 @@ import org.mage.test.serverside.base.CardTestPlayerBase; */ public class IncreasingCardsTest extends CardTestPlayerBase { + /** + * Increasing Ambition + * Sorcery, 4B + * Search your library for a card and put that card into your hand. If Increasing + * Ambition was cast from a graveyard, instead search your library for two cards + * and put those cards into your hand. Then shuffle your library. + * Flashback {7}{B} (You may cast this card from your graveyard for its flashback cost. Then exile it.) + */ @Test public void testIncreasingAmbition() { removeAllCardsFromHand(playerA); 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 eed69d091e1..d7aa681afdc 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 @@ -63,9 +63,9 @@ import mage.filter.common.FilterCreatureForCombatBlock; @Ignore public class TestPlayer extends ComputerPlayer { - private List actions = new ArrayList(); - private List choices = new ArrayList(); - private List targets = new ArrayList(); + private final List actions = new ArrayList<>(); + private final List choices = new ArrayList<>(); + private final List targets = new ArrayList<>(); public TestPlayer(String name, RangeOfInfluence range) { super(name, range); @@ -103,10 +103,14 @@ public class TestPlayer extends ComputerPlayer { String[] groups = command.split(";"); for (Ability ability: this.getPlayable(game, true)) { if (ability.toString().startsWith(groups[0])) { + Ability newAbility = ability.copy(); if (groups.length > 1) { - addTargets(ability, groups, game); + if (!addTargets(newAbility, groups, game)) { + // targets could not be set -> try next priority + break; + } } - this.activateAbility((ActivatedAbility)ability, game); + this.activateAbility((ActivatedAbility)newAbility, game); actions.remove(action); return true; } @@ -261,30 +265,38 @@ public class TestPlayer extends ComputerPlayer { return null; } - private void addTargets(Ability ability, String[] groups, Game game) { + private boolean addTargets(Ability ability, String[] groups, Game game) { + boolean result = true; for (int i = 1; i < groups.length; i++) { String group = groups[i]; String target; if (group.startsWith("targetPlayer=")) { + int targetsSet = 0; target = group.substring(group.indexOf("targetPlayer=") + 13); for (Player player: game.getPlayers().values()) { if (player.getName().equals(target)) { ability.getTargets().get(0).addTarget(player.getId(), ability, game); + targetsSet++; break; } } + if (targetsSet < 1) { + result = false; + } } else if (group.startsWith("target=")) { target = group.substring(group.indexOf("target=") + 7); - String[] targets = target.split("\\^"); + String[] targetList = target.split("\\^"); int index = 0; - for (String t: targets) { - if (t.startsWith("targetPlayer=")) { - target = t.substring(t.indexOf("targetPlayer=") + 13); + int targetsSet = 0; + for (String targetName: targetList) { + if (targetName.startsWith("targetPlayer=")) { + target = targetName.substring(targetName.indexOf("targetPlayer=") + 13); for (Player player: game.getPlayers().values()) { if (player.getName().equals(target)) { ability.getTargets().get(index).addTarget(player.getId(), ability, game); index++; + targetsSet++; break; } } @@ -294,7 +306,7 @@ public class TestPlayer extends ComputerPlayer { } for (UUID id: ability.getTargets().get(0).possibleTargets(ability.getSourceId(), ability.getControllerId(), game)) { MageObject object = game.getObject(id); - if (object != null && object.getName().equals(t)) { + if (object != null && object.getName().equals(targetName)) { if (index >= ability.getTargets().size()) { index--; } @@ -307,8 +319,10 @@ public class TestPlayer extends ComputerPlayer { targetAmount.setAmount(ability, game); int amount = targetAmount.getAmountRemaining(); targetAmount.addTarget(id, amount,ability, game); + targetsSet++; } else { ability.getTargets().get(index).addTarget(id, ability, game); + targetsSet++; } index++; break; @@ -316,8 +330,12 @@ public class TestPlayer extends ComputerPlayer { } } } + if (targetsSet != targetList.length) { + result = false; + } } } + return result; } } 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 4bbcc3e87db..cfe5bbf0708 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 @@ -41,6 +41,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement /** * Default game initialization params for red player (that plays with Mountains) */ + @Override public void useRedDefault() { // *** ComputerA *** // battlefield:ComputerA:Mountain:5 @@ -105,6 +106,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement * * @param player {@link Player} to remove all library cards from. */ + @Override public void removeAllCardsFromLibrary(TestPlayer player) { getCommands(player).put(Zone.LIBRARY, "clear"); } @@ -126,6 +128,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement * @param player {@link Player} to add cards for. Use either playerA or playerB. * @param cardName Card name in string format. */ + @Override public void addCard(Zone gameZone, TestPlayer player, String cardName) { addCard(gameZone, player, cardName, 1, false); } @@ -138,6 +141,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement * @param cardName Card name in string format. * @param count Amount of cards to be added. */ + @Override public void addCard(Zone gameZone, TestPlayer player, String cardName, int count) { addCard(gameZone, player, cardName, count, false); } @@ -152,6 +156,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement * @param tapped In case gameZone is Battlefield, determines whether permanent should be tapped. * In case gameZone is other than Battlefield, {@link IllegalArgumentException} is thrown */ + @Override public void addCard(Zone gameZone, TestPlayer player, String cardName, int count, boolean tapped) { if (gameZone.equals(Zone.BATTLEFIELD)) { @@ -206,13 +211,16 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement * @param player {@link Player} to set life count for. * @param life Life count to set. */ + @Override public void setLife(TestPlayer player, int life) { getCommands(player).put(Zone.OUTSIDE, "life:" + String.valueOf(life)); } /** * Define turn number to stop the game on. + * @param turn */ + @Override public void setStopOnTurn(int turn) { stopOnTurn = turn == -1 ? null : Integer.valueOf(turn); stopAtStep = PhaseStep.UNTAP; @@ -220,7 +228,10 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement /** * Define turn number and step to stop the game on. + * @param turn + * @param step */ + @Override public void setStopAt(int turn, PhaseStep step) { stopOnTurn = turn == -1 ? null : Integer.valueOf(turn); stopAtStep = step; @@ -231,6 +242,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement * * @param turn Expected turn number to compare with. 1-based. */ + @Override public void assertTurn(int turn) throws AssertionError { Assert.assertEquals("Turn numbers are not equal", turn, currentGame.getTurnNum()); } @@ -240,6 +252,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement * * @param result Expected {@link GameResult} to compare with. */ + @Override public void assertResult(Player player, GameResult result) throws AssertionError { if (player.equals(playerA)) { GameResult actual = CardTestAPI.GameResult.DRAW; @@ -266,6 +279,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement * @param player {@link Player} to get life for comparison. * @param life Expected player's life to compare with. */ + @Override public void assertLife(Player player, int life) throws AssertionError { int actual = currentGame.getPlayer(player.getId()).getLife(); Assert.assertEquals("Life amounts are not equal for player " + player.getName(), life, actual); @@ -288,6 +302,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement * @param scope {@link mage.filter.Filter.ComparisonScope} Use ANY, if you want "at least one creature with given name should have specified p\t" * Use ALL, if you want "all creature with gived name should have specified p\t" */ + @Override public void assertPowerToughness(Player player, String cardName, int power, int toughness, Filter.ComparisonScope scope) throws AssertionError { int count = 0; @@ -339,6 +354,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement /** * {@inheritDoc} */ + @Override public void assertAbilities(Player player, String cardName, List abilities) throws AssertionError { int count = 0; @@ -401,6 +417,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement * @param player {@link Player} which permanents should be counted. * @param count Expected count. */ + @Override public void assertPermanentCount(Player player, int count) throws AssertionError { int actualCount = 0; for (Permanent permanent : currentGame.getBattlefield().getAllPermanents()) { @@ -418,6 +435,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement * @param cardName Name of the cards that should be counted. * @param count Expected count. */ + @Override public void assertPermanentCount(Player player, String cardName, int count) throws AssertionError { int actualCount = 0; for (Permanent permanent : currentGame.getBattlefield().getAllPermanents()) { diff --git a/Mage.Tests/src/test/java/org/mage/test/serverside/cards/effects/TestActivatedContinuousEffect.java b/Mage.Tests/src/test/java/org/mage/test/serverside/cards/effects/TestActivatedContinuousEffect.java index cf125d38b59..5c0f37cae8c 100644 --- a/Mage.Tests/src/test/java/org/mage/test/serverside/cards/effects/TestActivatedContinuousEffect.java +++ b/Mage.Tests/src/test/java/org/mage/test/serverside/cards/effects/TestActivatedContinuousEffect.java @@ -15,6 +15,7 @@ public class TestActivatedContinuousEffect extends CardTestPlayerBase { @Test public void testCard() { addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3); + // {R}: Target creature gets +1/+0 until end of turn. addCard(Zone.BATTLEFIELD, playerA, "Captive Flame"); addCard(Zone.BATTLEFIELD, playerA, "White Knight"); @@ -33,6 +34,7 @@ public class TestActivatedContinuousEffect extends CardTestPlayerBase { @Test public void testCard2() { addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3); + // {R}: Target creature gets +1/+0 until end of turn. addCard(Zone.BATTLEFIELD, playerA, "Captive Flame"); addCard(Zone.BATTLEFIELD, playerA, "White Knight");