diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/UndyingTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/UndyingTest.java index b62a2598f59..3f827caec13 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/UndyingTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/UndyingTest.java @@ -146,5 +146,39 @@ public class UndyingTest extends CardTestPlayerBase { assertExileCount("Butcher Ghoul", 1); } - + /** + * Tests "Target creature with Undying will be exiled by Anafenza before it returns to battlefield + * if both leave the battlefield at the same time + * + * Anafenza the foremost doesn't exile an undying creature when dying at the same time as + * that undying one. The undying comes back to the field when he shouldn't. + */ + @Test + public void testReplacementEffectPreventsReturnOfUndyingWrath() { + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2); + // Butcher Ghoul + // Creature - Zombie, 1/1 {1}{B} + // Undying (When this creature dies, if it had no +1/+1 counters on it, return it to the battlefield under its owner's control with a +1/+1 counter on it.) + addCard(Zone.HAND, playerA, "Butcher Ghoul"); + + addCard(Zone.BATTLEFIELD, playerB, "Plains", 4); + // Destroy all creatures. They can't be regenerated. + addCard(Zone.HAND, playerB, "Wrath of God"); + // Anafenza, the Foremost + // Whenever Anafenza, the Foremost attacks, put a +1/+1 counter on another target tapped creature you control. + // If a creature card would be put into an opponent's graveyard from anywhere, exile it instead. + addCard(Zone.BATTLEFIELD, playerB, "Anafenza, the Foremost"); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Butcher Ghoul"); + castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Wrath of God"); + + setStopAt(2, PhaseStep.BEGIN_COMBAT); + execute(); + + assertGraveyardCount(playerB, "Anafenza, the Foremost", 1); + assertGraveyardCount(playerB, "Wrath of God", 1); + + assertPermanentCount(playerA, "Butcher Ghoul", 0); + assertExileCount("Butcher Ghoul", 1); + } } diff --git a/Mage/src/mage/abilities/effects/ContinuousEffects.java b/Mage/src/mage/abilities/effects/ContinuousEffects.java index 2bbc85cf77b..2f0de6e876f 100644 --- a/Mage/src/mage/abilities/effects/ContinuousEffects.java +++ b/Mage/src/mage/abilities/effects/ContinuousEffects.java @@ -331,6 +331,7 @@ public class ContinuousEffects implements Serializable { if(auraReplacementEffect.checksEventType(event, game) && auraReplacementEffect.applies(event, null, game)){ replaceEffects.put(auraReplacementEffect, null); } + boolean checkLKI = event.getType().equals(EventType.ZONE_CHANGE) || event.getType().equals(EventType.DESTROYED_PERMANENT); //get all applicable transient Replacement effects for (ReplacementEffect effect: replacementEffects) { if (!effect.checksEventType(event, game)) { @@ -344,7 +345,7 @@ public class ContinuousEffects implements Serializable { HashSet abilities = replacementEffects.getAbility(effect.getId()); HashSet applicableAbilities = new HashSet<>(); for (Ability ability : abilities) { - if (!(ability instanceof StaticAbility) || ability.isInUseableZone(game, null, false)) { + if (!(ability instanceof StaticAbility) || ability.isInUseableZone(game, null, checkLKI)) { if (effect.getDuration() != Duration.OneUse || !effect.isUsed()) { if (!game.getScopeRelevant() || effect.hasSelfScope() || !event.getTargetId().equals(ability.getSourceId())) { if (checkAbilityStillExists(ability, effect, event, game)) { diff --git a/Mage/src/mage/abilities/keyword/UndyingAbility.java b/Mage/src/mage/abilities/keyword/UndyingAbility.java index f77fbd18708..be16dd65a6f 100644 --- a/Mage/src/mage/abilities/keyword/UndyingAbility.java +++ b/Mage/src/mage/abilities/keyword/UndyingAbility.java @@ -40,7 +40,6 @@ public class UndyingAbility extends DiesTriggeredAbility { if (super.checkTrigger(event, game)) { Permanent permanent = (Permanent) game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD); if (!permanent.getCounters().containsKey(CounterType.P1P1) || permanent.getCounters().getCount(CounterType.P1P1) == 0) { - Logger.getLogger(UndyingAbility.class).info("Undying trigger: " + getSourceId()); game.getState().setValue("undying" + getSourceId(),permanent.getId()); return true; } @@ -115,8 +114,6 @@ class UndyingReplacementEffect extends ReplacementEffectImpl { if (event.getTargetId().equals(source.getSourceId())) { // Check if undying condition is true UUID targetId = (UUID) game.getState().getValue("undying" + source.getSourceId()); - Logger.getLogger(UndyingReplacementEffect.class).info("Undying replacement applies: " + targetId + " eventSourceId " + event.getTargetId()); - if (targetId != null && targetId.equals(source.getSourceId())) { return true; }