From 61b1b1ba0509edd2ce6af5ef1ee325218e0f0e4c Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 26 Sep 2018 16:30:17 +0200 Subject: [PATCH] * JumpStart - fixed that card was not always moved to exile after cast from graveyard. --- .../abilities/keywords/JumpStartTest.java | 71 +++++++++++++++++++ .../cards/dynamicvalue/CryptRatsTest.java | 3 +- .../abilities/keyword/FlashbackAbility.java | 3 +- .../abilities/keyword/JumpStartAbility.java | 31 +++++++- 4 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/JumpStartTest.java diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/JumpStartTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/JumpStartTest.java new file mode 100644 index 0000000000..5e250462d8 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/JumpStartTest.java @@ -0,0 +1,71 @@ +package org.mage.test.cards.abilities.keywords; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * Jump-start is found on instants and sorceries. You can cast a card with + * jump-start from your graveyard by paying all its regular costs and one + * additional cost: discarding a card from your hand. + * + * @author LevelX2 + */ +public class JumpStartTest extends CardTestPlayerBase { + + @Test + public void testNormalUse() { + // Direct Current deals 2 damage to any target. + // Jump-start + addCard(Zone.HAND, playerA, "Direct Current", 1); // Sorcery {1}{R}{R} + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 6); + addCard(Zone.HAND, playerA, "Disenchant", 1); + + addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 1); // 2/2 + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Direct Current", "Silvercoat Lion"); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Direct Current with jump-start", playerB); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertGraveyardCount(playerB, "Silvercoat Lion", 1); + assertHandCount(playerA, 0); // 1 from sacrificed Clue and 1 from draw of turn 3 + assertExileCount(playerA, "Direct Current", 1); + + assertLife(playerA, 20); + assertLife(playerB, 18); + + } + + @Test + public void testCastFromGraveyardCountered() { + // Direct Current deals 2 damage to any target. + // Jump-start + addCard(Zone.HAND, playerA, "Direct Current", 1); // Sorcery {1}{R}{R} + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 6); + addCard(Zone.HAND, playerA, "Disenchant", 1); + + addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 1); // 2/2 + addCard(Zone.HAND, playerB, "Counterspell", 1); + addCard(Zone.BATTLEFIELD, playerB, "Island", 2); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Direct Current", "Silvercoat Lion"); + castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Direct Current with jump-start", playerB); + castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerB, "Counterspell", "Direct Current"); + + setStopAt(1, PhaseStep.END_TURN); + execute(); + + assertGraveyardCount(playerB, "Silvercoat Lion", 1); + assertGraveyardCount(playerB, "Counterspell", 1); + assertHandCount(playerA, 0); // 1 from sacrificed Clue and 1 from draw of turn 3 + assertGraveyardCount(playerA, "Direct Current", 0); + assertExileCount(playerA, "Direct Current", 1); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + } +} diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/dynamicvalue/CryptRatsTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/dynamicvalue/CryptRatsTest.java index fd6064f78a..b00ae84ebf 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/dynamicvalue/CryptRatsTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/dynamicvalue/CryptRatsTest.java @@ -10,7 +10,7 @@ public class CryptRatsTest extends CardTestPlayerBase { String cRats = "Crypt Rats"; @Test - public void damageOnlyCreatureAndPlayers(){ + public void damageOnlyCreatureAndPlayers() { addCard(Zone.BATTLEFIELD, playerA, "Swamp", 10); addCard(Zone.BATTLEFIELD, playerA, cRats, 1); addCard(Zone.BATTLEFIELD, playerB, "Shivan Dragon", 1); @@ -20,6 +20,7 @@ public class CryptRatsTest extends CardTestPlayerBase { setChoice(playerA, "X=4"); setStopAt(1, PhaseStep.POSTCOMBAT_MAIN); execute(); + assertLife(playerA, 16); assertLife(playerB, 16); assertGraveyardCount(playerA, cRats, 1); diff --git a/Mage/src/main/java/mage/abilities/keyword/FlashbackAbility.java b/Mage/src/main/java/mage/abilities/keyword/FlashbackAbility.java index 3d48995f48..b07f6dbd32 100644 --- a/Mage/src/main/java/mage/abilities/keyword/FlashbackAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/FlashbackAbility.java @@ -1,4 +1,3 @@ - package mage.abilities.keyword; import java.util.UUID; @@ -158,7 +157,7 @@ public class FlashbackAbility extends SpellAbility { } /** - * Used for split card sin PlayerImpl method: + * Used for split card in PlayerImpl method: * getOtherUseableActivatedAbilities * * @param abilityName diff --git a/Mage/src/main/java/mage/abilities/keyword/JumpStartAbility.java b/Mage/src/main/java/mage/abilities/keyword/JumpStartAbility.java index f04478c4a1..815f625c75 100644 --- a/Mage/src/main/java/mage/abilities/keyword/JumpStartAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/JumpStartAbility.java @@ -4,6 +4,7 @@ import mage.abilities.Ability; import mage.abilities.SpellAbility; import mage.abilities.costs.Cost; import mage.abilities.costs.common.DiscardTargetCost; +import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.ReplacementEffectImpl; import mage.cards.Card; import mage.constants.Duration; @@ -15,13 +16,25 @@ import mage.game.events.GameEvent; import mage.game.events.ZoneChangeEvent; import mage.players.Player; import mage.target.common.TargetCardInHand; +import mage.target.targetpointer.FixedTarget; /** + * Jump-start is found on instants and sorceries. You can cast a card with + * jump-start from your graveyard by paying all its regular costs and one + * additional cost: discarding a card from your hand. Casting a spell with + * jump-start follows all the normal timing rules, so sorceries with jump-start + * are still limited to your main phases. A spell with jump-start that was cast + * from your graveyard can still be countered, and if it has targets, it won't + * do anything if all its targets disappear or otherwise become illegal. After a + * spell with jump-start cast from your graveyard resolves, is countered, or + * leaves the stack in any way, it's exiled. * * @author TheElk801 */ public class JumpStartAbility extends SpellAbility { + private boolean replacementEffectAdded = false; + public JumpStartAbility(Card card) { super(card.getManaCost(), card.getName() + " with jump-start", Zone.GRAVEYARD, SpellAbilityType.BASE_ALTERNATE); this.getCosts().addAll(card.getSpellAbility().getCosts().copy()); @@ -29,7 +42,6 @@ public class JumpStartAbility extends SpellAbility { cost.setText(""); this.addCost(cost); this.getEffects().addAll(card.getSpellAbility().getEffects().copy()); - this.addEffect(new JumpStartReplacementEffect()); this.getTargets().addAll(card.getSpellAbility().getTargets().copy()); this.spellAbilityType = SpellAbilityType.BASE_ALTERNATE; this.timing = card.getSpellAbility().getTiming(); @@ -38,6 +50,21 @@ public class JumpStartAbility extends SpellAbility { public JumpStartAbility(final JumpStartAbility ability) { super(ability); + this.replacementEffectAdded = ability.replacementEffectAdded; + } + + @Override + public SpellAbility getSpellAbilityToResolve(Game game) { + Card card = game.getCard(getSourceId()); + if (card != null) { + if (!replacementEffectAdded) { + replacementEffectAdded = true; + ContinuousEffect effect = new JumpStartReplacementEffect(); + effect.setTargetPointer(new FixedTarget(getSourceId(), game.getState().getZoneChangeCounter(getSourceId()))); + game.addEffect(effect, this); + } + } + return this; } @Override @@ -105,7 +132,7 @@ class JumpStartReplacementEffect extends ReplacementEffectImpl { if (event.getTargetId().equals(source.getSourceId()) && ((ZoneChangeEvent) event).getFromZone() == Zone.STACK && ((ZoneChangeEvent) event).getToZone() != Zone.EXILED) { - if (game.getState().getZoneChangeCounter(source.getSourceId()) == source.getSourceObjectZoneChangeCounter()) { + if (game.getState().getZoneChangeCounter(source.getSourceId()) == source.getSourceObjectZoneChangeCounter() + 1) { return true; }