From 87d8383eb884d93f04d90b96d88e6b6080511e5f Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Sat, 29 Aug 2020 20:40:02 +0400 Subject: [PATCH] * Undercity Reaches - fixed rollback error on plane's draw trigger --- .../cards/planes/UndercityReachesTest.java | 53 +++++++++++++++++++ .../command/planes/UndercityReachesPlane.java | 8 +-- 2 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/planes/UndercityReachesTest.java diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/planes/UndercityReachesTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/planes/UndercityReachesTest.java new file mode 100644 index 0000000000..e1dad1ed05 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/planes/UndercityReachesTest.java @@ -0,0 +1,53 @@ +package org.mage.test.cards.planes; + +import mage.constants.PhaseStep; +import mage.constants.Planes; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * @author JayDi85 + */ +public class UndercityReachesTest extends CardTestPlayerBase { + + @Test + public void test_CanTriggerByController() { + removeAllCardsFromHand(playerA); + + // Whenever a creature deals combat damage to a player, its controller may a draw a card + addPlane(playerA, Planes.PLANE_UNDERCITY_REACHES); + addCard(Zone.BATTLEFIELD, playerA, "Balduvian Bears", 1); + + attack(1, playerA, "Balduvian Bears"); + setChoice(playerA, "Yes"); // draw + + setStrictChooseMode(true); + setStopAt(1, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + + assertLife(playerB, 20 - 2); + assertHandCount(playerA, 1); + } + + @Test + public void test_CanTriggerByOther() { + removeAllCardsFromHand(playerB); + + // Whenever a creature deals combat damage to a player, its controller may a draw a card + addPlane(playerA, Planes.PLANE_UNDERCITY_REACHES); + addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 1); + + attack(2, playerB, "Balduvian Bears"); + setChoice(playerB, "Yes"); // draw + + setStrictChooseMode(true); + setStopAt(2, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + + assertLife(playerA, 20 - 2); + assertHandCount(playerB, 1 + 1); // +1 from turn draw, +1 from trigger + } +} diff --git a/Mage/src/main/java/mage/game/command/planes/UndercityReachesPlane.java b/Mage/src/main/java/mage/game/command/planes/UndercityReachesPlane.java index 8c0eb0de09..c93b9b9952 100644 --- a/Mage/src/main/java/mage/game/command/planes/UndercityReachesPlane.java +++ b/Mage/src/main/java/mage/game/command/planes/UndercityReachesPlane.java @@ -43,7 +43,7 @@ public class UndercityReachesPlane extends Plane { this.setPlaneType(Planes.PLANE_UNDERCITY_REACHES); this.setExpansionSetCodeForImage("PCA"); - // Whenever a creature deals combat damage to a player, its controller may a draw a card + // Whenever a creature deals combat damage to a player, its controller may draw a card. Ability ability = new UndercityReachesTriggeredAbility(); this.getAbilities().add(ability); @@ -68,7 +68,7 @@ public class UndercityReachesPlane extends Plane { class UndercityReachesTriggeredAbility extends TriggeredAbilityImpl { public UndercityReachesTriggeredAbility() { - super(Zone.COMMAND, null, true); + super(Zone.COMMAND, null, false); // effect must be optional } public UndercityReachesTriggeredAbility(final UndercityReachesTriggeredAbility ability) { @@ -98,9 +98,9 @@ class UndercityReachesTriggeredAbility extends TriggeredAbilityImpl { if (((DamagedPlayerEvent) event).isCombatDamage()) { Permanent creature = game.getPermanent(event.getSourceId()); if (creature != null) { - Effect effect = new DrawCardTargetEffect(StaticValue.get(1), false, true); + Effect effect = new DrawCardTargetEffect(StaticValue.get(1), true, false); effect.setTargetPointer(new FixedTarget(creature.getControllerId())); - effect.apply(game, null); + effect.apply(game, this); return true; } }