From b279d4b3188fa1a678405595278c68a5544c3694 Mon Sep 17 00:00:00 2001 From: Jeff Wadsworth Date: Fri, 6 May 2022 10:23:10 -0500 Subject: [PATCH] - Fixed #8839 and added test for it. --- Mage.Sets/src/mage/cards/s/StrictProctor.java | 22 +++++-- .../cards/triggers/StrictProctorTest.java | 64 +++++++++++++++++++ .../mage/abilities/TriggeredAbilities.java | 3 + 3 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/triggers/StrictProctorTest.java diff --git a/Mage.Sets/src/mage/cards/s/StrictProctor.java b/Mage.Sets/src/mage/cards/s/StrictProctor.java index b6b6034074..e94df1af1f 100644 --- a/Mage.Sets/src/mage/cards/s/StrictProctor.java +++ b/Mage.Sets/src/mage/cards/s/StrictProctor.java @@ -15,6 +15,7 @@ import mage.game.events.GameEvent; import mage.target.targetpointer.FixedTarget; import java.util.UUID; +import mage.game.stack.StackAbility; /** * @author TheElk801 @@ -58,16 +59,25 @@ class StrictProctorTriggeredAbility extends TriggeredAbilityImpl { @Override public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.ABILITY_TRIGGERED; + return event.getType() == GameEvent.EventType.TRIGGERED_ABILITY; } @Override public boolean checkTrigger(GameEvent event, Game game) { - GameEvent triggeringEvent = (GameEvent) game.getState().getValue(event.getId().toString()); - if (triggeringEvent == null || triggeringEvent.getType() != GameEvent.EventType.ENTERS_THE_BATTLEFIELD) { + // retrieve the event that led to the trigger triggering + // verify that it is a ETB event + StackAbility stackAbilityOfTriggeredAbility = (StackAbility) game.getObject(event.getTargetId()); + if (stackAbilityOfTriggeredAbility == null + || stackAbilityOfTriggeredAbility.getSourceId() == null) { return false; } - getEffects().setTargetPointer(new FixedTarget(triggeringEvent.getTargetId(), game)); + GameEvent triggeringEvent = (GameEvent) game.getState().getValue("triggeringEvent" + stackAbilityOfTriggeredAbility.getSourceId()); + if (triggeringEvent == null + || triggeringEvent.getType() != GameEvent.EventType.ENTERS_THE_BATTLEFIELD) { + return false; + } + // set the target to the ability that gets triggered from the enter the battlefield trigger + getEffects().setTargetPointer(new FixedTarget(event.getTargetId(), game)); return true; } @@ -78,7 +88,7 @@ class StrictProctorTriggeredAbility extends TriggeredAbilityImpl { @Override public String getRule() { - return "Whenever a permanent entering the battlefield causes a triggered ability to trigger, " + - "counter that ability unless its controller pays {2}."; + return "Whenever a permanent entering the battlefield causes a triggered ability to trigger, " + + "counter that ability unless its controller pays {2}."; } } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/triggers/StrictProctorTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/triggers/StrictProctorTest.java new file mode 100644 index 0000000000..1dede1407c --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/triggers/StrictProctorTest.java @@ -0,0 +1,64 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.mage.test.cards.triggers; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author jeffwadsworth + */ +public class StrictProctorTest extends CardTestPlayerBase { + + @Test + public void testStrictProctorPaid() { + setStrictChooseMode(true); + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2); + // Whenever a permanent entering the battlefield causes a triggered ability to + // trigger, counter that ability unless its controller pays {2}. + addCard(Zone.BATTLEFIELD, playerA, "Strict Proctor", 1); + // Whenever a land enters the battlefield under your control, you gain 3 life. + addCard(Zone.BATTLEFIELD, playerA, "Primeval Bounty", 1); + // land to play for trigger + addCard(Zone.HAND, playerA, "Swamp", 1); + + playLand(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Swamp"); // play land + setChoice(playerA, "Yes"); // pay the {2} mana cost to prevent the countering of the trigger + + setStopAt(1, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + + assertLife(playerA, 23); // player gains the 3 life + + } + + @Test + public void testStrictProctorNotPaid() { + setStrictChooseMode(true); + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2); + // Whenever a permanent entering the battlefield causes a triggered ability to + // trigger, counter that ability unless its controller pays {2}. + addCard(Zone.BATTLEFIELD, playerA, "Strict Proctor", 1); + // Whenever a land enters the battlefield under your control, you gain 3 life. + addCard(Zone.BATTLEFIELD, playerA, "Primeval Bounty", 1); + // land to play for trigger + addCard(Zone.HAND, playerA, "Swamp", 1); + + playLand(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Swamp"); // play land + setChoice(playerA, "No"); // do not pay the {2} mana cost to prevent the countering of the trigger + + setStopAt(1, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + + assertLife(playerA, 20); // player does not gain the 3 life + + } +} diff --git a/Mage/src/main/java/mage/abilities/TriggeredAbilities.java b/Mage/src/main/java/mage/abilities/TriggeredAbilities.java index 199da56edc..aa6f89bb1d 100644 --- a/Mage/src/main/java/mage/abilities/TriggeredAbilities.java +++ b/Mage/src/main/java/mage/abilities/TriggeredAbilities.java @@ -93,6 +93,9 @@ public class TriggeredAbilities extends ConcurrentHashMap