From 77a526b6d920f65ccdfec46ffb324f00a4656aed Mon Sep 17 00:00:00 2001 From: Myrd Date: Tue, 27 Dec 2016 04:09:18 +0000 Subject: [PATCH] [Simulated AI] Fix copying tokens with abilities, like Eldrazi Scions. Also fixes a bug in the main game code where if you have Clone try to copy a token with abilities, like an Eldrazi Scion, it would previously not get those abilities. Adds a test for the game simulation/copy case. --- .../java/forge/ai/simulation/GameCopier.java | 5 ++- .../game/ability/effects/TokenEffect.java | 2 ++ .../ai/simulation/GameSimulatorTest.java | 36 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/forge-ai/src/main/java/forge/ai/simulation/GameCopier.java b/forge-ai/src/main/java/forge/ai/simulation/GameCopier.java index 376179124d9..aa0c900e079 100644 --- a/forge-ai/src/main/java/forge/ai/simulation/GameCopier.java +++ b/forge-ai/src/main/java/forge/ai/simulation/GameCopier.java @@ -197,7 +197,10 @@ public class GameCopier { private Card createCardCopy(Game newGame, Player newOwner, Card c) { if (c.isToken() && !c.isEmblem()) { String tokenStr = new CardFactory.TokenInfo(c).toString(); - return CardFactory.makeOneToken(CardFactory.TokenInfo.fromString(tokenStr), newOwner); + Card result = CardFactory.makeOneToken(CardFactory.TokenInfo.fromString(tokenStr), newOwner); + CardFactory.copyCopiableCharacteristics(c, result); + CardFactory.copyCopiableAbilities(c, result); + return result; } if (USE_FROM_PAPER_CARD && !c.isEmblem()) { return Card.fromPaperCard(c.getPaperCard(), newOwner); diff --git a/forge-game/src/main/java/forge/game/ability/effects/TokenEffect.java b/forge-game/src/main/java/forge/game/ability/effects/TokenEffect.java index e4d75cb56bb..841b5e5e2bc 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/TokenEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/TokenEffect.java @@ -291,6 +291,8 @@ public class TokenEffect extends SpellAbilityEffect { final String actualAbility = AbilityUtils.getSVar(root, s); for (final Card c : tokens) { final SpellAbility grantedAbility = AbilityFactory.getAbility(actualAbility, c); + // Set intrinsic, so that effects like Clone will copy these. + grantedAbility.setIntrinsic(true); c.addSpellAbility(grantedAbility); } } diff --git a/forge-gui-desktop/src/test/java/forge/ai/simulation/GameSimulatorTest.java b/forge-gui-desktop/src/test/java/forge/ai/simulation/GameSimulatorTest.java index 364e7c07741..76f5afa6c1d 100644 --- a/forge-gui-desktop/src/test/java/forge/ai/simulation/GameSimulatorTest.java +++ b/forge-gui-desktop/src/test/java/forge/ai/simulation/GameSimulatorTest.java @@ -623,4 +623,40 @@ public class GameSimulatorTest extends TestCase { assertEquals(1, berserker2.getNetToughness()); assertFalse(berserker2.isSick()); } + + public void testTokenAbilities() { + Game game = initAndCreateGame(); + Player p = game.getPlayers().get(1); + + addCard("Forest", p); + addCard("Forest", p); + addCard("Forest", p); + Card callTheScionsCard = addCardToZone("Call the Scions", p, ZoneType.Hand); + + game.getPhaseHandler().devModeSet(PhaseType.MAIN1, p); + + SpellAbility callTheScionsSA = callTheScionsCard.getSpellAbilities().get(0); + + GameSimulator sim = createSimulator(game, p); + int score = sim.simulateSpellAbility(callTheScionsSA).value; + assertTrue(score > 0); + Game simGame = sim.getSimulatedGameState(); + + Card scion = findCardWithName(simGame, "Eldrazi Scion"); + assertNotNull(scion); + assertEquals(1, scion.getNetPower()); + assertEquals(1, scion.getNetToughness()); + assertTrue(scion.isSick()); + assertNotNull(findSAWithPrefix(scion, "Sacrifice CARDNAME: Add {C} to your mana pool.")); + + GameCopier copier = new GameCopier(simGame); + Game copy = copier.makeCopy(); + Card scionCopy = findCardWithName(copy, "Eldrazi Scion"); + assertNotNull(scionCopy); + assertEquals(1, scionCopy.getNetPower()); + assertEquals(1, scionCopy.getNetToughness()); + assertTrue(scionCopy.isSick()); + System.err.println("Search continues on: " + scionCopy); + assertNotNull(findSAWithPrefix(scionCopy, "Sacrifice CARDNAME: Add {C} to your mana pool.")); + } }