From 42cf7f1f4e7087cca0bf09f5bc8e4cbef9876ceb Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 18 Jun 2015 22:42:13 +0200 Subject: [PATCH] Fixed possible npe, added some tests. --- .../mirrodinbesieged/BlackSunsZenith.java | 1 + .../sets/mirrodinbesieged/BlueSunsZenith.java | 1 + .../test/AI/basic/CostModificationTest.java | 64 +++++++++++++++++++ .../test/cards/triggers/SpellskiteTest.java | 41 ++++++++++++ .../effects/common/ShuffleSpellEffect.java | 16 +++-- 5 files changed, 117 insertions(+), 6 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/AI/basic/CostModificationTest.java diff --git a/Mage.Sets/src/mage/sets/mirrodinbesieged/BlackSunsZenith.java b/Mage.Sets/src/mage/sets/mirrodinbesieged/BlackSunsZenith.java index 410eaa83e94..c344a161b43 100644 --- a/Mage.Sets/src/mage/sets/mirrodinbesieged/BlackSunsZenith.java +++ b/Mage.Sets/src/mage/sets/mirrodinbesieged/BlackSunsZenith.java @@ -51,6 +51,7 @@ public class BlackSunsZenith extends CardImpl { super(ownerId, 39, "Black Sun's Zenith", Rarity.RARE, new CardType[]{CardType.SORCERY}, "{X}{B}{B}"); this.expansionSetCode = "MBS"; + // Put X -1/-1 counters on each creature. Shuffle Black Sun's Zenith into its owner's library. this.getSpellAbility().addEffect(new BlackSunsZenithEffect()); this.getSpellAbility().addEffect(ShuffleSpellEffect.getInstance()); } diff --git a/Mage.Sets/src/mage/sets/mirrodinbesieged/BlueSunsZenith.java b/Mage.Sets/src/mage/sets/mirrodinbesieged/BlueSunsZenith.java index 6f0f4e2ac2a..ec71848b5b5 100644 --- a/Mage.Sets/src/mage/sets/mirrodinbesieged/BlueSunsZenith.java +++ b/Mage.Sets/src/mage/sets/mirrodinbesieged/BlueSunsZenith.java @@ -47,6 +47,7 @@ public class BlueSunsZenith extends CardImpl { super(ownerId, 20, "Blue Sun's Zenith", Rarity.RARE, new CardType[]{CardType.INSTANT}, "{X}{U}{U}{U}"); this.expansionSetCode = "MBS"; + // Target player draws X cards. Shuffle Blue Sun's Zenith into its owner's library. this.getSpellAbility().addEffect(new DrawCardTargetEffect(new ManacostVariableValue())); this.getSpellAbility().addEffect(ShuffleSpellEffect.getInstance()); this.getSpellAbility().addTarget(new TargetPlayer()); diff --git a/Mage.Tests/src/test/java/org/mage/test/AI/basic/CostModificationTest.java b/Mage.Tests/src/test/java/org/mage/test/AI/basic/CostModificationTest.java new file mode 100644 index 00000000000..82c1889c081 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/AI/basic/CostModificationTest.java @@ -0,0 +1,64 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package org.mage.test.AI.basic; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBaseAI; + +/** + * + * @author LevelX2 + */ + +public class CostModificationTest extends CardTestPlayerBaseAI { + + /** + * There seems to be a problem when playing Fluctuator against Computer. + * Once played, I am stuck at "Waiting for Computer" forever... + */ + @Test + public void testFluctuator() { + addCard(Zone.HAND, playerA, "Silvercoat Lion"); + // Destroy all artifacts, creatures, and enchantments. + // Cycling ({3}, Discard this card: Draw a card.) + addCard(Zone.HAND, playerA, "Akroma's Vengeance"); + + addCard(Zone.BATTLEFIELD, playerA, "Plains", 3); + // Cycling abilities you activate cost you up to {2} less to activate. + addCard(Zone.BATTLEFIELD, playerA, "Fluctuator"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertGraveyardCount(playerA, "Akroma's Vengeance", 1); + assertPermanentCount(playerA, "Silvercoat Lion", 1); + } + +} diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/triggers/SpellskiteTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/triggers/SpellskiteTest.java index 7884d15402b..083a1936058 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/triggers/SpellskiteTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/triggers/SpellskiteTest.java @@ -113,4 +113,45 @@ public class SpellskiteTest extends CardTestPlayerBase { } + /** + * Spellskite fails to redirect Cryptic Command on itself + */ + @Test + public void testSpellskite() { + addCard(Zone.BATTLEFIELD, playerA, "Island", 4); + // Choose two - + // Counter target spell; + // or return target permanent to its owner's hand; + // or tap all creatures your opponents control; + // or draw a card. + addCard(Zone.HAND, playerA, "Cryptic Command"); + + addCard(Zone.BATTLEFIELD, playerB, "Spellskite", 1); + addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 1); + addCard(Zone.BATTLEFIELD, playerB, "Mountain", 1); + addCard(Zone.BATTLEFIELD, playerB, "Island", 1); + addCard(Zone.HAND, playerB, "Lightning Bolt", 1); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Lightning Bolt", playerA); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cryptic Command", "mode=1Lightning Bolt^mode=2Silvercoat Lion", "Lightning Bolt"); + setModeChoice(playerA, "1"); // Counter target spell + setModeChoice(playerA, "2"); // return target permanent to its owner's hand + + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerB, "{UP}: Change a target of target spell or ability to {this}.", "Cryptic Command"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertGraveyardCount(playerB, "Lightning Bolt", 1); + + assertGraveyardCount(playerA, "Cryptic Command", 1); + + assertHandCount(playerB, "Spellskite", 1); + assertPermanentCount(playerB, "Silvercoat Lion", 1); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + } } \ No newline at end of file diff --git a/Mage/src/mage/abilities/effects/common/ShuffleSpellEffect.java b/Mage/src/mage/abilities/effects/common/ShuffleSpellEffect.java index ef4b9ae1bfa..47b4322115a 100644 --- a/Mage/src/mage/abilities/effects/common/ShuffleSpellEffect.java +++ b/Mage/src/mage/abilities/effects/common/ShuffleSpellEffect.java @@ -35,6 +35,7 @@ import mage.cards.Card; import mage.constants.Outcome; import mage.constants.Zone; import mage.game.Game; +import mage.game.stack.Spell; import mage.players.Player; /** @@ -58,12 +59,15 @@ public class ShuffleSpellEffect extends OneShotEffect implements MageSingleton { public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { - Card spellCard = game.getStack().getSpell(source.getSourceId()).getCard(); - if (spellCard != null) { - Player owner = game.getPlayer(spellCard.getOwnerId()); - if (owner != null) { - controller.moveCardToLibraryWithInfo(spellCard, source.getSourceId(), game, Zone.STACK, true, true); - owner.shuffleLibrary(game); + Spell spell = game.getStack().getSpell(source.getSourceId()); + if (spell != null) { + Card spellCard = spell.getCard(); + if (spellCard != null) { + Player owner = game.getPlayer(spellCard.getOwnerId()); + if (owner != null) { + controller.moveCardToLibraryWithInfo(spellCard, source.getSourceId(), game, Zone.STACK, true, true); + owner.shuffleLibrary(game); + } } } return true;