From 397a6ccfc42838be8f5cd25042df989993e4bc2d Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sun, 3 Jun 2018 23:51:09 +0200 Subject: [PATCH] * Grafted Exoskeleton - Fixed that if it left the battlefield it doesn't sacrifice its creature (fixes #4997). --- .../triggers/events/UnequipEventTest.java | 97 +++++++++++++++++++ .../common/SacrificeEquippedEffect.java | 9 +- 2 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/triggers/events/UnequipEventTest.java diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/triggers/events/UnequipEventTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/triggers/events/UnequipEventTest.java new file mode 100644 index 00000000000..e05df894f09 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/triggers/events/UnequipEventTest.java @@ -0,0 +1,97 @@ +package org.mage.test.cards.triggers.events; + +import mage.abilities.keyword.IndestructibleAbility; +import mage.abilities.keyword.InfectAbility; +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author LevelX2 + */ +public class UnequipEventTest extends CardTestPlayerBase { + + @Test + public void testGraftedExoskeletonEvent() { + // When Nazahn, Revered Bladesmith enters the battlefield, search your library for an Equipment card and reveal it. If you reveal a card named Hammer of Nazahn this way, put it onto the battlefield. Otherwise, put that card into your hand. Then shuffle your library. + // Whenever an equipped creature you control attacks, you may tap target creature defending player controls. + addCard(Zone.HAND, playerA, "Nazahn, Revered Bladesmith"); // Creature 5/4 {4}{G}{W} + // Whenever Hammer of Nazahn or another Equipment enters the battlefiend under your control, you may attach that Equipment to target creature you control. + // Equipped creature gets +2/+0 and has indestructible. + // Equip {4} + addCard(Zone.LIBRARY, playerA, "Hammer of Nazahn"); + addCard(Zone.BATTLEFIELD, playerA, "Forest", 5); + addCard(Zone.BATTLEFIELD, playerA, "Plains", 1); + + // Equipped creature gets +2/+2 and has infect. + // Whenever Grafted Exoskeleton becomes unattached from a permanent, sacrifice that permanent. + // Equip {2} + addCard(Zone.BATTLEFIELD, playerA, "Grafted Exoskeleton", 1); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Nazahn, Revered Bladesmith"); + setChoice(playerA, "Hammer of Nazahn"); + + activateAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Equip {2}"); + + setStopAt(3, PhaseStep.BEGIN_COMBAT); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + assertPermanentCount(playerA, "Nazahn, Revered Bladesmith", 1); + assertPowerToughness(playerA, "Nazahn, Revered Bladesmith", 9, 6); + assertAbility(playerA, "Nazahn, Revered Bladesmith", IndestructibleAbility.getInstance(), true); + assertAbility(playerA, "Nazahn, Revered Bladesmith", InfectAbility.getInstance(), true); + + assertPermanentCount(playerA, "Hammer of Nazahn", 1); + } + + /** + * I cast Beast Within on a Grafted Exoskeleton (equipped on a Nazahn with + * also a Bloodforged Battle-Axe and Hammer of Nazahn), it got destroyed, + * but Nazahn didn't get sacrificed. Perhaps of note is the fact that it got + * equipped via Hammer of Nazahn's ability. Also I remember this interaction + * working correctly in the past, so a recent-ish update must've broken it. + */ + @Test + public void testGraftedExoskeletonAndBeastWithinEvent() { + // When Nazahn, Revered Bladesmith enters the battlefield, search your library for an Equipment card and reveal it. If you reveal a card named Hammer of Nazahn this way, put it onto the battlefield. Otherwise, put that card into your hand. Then shuffle your library. + // Whenever an equipped creature you control attacks, you may tap target creature defending player controls. + addCard(Zone.HAND, playerA, "Nazahn, Revered Bladesmith"); // Creature 5/4 {4}{G}{W} + // Whenever Hammer of Nazahn or another Equipment enters the battlefiend under your control, you may attach that Equipment to target creature you control. + // Equipped creature gets +2/+0 and has indestructible. + // Equip {4} + addCard(Zone.LIBRARY, playerA, "Hammer of Nazahn"); + addCard(Zone.BATTLEFIELD, playerA, "Forest", 5); + addCard(Zone.BATTLEFIELD, playerA, "Plains", 1); + + // Destroy target permanent. Its controller creates a 3/3 green Beast creature token. + addCard(Zone.HAND, playerA, "Beast Within"); // Instant {2}{G} + // Equipped creature gets +2/+2 and has infect. + // Whenever Grafted Exoskeleton becomes unattached from a permanent, sacrifice that permanent. + // Equip {2} + addCard(Zone.BATTLEFIELD, playerA, "Grafted Exoskeleton", 1); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Nazahn, Revered Bladesmith"); + setChoice(playerA, "Hammer of Nazahn"); + + activateAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Equip {2}"); + castSpell(3, PhaseStep.BEGIN_COMBAT, playerA, "Beast Within", "Grafted Exoskeleton"); + + setStopAt(3, PhaseStep.END_COMBAT); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + assertPermanentCount(playerA, "Hammer of Nazahn", 1); + assertGraveyardCount(playerA, "Beast Within", 1); + assertPowerToughness(playerA, "Beast", 3, 3); + assertGraveyardCount(playerA, "Grafted Exoskeleton", 1); + assertGraveyardCount(playerA, "Nazahn, Revered Bladesmith", 1); + + } +} diff --git a/Mage/src/main/java/mage/abilities/effects/common/SacrificeEquippedEffect.java b/Mage/src/main/java/mage/abilities/effects/common/SacrificeEquippedEffect.java index 59b6817b1e9..a020e71d751 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/SacrificeEquippedEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/SacrificeEquippedEffect.java @@ -1,15 +1,12 @@ - - package mage.abilities.effects.common; -import mage.constants.Outcome; +import java.util.UUID; import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; +import mage.constants.Outcome; import mage.game.Game; import mage.game.permanent.Permanent; -import java.util.UUID; - /** * * @author nantuko @@ -32,7 +29,7 @@ public class SacrificeEquippedEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Permanent equipment = game.getPermanent(source.getSourceId()); + Permanent equipment = game.getPermanentOrLKIBattlefield(source.getSourceId()); if (equipment != null && equipment.getAttachedTo() != null) { UUID uuid = getTargetPointer().getFirst(game, source); Permanent permanent = game.getPermanent(uuid);