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.
This commit is contained in:
Samuel Sandeen 2020-02-08 19:28:10 -05:00 committed by GitHub
parent def8ef0a26
commit 51424b1460
2 changed files with 79 additions and 12 deletions

View file

@ -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;
}
}

View file

@ -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);
}
}