diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/triggers/KarmicJusticeTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/triggers/KarmicJusticeTest.java index 3c02c2b763c..00e99b61d9f 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/triggers/KarmicJusticeTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/triggers/KarmicJusticeTest.java @@ -39,8 +39,14 @@ import org.mage.test.serverside.base.CardTestPlayerBase; public class KarmicJusticeTest extends CardTestPlayerBase { + /* + Karmic Justice + Whenever a spell or ability an opponent controls destroys a noncreature permanent you control, + you may destroy target permanent that opponent controls. + */ + /** - * Karmic Justice triggers for its own destroyment + * Karmic Justice should triggers for its own destroyment */ @Test public void testFirstTriggeredAbility() { @@ -62,4 +68,41 @@ public class KarmicJusticeTest extends CardTestPlayerBase { } + /** + * Karmic Justice should triggers for each destroyed permanent + */ + @Test + public void testMultiplePermanentsDestroyedTriggeredAbility() { + // At the beginning of each upkeep, if you lost life last turn, put a 1/1 white Soldier creature token onto the battlefield. + addCard(Zone.BATTLEFIELD, playerA, "First Response",2); + addCard(Zone.BATTLEFIELD, playerA, "Karmic Justice"); + + // Planar Cleansing {3}{W}{W}{W} + // Sorcery + // Destroy all nonland permanents. + addCard(Zone.HAND, playerB, "Planar Cleansing"); + addCard(Zone.BATTLEFIELD, playerB, "Plains", 4); + addCard(Zone.BATTLEFIELD, playerB, "Mountain", 1); + addCard(Zone.BATTLEFIELD, playerB, "Swamp", 1); + + castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Planar Cleansing"); + setChoice(playerA, "Yes"); + addTarget(playerA, "Plains"); + setChoice(playerA, "Yes"); + addTarget(playerA, "Swamp"); + setChoice(playerA, "Yes"); + addTarget(playerA, "Mountain"); + + setStopAt(2, PhaseStep.BEGIN_COMBAT); + execute(); + + assertGraveyardCount(playerB, "Planar Cleansing", 1); + assertGraveyardCount(playerA, "Karmic Justice", 1); + assertGraveyardCount(playerA, "First Response", 2); + assertGraveyardCount(playerB, "Mountain", 1); + assertGraveyardCount(playerB, "Swamp", 1); + assertGraveyardCount(playerB, "Plains", 1); + + } + } diff --git a/Mage/src/mage/abilities/TriggeredAbilities.java b/Mage/src/mage/abilities/TriggeredAbilities.java index 9782876ddaa..3d0f8e146d1 100644 --- a/Mage/src/mage/abilities/TriggeredAbilities.java +++ b/Mage/src/mage/abilities/TriggeredAbilities.java @@ -37,6 +37,7 @@ import mage.game.permanent.Permanent; import mage.game.permanent.PermanentCard; import java.util.*; +import mage.game.events.GameEvent.EventType; /** @@ -61,8 +62,8 @@ public class TriggeredAbilities extends HashMap { public void checkTriggers(GameEvent event, Game game) { for (Iterator it = this.values().iterator(); it.hasNext();) { TriggeredAbility ability = it.next(); - // for effects like when leaves battlefield use ShortLKI to check if permanent was in the correct zone before (e.g. Oblivion Ring) - if (ability.isInUseableZone(game, null, event.getType().equals(GameEvent.EventType.ZONE_CHANGE))) { + // 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 (!game.getContinuousEffects().preventedByRuleModification(event, ability, game, false)) { MageObject object = null; @@ -89,7 +90,7 @@ public class TriggeredAbilities extends HashMap { } } } - + private boolean checkAbilityStillExists(TriggeredAbility ability, GameEvent event, MageObject object) { boolean exists = true; if (!object.getAbilities().contains(ability)) {