From 974951e18ddf5490fb7012206c2d004eb56c0239 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Fri, 6 Feb 2015 16:13:51 +0100 Subject: [PATCH] * Fixed that for "Shoal" spells a wrong CMC was calculated while on the stack, if alternate casting cost was used (fixes #696). --- .../betrayersofkamigawa/BlazingShoal.java | 2 +- .../betrayersofkamigawa/DisruptingShoal.java | 2 +- .../betrayersofkamigawa/NourishingShoal.java | 2 +- .../betrayersofkamigawa/ShiningShoal.java | 2 +- .../betrayersofkamigawa/SickeningShoal.java | 2 +- .../counterspell/DisruptingShoalTest.java | 82 +++++++++++++++++++ .../costs/common/ExileFromHandCost.java | 23 +++++- 7 files changed, 109 insertions(+), 6 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/counterspell/DisruptingShoalTest.java diff --git a/Mage.Sets/src/mage/sets/betrayersofkamigawa/BlazingShoal.java b/Mage.Sets/src/mage/sets/betrayersofkamigawa/BlazingShoal.java index b558b36793b..8581c68c6ae 100644 --- a/Mage.Sets/src/mage/sets/betrayersofkamigawa/BlazingShoal.java +++ b/Mage.Sets/src/mage/sets/betrayersofkamigawa/BlazingShoal.java @@ -61,7 +61,7 @@ public class BlazingShoal extends CardImpl { FilterOwnedCard filter = new FilterOwnedCard("a red card with converted mana cost X from your hand"); filter.add(new ColorPredicate(ObjectColor.RED)); filter.add(Predicates.not(new CardIdPredicate(this.getId()))); // the exile cost can never be paid with the card itself - this.addAbility(new AlternativeCostSourceAbility(new ExileFromHandCost(new TargetCardInHand(filter)))); + this.addAbility(new AlternativeCostSourceAbility(new ExileFromHandCost(new TargetCardInHand(filter),true))); // Target creature gets +X/+0 until end of turn. this.getSpellAbility().addEffect(new BoostTargetEffect(new ExileFromHandCostCardConvertedMana(), new StaticValue(0), Duration.EndOfTurn)); diff --git a/Mage.Sets/src/mage/sets/betrayersofkamigawa/DisruptingShoal.java b/Mage.Sets/src/mage/sets/betrayersofkamigawa/DisruptingShoal.java index 2fc03995818..571ed3d8697 100644 --- a/Mage.Sets/src/mage/sets/betrayersofkamigawa/DisruptingShoal.java +++ b/Mage.Sets/src/mage/sets/betrayersofkamigawa/DisruptingShoal.java @@ -65,7 +65,7 @@ public class DisruptingShoal extends CardImpl { FilterOwnedCard filter = new FilterOwnedCard("a blue card with converted mana cost X from your hand"); filter.add(new ColorPredicate(ObjectColor.BLUE)); filter.add(Predicates.not(new CardIdPredicate(this.getId()))); // the exile cost can never be paid with the card itself - this.addAbility(new AlternativeCostSourceAbility(new ExileFromHandCost(new TargetCardInHand(filter)))); + this.addAbility(new AlternativeCostSourceAbility(new ExileFromHandCost(new TargetCardInHand(filter), true))); // 2/1/2005: Disrupting Shoal can target any spell, but does nothing unless that spell's converted mana cost is X. // Counter target spell if its converted mana cost is X. diff --git a/Mage.Sets/src/mage/sets/betrayersofkamigawa/NourishingShoal.java b/Mage.Sets/src/mage/sets/betrayersofkamigawa/NourishingShoal.java index d0a0ca03110..ecba9b6217c 100644 --- a/Mage.Sets/src/mage/sets/betrayersofkamigawa/NourishingShoal.java +++ b/Mage.Sets/src/mage/sets/betrayersofkamigawa/NourishingShoal.java @@ -58,7 +58,7 @@ public class NourishingShoal extends CardImpl { FilterOwnedCard filter = new FilterOwnedCard("a green card with converted mana cost X from your hand"); filter.add(new ColorPredicate(ObjectColor.GREEN)); filter.add(Predicates.not(new CardIdPredicate(this.getId()))); // the exile cost can never be paid with the card itself - this.addAbility(new AlternativeCostSourceAbility(new ExileFromHandCost(new TargetCardInHand(filter)))); + this.addAbility(new AlternativeCostSourceAbility(new ExileFromHandCost(new TargetCardInHand(filter), true))); // You gain X life. this.getSpellAbility().addEffect(new GainLifeEffect(new ExileFromHandCostCardConvertedMana())); diff --git a/Mage.Sets/src/mage/sets/betrayersofkamigawa/ShiningShoal.java b/Mage.Sets/src/mage/sets/betrayersofkamigawa/ShiningShoal.java index 3ad92a81e73..d1506296425 100644 --- a/Mage.Sets/src/mage/sets/betrayersofkamigawa/ShiningShoal.java +++ b/Mage.Sets/src/mage/sets/betrayersofkamigawa/ShiningShoal.java @@ -68,7 +68,7 @@ public class ShiningShoal extends CardImpl { FilterOwnedCard filter = new FilterOwnedCard("a white card with converted mana cost X from your hand"); filter.add(new ColorPredicate(ObjectColor.WHITE)); filter.add(Predicates.not(new CardIdPredicate(this.getId()))); // the exile cost can never be paid with the card itself - this.addAbility(new AlternativeCostSourceAbility(new ExileFromHandCost(new TargetCardInHand(filter)))); + this.addAbility(new AlternativeCostSourceAbility(new ExileFromHandCost(new TargetCardInHand(filter), true))); // The next X damage that a source of your choice would deal to you and/or creatures you control this turn is dealt to target creature or player instead. this.getSpellAbility().addEffect(new ShiningShoalPreventDamageTargetEffect(Duration.EndOfTurn, new ExileFromHandCostCardConvertedMana())); diff --git a/Mage.Sets/src/mage/sets/betrayersofkamigawa/SickeningShoal.java b/Mage.Sets/src/mage/sets/betrayersofkamigawa/SickeningShoal.java index b1b37039fe0..fdecb658b4b 100644 --- a/Mage.Sets/src/mage/sets/betrayersofkamigawa/SickeningShoal.java +++ b/Mage.Sets/src/mage/sets/betrayersofkamigawa/SickeningShoal.java @@ -62,7 +62,7 @@ public class SickeningShoal extends CardImpl { FilterOwnedCard filter = new FilterOwnedCard("a black card with converted mana cost X from your hand"); filter.add(new ColorPredicate(ObjectColor.BLACK)); filter.add(Predicates.not(new CardIdPredicate(this.getId()))); // the exile cost can never be paid with the card itself - this.addAbility(new AlternativeCostSourceAbility(new ExileFromHandCost(new TargetCardInHand(filter)))); + this.addAbility(new AlternativeCostSourceAbility(new ExileFromHandCost(new TargetCardInHand(filter), true))); // Target creature gets -X/-X until end of turn. DynamicValue x = new SignInversionDynamicValue(new ExileFromHandCostCardConvertedMana()); diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/counterspell/DisruptingShoalTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/counterspell/DisruptingShoalTest.java new file mode 100644 index 00000000000..c1b2a801a94 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/counterspell/DisruptingShoalTest.java @@ -0,0 +1,82 @@ +/* + * 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.cards.abilities.oneshot.counterspell; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author LevelX2 + */ + +public class DisruptingShoalTest extends CardTestPlayerBase { + + /** + * Test that Disrupting Shoal can be played with alternate casting costs + * And the X Value is equal to the CMC of the exiled blue card + * + */ + @Test + public void testWithBlueCardsInHand() { + addCard(Zone.HAND, playerA, "Pillarfield Ox"); + addCard(Zone.HAND, playerA, "Spell Snare"); + addCard(Zone.BATTLEFIELD, playerA, "Plains", 3); + addCard(Zone.BATTLEFIELD, playerA, "Island", 4); + + addCard(Zone.HAND, playerB, "Disrupting Shoal"); + addCard(Zone.HAND, playerB, "Mistfire Adept", 2); // blue cards with 4 CMC to pay Disrupting Shoal + addCard(Zone.BATTLEFIELD, playerB, "Island", 2); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Pillarfield Ox"); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Disrupting Shoal", "Pillarfield Ox", "Pillarfield Ox"); + playerB.addChoice("Yes"); // use alternate costs = Mistfire Adept = CMC = 4 + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Spell Snare", "Disrupting Shoal", "Disrupting Shoal"); + + + setStopAt(1, PhaseStep.CLEANUP); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + assertGraveyardCount(playerB,"Disrupting Shoal", 1); + assertExileCount(playerB, 1); // Mistfire Adept + assertHandCount(playerB, "Mistfire Adept", 1); // One Left + + assertHandCount(playerA, "Spell Snare", 1); // Can't be cast -> no valid target + + assertGraveyardCount(playerA, "Pillarfield Ox", 1); + + + + } +} \ No newline at end of file diff --git a/Mage/src/mage/abilities/costs/common/ExileFromHandCost.java b/Mage/src/mage/abilities/costs/common/ExileFromHandCost.java index d447ab4d7c1..f9e3b063ef3 100644 --- a/Mage/src/mage/abilities/costs/common/ExileFromHandCost.java +++ b/Mage/src/mage/abilities/costs/common/ExileFromHandCost.java @@ -31,8 +31,10 @@ package mage.abilities.costs.common; import java.util.ArrayList; import java.util.List; import java.util.UUID; +import mage.Mana; import mage.abilities.Ability; import mage.abilities.costs.CostImpl; +import mage.abilities.costs.mana.VariableManaCost; import mage.cards.Card; import mage.constants.Outcome; import mage.constants.Zone; @@ -47,31 +49,50 @@ import mage.target.common.TargetCardInHand; public class ExileFromHandCost extends CostImpl { List cards = new ArrayList<>(); + private boolean setXFromCMC; public ExileFromHandCost(TargetCardInHand target) { + this(target, false); + } + /** + * + * @param target + * @param setXFromCMC the spells X value on the stack is set to the converted mana costs of the exiled card + */ + public ExileFromHandCost(TargetCardInHand target, boolean setXFromCMC) { this.addTarget(target); this.text = "exile " + target.getTargetName(); + this.setXFromCMC = setXFromCMC; } - public ExileFromHandCost(ExileFromHandCost cost) { + public ExileFromHandCost(final ExileFromHandCost cost) { super(cost); for (Card card: cost.cards) { this.cards.add(card.copy()); } + this.setXFromCMC = cost.setXFromCMC; } @Override public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana) { if (targets.choose(Outcome.Exile, controllerId, sourceId, game)) { Player player = game.getPlayer(controllerId); + int cmc = 0; for (UUID targetId: targets.get(0).getTargets()) { Card card = player.getHand().get(targetId, game); if (card == null) { return false; } + cmc += card.getManaCost().convertedManaCost(); this.cards.add(card); paid |= player.moveCardToExileWithInfo(card, null, null, ability.getSourceId(), game, Zone.HAND); } + if (paid && setXFromCMC) { + VariableManaCost vmc = new VariableManaCost(); + vmc.setAmount(cmc); + vmc.setPaid(); + ability.getManaCostsToPay().add(vmc); + } } return paid; }