diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/MorphTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/MorphTest.java index 5215e5698c..a741e5c6d2 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/MorphTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/MorphTest.java @@ -116,7 +116,7 @@ public class MorphTest extends CardTestPlayerBase { /** * Test that the triggered "turned face up" ability of Pine Walker does not trigger - * aas long as Pine Walker is not turned face up. + * as long as Pine Walker is not turned face up. * */ @Test @@ -366,7 +366,7 @@ public class MorphTest extends CardTestPlayerBase { } /** - * Check that an effect like "arget creature and all other creatures with the same name" does + * Check that an effect like "Target creature and all other creatures with the same name" does * only effect one face down creature, also if multiple on the battlefield. Because they have no * name, they don't have the same name. * @@ -469,4 +469,41 @@ public class MorphTest extends CardTestPlayerBase { } } + /** + * Check that a DiesTriggeredAbility of a creature does not trigger + * if the creature dies face down + */ + + @Test + public void testDiesTriggeredDoesNotTriggerIfFaceDown() { + addCard(Zone.HAND, playerA, "Ashcloud Phoenix", 1); + addCard(Zone.BATTLEFIELD, playerA, "Forest", 3); + + addCard(Zone.HAND, playerB, "Lightning Bolt", 1); + addCard(Zone.BATTLEFIELD, playerB, "Mountain", 1); + + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Ashcloud Phoenix"); + setChoice(playerA, "Yes"); // cast it face down as 2/2 creature + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Lightning Bolt", "face down creature"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + assertGraveyardCount(playerB, "Lightning Bolt", 1); + assertGraveyardCount(playerA, "Ashcloud Phoenix", 1); + + + for (Card card: playerA.getGraveyard().getCards(currentGame)) { + if (card.getName().equals("Ashcloud Phoenix")) { + Assert.assertEquals("Ashcloud Phoenix has to be face up in graveyard", false, card.isFaceDown(currentGame)); + break; + } + } + + } } diff --git a/Mage/src/mage/abilities/AbilityImpl.java b/Mage/src/mage/abilities/AbilityImpl.java index 877064d671..ed9b1df7b5 100644 --- a/Mage/src/mage/abilities/AbilityImpl.java +++ b/Mage/src/mage/abilities/AbilityImpl.java @@ -895,14 +895,6 @@ public abstract class AbilityImpl implements Ability { return false; } } - // else if (object instanceof PermanentCard) { - // this check prevents Flying to work if assigned to a face down creature - // Why is this neccessary?? -// if (((PermanentCard)object).isFaceDown(game)&& !this.getWorksFaceDown()) { -// return false; -// } -// } - // check against current state Zone test = game.getState().getZone(parameterSourceId); return test != null && zone.match(test); diff --git a/Mage/src/mage/abilities/TriggeredAbilities.java b/Mage/src/mage/abilities/TriggeredAbilities.java index a306d31b48..705efd3737 100644 --- a/Mage/src/mage/abilities/TriggeredAbilities.java +++ b/Mage/src/mage/abilities/TriggeredAbilities.java @@ -70,7 +70,8 @@ public class TriggeredAbilities extends ConcurrentHashMap<String, TriggeredAbili continue; } // for effects like when leaves battlefield or destroyed use ShortLKI to check if permanent was in the correct zone before (e.g. Oblivion Ring or Karmic Justice) - if (ability.isInUseableZone(game, null, event.getType().equals(EventType.ZONE_CHANGE) || event.getType().equals(EventType.DESTROYED_PERMANENT))) { + if (ability.isInUseableZone(game, ability.getSourceObject(game), event.getType().equals(EventType.ZONE_CHANGE) || event.getType().equals(EventType.DESTROYED_PERMANENT))) { + if (!game.getContinuousEffects().preventedByRuleModification(event, ability, game, false)) { MageObject object = null; if (!ability.getZone().equals(Zone.COMMAND) && !game.getState().getZone(ability.getSourceId()).equals(ability.getZone())) { @@ -82,6 +83,9 @@ public class TriggeredAbilities extends ConcurrentHashMap<String, TriggeredAbili if (object != null) { if (object instanceof Permanent) { + if (((Permanent)object).isFaceDown(game) && !ability.getWorksFaceDown()) { + continue; + } ability.setControllerId(((Permanent) object).getControllerId()); } ability.setSourceObject(object); diff --git a/Mage/src/mage/abilities/common/DiesTriggeredAbility.java b/Mage/src/mage/abilities/common/DiesTriggeredAbility.java index 686cc12249..93baa64641 100644 --- a/Mage/src/mage/abilities/common/DiesTriggeredAbility.java +++ b/Mage/src/mage/abilities/common/DiesTriggeredAbility.java @@ -34,6 +34,7 @@ import mage.abilities.effects.Effect; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.events.ZoneChangeEvent; +import mage.game.permanent.Permanent; /** * @@ -56,7 +57,7 @@ public class DiesTriggeredAbility extends ZoneChangeTriggeredAbility { @Override public boolean isInUseableZone(Game game, MageObject source, boolean checkLKI) { // check it was previously on battlefield - MageObject before = game.getLastKnownInformation(sourceId, Zone.BATTLEFIELD); + Permanent before = (Permanent) game.getLastKnownInformation(sourceId, Zone.BATTLEFIELD); // check now it is in graveyard Zone after = game.getState().getZone(sourceId); return before != null && after != null && Zone.GRAVEYARD.match(after); diff --git a/Mage/src/mage/abilities/effects/common/continuous/BecomesFaceDownCreatureEffect.java b/Mage/src/mage/abilities/effects/common/continuous/BecomesFaceDownCreatureEffect.java index 161f0162ec..e81d02aaf5 100644 --- a/Mage/src/mage/abilities/effects/common/continuous/BecomesFaceDownCreatureEffect.java +++ b/Mage/src/mage/abilities/effects/common/continuous/BecomesFaceDownCreatureEffect.java @@ -158,7 +158,7 @@ public class BecomesFaceDownCreatureEffect extends ContinuousEffectImpl implemen break; case AbilityAddingRemovingEffects_6: Card card = game.getCard(permanent.getId()); // - List<Ability> abilities = new ArrayList<>(); + List<Ability> abilitiesToRemove = new ArrayList<>(); for (Ability ability : permanent.getAbilities()) { if (card != null && !card.getAbilities().contains(ability)) { // gained abilities from other sources won't be removed @@ -174,9 +174,9 @@ public class BecomesFaceDownCreatureEffect extends ContinuousEffectImpl implemen } } } - abilities.add(ability); + abilitiesToRemove.add(ability); } - permanent.getAbilities().removeAll(abilities); + permanent.getAbilities().removeAll(abilitiesToRemove); if (turnFaceUpAbility != null) { permanent.addAbility(turnFaceUpAbility, source.getSourceId(), game); }