From f1d2d2fb228b768f086c3de4c6b61a35a4e41036 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 25 Aug 2020 16:30:48 +0200 Subject: [PATCH] * Safe Passage - Fixed a problem that damage to player was not prevented (fixes #6995). --- Mage.Sets/src/mage/cards/s/SafePassage.java | 1 + .../prevention/PreventAllDamageTest.java | 98 +++++++++++++++++++ .../common/PreventAllDamageToAllEffect.java | 12 ++- 3 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/prevention/PreventAllDamageTest.java diff --git a/Mage.Sets/src/mage/cards/s/SafePassage.java b/Mage.Sets/src/mage/cards/s/SafePassage.java index 500efab8dd..f84d4a3ec5 100644 --- a/Mage.Sets/src/mage/cards/s/SafePassage.java +++ b/Mage.Sets/src/mage/cards/s/SafePassage.java @@ -22,6 +22,7 @@ public final class SafePassage extends CardImpl { public SafePassage(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{2}{W}"); + // Prevent all damage that would be dealt to you and creatures you control this turn. this.getSpellAbility().addEffect(new PreventAllDamageToAllEffect(Duration.EndOfTurn, filter)); } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/prevention/PreventAllDamageTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/prevention/PreventAllDamageTest.java new file mode 100644 index 0000000000..bb671ccaba --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/prevention/PreventAllDamageTest.java @@ -0,0 +1,98 @@ + +package org.mage.test.cards.prevention; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author LevelX2 + */ +public class PreventAllDamageTest extends CardTestPlayerBase { + + @Test + public void test_SafePassage() { + setStrictChooseMode(true); + + addCard(Zone.BATTLEFIELD, playerA, "Plains", 3); + // Prevent all damage that would be dealt to you and creatures you control this turn. + addCard(Zone.HAND, playerA, "Safe Passage"); // Instant {2}{W} + + addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 1); // (2/2) + + + addCard(Zone.BATTLEFIELD, playerB, "Pillarfield Ox", 2); // (2/4) + addCard(Zone.BATTLEFIELD, playerB, "Mountain", 2); + + addCard(Zone.HAND, playerB, "Lightning Bolt",2); // Instnat {R} + + castSpell(2, PhaseStep.UPKEEP, playerA, "Safe Passage"); + + castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Lightning Bolt", playerA); + castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Lightning Bolt", "Silvercoat Lion"); + + attack(2, playerB, "Pillarfield Ox"); + attack(2, playerB, "Pillarfield Ox"); + + block(2, playerA, "Silvercoat Lion", "Pillarfield Ox"); + + setStopAt(2, PhaseStep.POSTCOMBAT_MAIN); + execute(); + + assertAllCommandsUsed(); + + assertGraveyardCount(playerA, "Safe Passage", 1); + assertPermanentCount(playerA, "Silvercoat Lion", 1); + + assertGraveyardCount(playerB, "Lightning Bolt", 2); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + + } + + @Test + public void test_EtherealHaze() { + setStrictChooseMode(true); + + addCard(Zone.BATTLEFIELD, playerA, "Plains", 1); + // Prevent all damage that would be dealt by creatures this turn. + addCard(Zone.HAND, playerA, "Ethereal Haze"); // Instant {W} + + addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 1); // (2/2) + + + addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 2); // (2/4) + addCard(Zone.BATTLEFIELD, playerB, "Mountain", 2); + + addCard(Zone.HAND, playerB, "Lightning Bolt",1); // Instant {R} + + castSpell(2, PhaseStep.UPKEEP, playerA, "Ethereal Haze"); + + castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Lightning Bolt", playerA); + + attack(2, playerB, "Silvercoat Lion"); + attack(2, playerB, "Silvercoat Lion"); + + block(2, playerA, "Silvercoat Lion", "Silvercoat Lion"); + + setStopAt(2, PhaseStep.POSTCOMBAT_MAIN); + execute(); + + assertAllCommandsUsed(); + + assertGraveyardCount(playerA, "Ethereal Haze", 1); + assertPermanentCount(playerA, "Silvercoat Lion", 1); + + assertPermanentCount(playerB, "Silvercoat Lion", 2); + assertGraveyardCount(playerB, "Lightning Bolt", 1); + + assertLife(playerA, 17); + assertLife(playerB, 20); + + + } +} diff --git a/Mage/src/main/java/mage/abilities/effects/common/PreventAllDamageToAllEffect.java b/Mage/src/main/java/mage/abilities/effects/common/PreventAllDamageToAllEffect.java index b98a0a97cf..413b888cdc 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/PreventAllDamageToAllEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/PreventAllDamageToAllEffect.java @@ -1,6 +1,5 @@ package mage.abilities.effects.common; -import mage.MageObject; import mage.abilities.Ability; import mage.abilities.effects.PreventionEffectImpl; import mage.constants.Duration; @@ -13,6 +12,8 @@ import mage.game.Game; import mage.game.events.GameEvent; import java.util.UUID; +import mage.MageItem; +import mage.game.events.GameEvent.EventType; /** * @author BetaSteward_at_googlemail.com @@ -34,7 +35,7 @@ public class PreventAllDamageToAllEffect extends PreventionEffectImpl { } public PreventAllDamageToAllEffect(Duration duration, FilterPermanentOrPlayer filter, boolean onlyCombat) { - super(duration, Integer.MAX_VALUE, onlyCombat); + super(duration, Integer.MAX_VALUE, onlyCombat, false); this.filter = filter; staticText = "Prevent all " + (onlyCombat ? "combat " : "") @@ -84,7 +85,12 @@ public class PreventAllDamageToAllEffect extends PreventionEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { if (super.applies(event, source, game)) { - MageObject object = game.getObject(event.getTargetId()); + MageItem object ; + if(EventType.DAMAGE_PLAYER.equals(event.getType())) { + object = game.getPlayer(event.getTargetId()); + } else { + object = game.getObject(event.getTargetId()); + } if (object != null) { return filter.match(object, source.getSourceId(), source.getControllerId(), game); }