From 7a44ee2a979514121b75633922137c9a4d522f4d Mon Sep 17 00:00:00 2001 From: xenohedron <12538125+xenohedron@users.noreply.github.com> Date: Sat, 14 Jun 2025 21:16:56 -0400 Subject: [PATCH] fix #12974 (zcc check in ReturnToBattlefieldUnderOwnerControlAttachedEffect) add test --- .../ReturnToBattlefieldEffectsTest.java | 58 +++++++++++++++++++ ...efieldUnderOwnerControlAttachedEffect.java | 14 ++--- 2 files changed, 64 insertions(+), 8 deletions(-) diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/triggers/ReturnToBattlefieldEffectsTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/triggers/ReturnToBattlefieldEffectsTest.java index ba897e5a889..f0b2d87c89f 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/triggers/ReturnToBattlefieldEffectsTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/triggers/ReturnToBattlefieldEffectsTest.java @@ -157,4 +157,62 @@ public class ReturnToBattlefieldEffectsTest extends CardTestPlayerBase { assertPermanentCount(playerB, "Reassembling Skeleton", 1); } + + // issue #12974 + private static final String rOrb = "Resurrection Orb"; + // Whenever equipped creature dies, return that card to the battlefield under its owner's control at the beginning of the next end step. + private static final String lMiss = "Lone Missionary"; // ETB gain 4 + private static final String cFeeder = "Carrion Feeder"; // sacrifice a creature: +1/+1 counter + + @Test + public void testReturnAttachedToBattlefield() { + addCard(Zone.BATTLEFIELD, playerA, rOrb); + addCard(Zone.BATTLEFIELD, playerA, lMiss); + addCard(Zone.BATTLEFIELD, playerA, cFeeder); + addCard(Zone.BATTLEFIELD, playerA, "Wastes", 4); + + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Equip", lMiss); + waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN); + + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Sacrifice"); + setChoice(playerA, lMiss); + + setStrictChooseMode(true); + setStopAt(2, PhaseStep.UPKEEP); + execute(); + + assertLife(playerA, 24); + assertPermanentCount(playerA, lMiss, 1); + assertPowerToughness(playerA, cFeeder, 2, 2); + + } + + @Test + public void testNotReturnAttachedToBattlefieldAfterZoneChange() { + addCard(Zone.BATTLEFIELD, playerA, rOrb); + addCard(Zone.BATTLEFIELD, playerA, lMiss); + addCard(Zone.BATTLEFIELD, playerA, cFeeder); + addCard(Zone.BATTLEFIELD, playerA, "Wastes", 4); + addCard(Zone.BATTLEFIELD, playerB, "Crypt Creeper"); + + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Equip", lMiss); + waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN); + + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Sacrifice"); + setChoice(playerA, lMiss); + + activateAbility(1, PhaseStep.POSTCOMBAT_MAIN, playerB, "Sacrifice"); + addTarget(playerB, lMiss); + + setStrictChooseMode(true); + setStopAt(2, PhaseStep.UPKEEP); + execute(); + + assertLife(playerA, 20); + assertExileCount(playerA, lMiss, 1); + assertPowerToughness(playerA, cFeeder, 2, 2); + assertGraveyardCount(playerB, "Crypt Creeper", 1); + + } + } diff --git a/Mage/src/main/java/mage/abilities/effects/common/ReturnToBattlefieldUnderOwnerControlAttachedEffect.java b/Mage/src/main/java/mage/abilities/effects/common/ReturnToBattlefieldUnderOwnerControlAttachedEffect.java index 163470b756d..15767c750a0 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/ReturnToBattlefieldUnderOwnerControlAttachedEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/ReturnToBattlefieldUnderOwnerControlAttachedEffect.java @@ -45,16 +45,14 @@ public class ReturnToBattlefieldUnderOwnerControlAttachedEffect extends OneShotE if (controller == null) { return false; } - Object object = getValue("attachedTo"); - if (object instanceof Permanent) { - Card card = game.getCard(((Permanent) object).getId()); - if (card != null) { - if (controller.moveCards(card, Zone.BATTLEFIELD, source, game, this.tapped, false, true, null)) { - return true; - } + Object attached = getValue("attachedTo"); + Object zcc = getValue("zcc"); + if (attached instanceof Permanent && zcc instanceof Integer) { + Card card = game.getCard(((Permanent) attached).getId()); + if (card != null && (int) zcc == card.getZoneChangeCounter(game)) { + return controller.moveCards(card, Zone.BATTLEFIELD, source, game, this.tapped, false, true, null); } } - return false; } }