From 535e49b89f4db4c770e0bd47d7a4ba40e0179e71 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Fri, 4 Sep 2020 02:18:40 +0400 Subject: [PATCH] Test framework: added aliases support for activated abilities (related to #7036); --- .../abilities/activated/LightningStormTest.java | 6 +++--- .../test/java/org/mage/test/player/TestPlayer.java | 3 ++- .../serverside/base/impl/CardTestPlayerAPIImpl.java | 10 +++++----- .../test/java/org/mage/test/testapi/TestAliases.java | 12 +++++++++--- Mage/src/main/java/mage/players/PlayerImpl.java | 4 +++- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/activated/LightningStormTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/activated/LightningStormTest.java index 8c900e619c..e59a302c23 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/activated/LightningStormTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/activated/LightningStormTest.java @@ -33,9 +33,9 @@ public class LightningStormTest extends CardTestPlayerBase { // B discard and re-target activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Discard"); - setChoice(playerB, "Mountain"); - setChoice(playerB, "Yes"); - addTarget(playerB, playerA); + setChoice(playerB, "Yes"); // change target + addTarget(playerB, playerA); // new target + setChoice(playerB, "Mountain"); // discard cost // A discard and re-target activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Discard"); 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 00a4c0a169..75999b3022 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 @@ -578,7 +578,8 @@ public class TestPlayer implements Player { if (groups.length > 2 && !checkExecuteCondition(groups, game)) { break; } - for (ActivatedAbility ability : computerPlayer.getPlayable(game, true)) { // add wrong action log? + // must process all duplicated abilities (aliases need objects to search) + for (ActivatedAbility ability : computerPlayer.getPlayable(game, true, Zone.ALL, false)) { // add wrong action log? if (hasAbilityTargetNameOrAlias(game, ability, groups[0])) { int bookmark = game.bookmarkState(); ActivatedAbility newAbility = ability.copy(); 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 5df4d662a7..67b1ce7e49 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 @@ -1728,19 +1728,19 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement public void activateAbility(int turnNum, PhaseStep step, TestPlayer player, String ability) { // TODO: it's uses computerPlayer to execute, only ability target will work, but choices and targets commands aren't - assertAliaseSupportInActivateCommand(ability, false); + assertAliaseSupportInActivateCommand(ability, true); addPlayerAction(player, turnNum, step, ACTIVATE_ABILITY + ability); } public void activateAbility(int turnNum, PhaseStep step, TestPlayer player, String ability, Player target) { // TODO: it's uses computerPlayer to execute, only ability target will work, but choices and targets commands aren't - assertAliaseSupportInActivateCommand(ability, false); + assertAliaseSupportInActivateCommand(ability, true); addPlayerAction(player, turnNum, step, ACTIVATE_ABILITY + ability + "$targetPlayer=" + target.getName()); } public void activateAbility(int turnNum, PhaseStep step, TestPlayer player, String ability, String... targetNames) { // TODO: it's uses computerPlayer to execute, only ability target will work, but choices and targets commands aren't - assertAliaseSupportInActivateCommand(ability, false); + assertAliaseSupportInActivateCommand(ability, true); Arrays.stream(targetNames).forEach(n -> { assertAliaseSupportInActivateCommand(n, true); }); @@ -1771,8 +1771,8 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement * @param clause */ public void activateAbility(int turnNum, PhaseStep step, TestPlayer player, String ability, String targetName, String spellOnStack, StackClause clause) { - assertAliaseSupportInActivateCommand(ability, false); - assertAliaseSupportInActivateCommand(targetName, false); + assertAliaseSupportInActivateCommand(ability, true); + assertAliaseSupportInActivateCommand(targetName, true); StringBuilder sb = new StringBuilder(ACTIVATE_ABILITY).append(ability); if (targetName != null && !targetName.isEmpty()) { sb.append("$target=").append(targetName); diff --git a/Mage.Tests/src/test/java/org/mage/test/testapi/TestAliases.java b/Mage.Tests/src/test/java/org/mage/test/testapi/TestAliases.java index 663d280142..577c816bbc 100644 --- a/Mage.Tests/src/test/java/org/mage/test/testapi/TestAliases.java +++ b/Mage.Tests/src/test/java/org/mage/test/testapi/TestAliases.java @@ -205,12 +205,14 @@ public class TestAliases extends CardTestPlayerBase { @Test public void test_ActivateAbility_Alias() { // {T}: Embermage Goblin deals 1 damage to any target. - addCard(Zone.BATTLEFIELD, playerA, "Embermage Goblin@goblin", 2); + addCard(Zone.BATTLEFIELD, playerA, "Embermage Goblin@goblin", 3); addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion@lion", 1); + // use 2 of 3 goblins showAvailableAbilities("before", 1, PhaseStep.PRECOMBAT_MAIN, playerA); - activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: {this} deals", "@lion"); - activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: {this} deals", "@lion"); + showAliases("before", 1, PhaseStep.PRECOMBAT_MAIN, playerA); + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "@goblin.1 {T}: {this} deals", "@lion"); + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "@goblin.3 {T}: {this} deals", "@lion"); setStopAt(1, PhaseStep.END_TURN); execute(); @@ -218,7 +220,11 @@ public class TestAliases extends CardTestPlayerBase { assertPermanentCount(playerA, "@goblin.1", 1); assertPermanentCount(playerA, "@goblin.2", 1); + assertPermanentCount(playerA, "@goblin.3", 1); assertGraveyardCount(playerA, "@lion", 1); + assertTapped("@goblin.1", true); + assertTapped("@goblin.2", false); + assertTapped("@goblin.3", true); } @Test diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index 39f9bac285..37a2dba762 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -3390,8 +3390,10 @@ public abstract class PlayerImpl implements Player, Serializable { getPlayableFromObjectSingle(game, fromZone, adventureCard, adventureCard.getSharedAbilities(game), availableMana, output); } else if (object instanceof Card) { getPlayableFromObjectSingle(game, fromZone, object, ((Card) object).getAbilities(game), availableMana, output); + } else if (object instanceof StackObject) { + // spells on stack are processing by Card above, other stack objects must be ignored } else { - // other things like StackObject or CommandObject + // other things like CommandObject getPlayableFromObjectSingle(game, fromZone, object, object.getAbilities(), availableMana, output); }