diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/rules/CantCastTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/rules/CantCastTest.java index 97fa256ab86..1a04f88cbb3 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/rules/CantCastTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/rules/CantCastTest.java @@ -165,4 +165,33 @@ public class CantCastTest extends CardTestPlayerBase { assertLife(playerB, 20); } + + /** + * Test that panic can only be cast during the correct pahse/steü + */ + @Test + public void testPanic() { + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 4); + + // Cast Panic only during combat before blockers are declared. + // Target creature can't block this turn. + // Draw a card at the beginning of the next turn's upkeep. + addCard(Zone.HAND, playerA, "Panic", 4); // Instant - {R} + + addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 1); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Panic", "Silvercoat Lion"); + castSpell(1, PhaseStep.DECLARE_ATTACKERS, playerA, "Panic", "Silvercoat Lion"); + castSpell(1, PhaseStep.DECLARE_BLOCKERS, playerA, "Panic", "Silvercoat Lion"); + castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Panic", "Silvercoat Lion"); + + setStopAt(2, PhaseStep.PRECOMBAT_MAIN); + execute(); + + assertHandCount(playerA, "Panic", 3); + assertHandCount(playerA, 4); + assertGraveyardCount(playerA, "Panic", 1); + + } + } diff --git a/Mage/src/main/java/mage/abilities/effects/common/ruleModifying/CastOnlyDuringPhaseStepSourceEffect.java b/Mage/src/main/java/mage/abilities/effects/common/ruleModifying/CastOnlyDuringPhaseStepSourceEffect.java index 04a5308816e..136676b40a2 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/ruleModifying/CastOnlyDuringPhaseStepSourceEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/ruleModifying/CastOnlyDuringPhaseStepSourceEffect.java @@ -47,12 +47,15 @@ public class CastOnlyDuringPhaseStepSourceEffect extends ContinuousRuleModifying @Override public boolean applies(GameEvent event, Ability source, Game game) { + // has to return true, if the spell cannot be cast in the current phase / step if (event.getSourceId().equals(source.getSourceId())) { - return (turnPhase == null || !game.getPhase().getType().equals(turnPhase)) - && (phaseStep == null || !game.getTurn().getStepType().equals(phaseStep)) - && (condition == null || !condition.apply(game, source)); + if ((turnPhase != null && !game.getPhase().getType().equals(turnPhase)) + || (phaseStep != null && !game.getTurn().getStepType().equals(phaseStep)) + || (condition != null && !condition.apply(game, source))) { + return true; + } } - return false; + return false; // casr not prevented by this effect } @Override