From 51424b14602963747add8ea28ec0654bfd031bff Mon Sep 17 00:00:00 2001 From: Samuel Sandeen Date: Sat, 8 Feb 2020 19:28:10 -0500 Subject: [PATCH] Fix Irencrag Feat's spell casting effect. (#6268) * Create a test for Irencrag Feat to ensure it functions correctly. * Fix Irencrag Feat so it works correctly. --- Mage.Sets/src/mage/cards/i/IrencragFeat.java | 26 ++++---- .../cards/continuous/IrencragFeatTest.java | 65 +++++++++++++++++++ 2 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/continuous/IrencragFeatTest.java diff --git a/Mage.Sets/src/mage/cards/i/IrencragFeat.java b/Mage.Sets/src/mage/cards/i/IrencragFeat.java index 022811c4af..ec27580605 100644 --- a/Mage.Sets/src/mage/cards/i/IrencragFeat.java +++ b/Mage.Sets/src/mage/cards/i/IrencragFeat.java @@ -2,6 +2,7 @@ package mage.cards.i; import mage.Mana; import mage.abilities.Ability; +import mage.abilities.Mode; import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.abilities.effects.Effect; import mage.abilities.effects.OneShotEffect; @@ -26,6 +27,7 @@ public final class IrencragFeat extends CardImpl { super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{1}{R}{R}{R}"); // Add seven {R}. You can cast only one more spell this turn. + this.getSpellAbility().addEffect(new BasicManaEffect(Mana.RedMana(7))); this.getSpellAbility().addEffect(new IrencragFeatEffect()); } @@ -41,8 +43,6 @@ public final class IrencragFeat extends CardImpl { class IrencragFeatEffect extends OneShotEffect { - private static final Effect effect = new BasicManaEffect(Mana.RedMana(7)); - IrencragFeatEffect() { super(Outcome.Benefit); staticText = "Add seven {R}. You can cast only one more spell this turn."; @@ -63,24 +63,24 @@ class IrencragFeatEffect extends OneShotEffect { if (watcher == null) { return false; } - int spellsCast = watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(source.getControllerId()); - game.addEffect(new IrencragFeatCantCastEffect(spellsCast), source); - return effect.apply(game, source); + int start = watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(source.getControllerId()); + game.addEffect(new IrencragFeatCantCastEffect(start), source); + return true; } } class IrencragFeatCantCastEffect extends ContinuousRuleModifyingEffectImpl { - private final int spellsCast; + private final int start; - IrencragFeatCantCastEffect(int spellsCast) { - super(Duration.WhileOnBattlefield, Outcome.Detriment); - this.spellsCast = spellsCast; + IrencragFeatCantCastEffect(int start) { + super(Duration.EndOfTurn, Outcome.Detriment); + this.start = start; } private IrencragFeatCantCastEffect(final IrencragFeatCantCastEffect effect) { super(effect); - this.spellsCast = effect.spellsCast; + this.start = effect.start; } @Override @@ -96,7 +96,9 @@ class IrencragFeatCantCastEffect extends ContinuousRuleModifyingEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class); - return event.getPlayerId().equals(source.getControllerId()) - && watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(event.getPlayerId()) > spellsCast + 1; + int spellsCast = watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(source.getControllerId()); + // start is the spell index of IrencragFeat. + // If spellsCast is greater the player has already cast a spell after Irencrag Feat + return event.getPlayerId().equals(source.getControllerId()) && spellsCast > start; } } \ No newline at end of file diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/continuous/IrencragFeatTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/continuous/IrencragFeatTest.java new file mode 100644 index 0000000000..3bd183eb29 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/continuous/IrencragFeatTest.java @@ -0,0 +1,65 @@ +package org.mage.test.cards.continuous; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +public class IrencragFeatTest extends CardTestPlayerBase { + @Test + public void castFirst() { + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 10); + addCard(Zone.HAND, playerA, "Irencrag Feat", 1); + addCard(Zone.HAND, playerA, "Dwarven Trader", 2); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Irencrag Feat"); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Dwarven Trader"); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Dwarven Trader"); + setStopAt(1, PhaseStep.BEGIN_COMBAT); + + execute(); + + assertHandCount(playerA, "Dwarven Trader", 1); + assertPermanentCount(playerA, "Dwarven Trader", 1); + } + + + @Test + public void castThird() { + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 10); + addCard(Zone.HAND, playerA, "Irencrag Feat", 1); + addCard(Zone.HAND, playerA, "Dwarven Trader", 4); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Dwarven Trader"); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Dwarven Trader"); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Irencrag Feat"); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Dwarven Trader"); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Dwarven Trader"); + setStopAt(1, PhaseStep.BEGIN_COMBAT); + + execute(); + + assertHandCount(playerA, "Dwarven Trader", 1); + assertPermanentCount(playerA, "Dwarven Trader", 3); + } + + + @Test + public void nextTurn() { + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 10); + addCard(Zone.HAND, playerA, "Irencrag Feat", 1); + addCard(Zone.HAND, playerA, "Dwarven Trader", 4); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Irencrag Feat"); + castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Dwarven Trader"); + castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Dwarven Trader"); + castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Dwarven Trader"); + castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Dwarven Trader"); + setStopAt(3, PhaseStep.BEGIN_COMBAT); + + execute(); + + assertHandCount(playerA, "Dwarven Trader", 0); + assertPermanentCount(playerA, "Dwarven Trader", 4); + } +}