|
| 1 | +package forge.game.ability.effects; |
| 2 | + |
| 3 | +import org.testng.annotations.Test; |
| 4 | + |
| 5 | +import forge.ai.AITest; |
| 6 | +import forge.game.Game; |
| 7 | +import forge.game.card.Card; |
| 8 | +import forge.game.phase.PhaseType; |
| 9 | +import forge.game.player.Player; |
| 10 | +import forge.game.spellability.SpellAbility; |
| 11 | +import forge.game.zone.ZoneType; |
| 12 | + |
| 13 | +import static junit.framework.Assert.assertEquals; |
| 14 | + |
| 15 | +/** |
| 16 | + * Opposition Agent applies only while an opponent searches <i>their own</i> library, so searching |
| 17 | + * someone else's must not hand the cards found to the Agent's controller. |
| 18 | + */ |
| 19 | +public class SearchOwnLibraryTest extends AITest { |
| 20 | + |
| 21 | + @Test |
| 22 | + public void agentIgnoresSearchesOfOtherPlayersLibraries() { |
| 23 | + Game game = initAndCreateGame(); |
| 24 | + Player me = game.getPlayers().get(0); |
| 25 | + Player opp = game.getPlayers().get(1); |
| 26 | + addCard("Opposition Agent", me); |
| 27 | + |
| 28 | + assertEquals("my own Acquire must still fetch for me", ZoneType.Battlefield, |
| 29 | + acquireFrom(game, me, opp).getZone().getZoneType()); |
| 30 | + |
| 31 | + // and the case the card is for: the opponent tutoring out of their own library |
| 32 | + Game other = initAndCreateGame(); |
| 33 | + Player agentOwner = other.getPlayers().get(0); |
| 34 | + Player tutorer = other.getPlayers().get(1); |
| 35 | + addCard("Opposition Agent", agentOwner); |
| 36 | + assertEquals("their own tutor is still exiled by the Agent", ZoneType.Exile, |
| 37 | + tutorFrom(other, tutorer).getZone().getZoneType()); |
| 38 | + } |
| 39 | + |
| 40 | + /** Resolves Acquire cast by {@code me} at {@code opp}'s library, returning the Sol Ring. */ |
| 41 | + private Card acquireFrom(Game game, Player me, Player opp) { |
| 42 | + Card solRing = stockLibrary(game, opp); |
| 43 | + addCards("Island", 6, me); |
| 44 | + SpellAbility sa = cast(game, addCardToZone("Acquire", me, ZoneType.Hand), me); |
| 45 | + sa.getTargets().add(opp); |
| 46 | + sa.resolve(); |
| 47 | + game.getAction().checkStateEffects(true); |
| 48 | + return game.getCardState(solRing, solRing); |
| 49 | + } |
| 50 | + |
| 51 | + /** Resolves Diabolic Tutor cast by {@code tutorer} on their own library. */ |
| 52 | + private Card tutorFrom(Game game, Player tutorer) { |
| 53 | + Card solRing = stockLibrary(game, tutorer); |
| 54 | + addCards("Swamp", 6, tutorer); |
| 55 | + cast(game, addCardToZone("Diabolic Tutor", tutorer, ZoneType.Hand), tutorer).resolve(); |
| 56 | + game.getAction().checkStateEffects(true); |
| 57 | + return game.getCardState(solRing, solRing); |
| 58 | + } |
| 59 | + |
| 60 | + private Card stockLibrary(Game game, Player p) { |
| 61 | + Card solRing = addCardToZone("Sol Ring", p, ZoneType.Library); |
| 62 | + for (int i = 0; i < 5; i++) { |
| 63 | + addCardToZone("Forest", p, ZoneType.Library); |
| 64 | + } |
| 65 | + return solRing; |
| 66 | + } |
| 67 | + |
| 68 | + private SpellAbility cast(Game game, Card c, Player p) { |
| 69 | + game.getPhaseHandler().devModeSet(PhaseType.MAIN1, p); |
| 70 | + game.getAction().checkStateEffects(true); |
| 71 | + SpellAbility sa = c.getFirstSpellAbility(); |
| 72 | + sa.setActivatingPlayer(p); |
| 73 | + sa.resetTargets(); |
| 74 | + return sa; |
| 75 | + } |
| 76 | +} |
0 commit comments