* Disrupting Shoal - Fixed that the target spell was not countered if the spell was cast with the regular mana costs.

This commit is contained in:
LevelX2 2016-03-21 11:00:02 +01:00
parent 3441b9d216
commit 285cff0b33
3 changed files with 68 additions and 35 deletions

View file

@ -32,10 +32,12 @@ import mage.ObjectColor;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.Mode; import mage.abilities.Mode;
import mage.abilities.costs.AlternativeCostSourceAbility; import mage.abilities.costs.AlternativeCostSourceAbility;
import mage.abilities.costs.Cost;
import mage.abilities.costs.common.ExileFromHandCost; import mage.abilities.costs.common.ExileFromHandCost;
import mage.abilities.dynamicvalue.common.ExileFromHandCostCardConvertedMana;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.SplitCard;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
@ -99,12 +101,34 @@ class DisruptingShoalCounterTargetEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source)); Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
if (spell != null && new ExileFromHandCostCardConvertedMana().isConvertedManaCostEqual(game, source, this, spell.getConvertedManaCost())) { if (spell != null && isConvertedManaCostEqual(source, spell.getConvertedManaCost())) {
return game.getStack().counter(source.getFirstTarget(), source.getSourceId(), game); return game.getStack().counter(source.getFirstTarget(), source.getSourceId(), game);
} }
return false; return false;
} }
private boolean isConvertedManaCostEqual(Ability sourceAbility, int amount) {
for (Cost cost : sourceAbility.getCosts()) {
if (cost.isPaid() && cost instanceof ExileFromHandCost) {
for (Card card : ((ExileFromHandCost) cost).getCards()) {
if (card instanceof SplitCard) {
if (((SplitCard) card).getLeftHalfCard().getManaCost().convertedManaCost() == amount) {
return true;
}
if (((SplitCard) card).getRightHalfCard().getManaCost().convertedManaCost() == amount) {
return true;
}
} else if (card.getManaCost().convertedManaCost() == amount) {
return true;
}
}
return false;
}
}
// No alternate costs payed so compare to X value
return sourceAbility.getManaCostsToPay().getX() == amount;
}
@Override @Override
public String getText(Mode mode) { public String getText(Mode mode) {
return "Counter target spell if its converted mana cost is X"; return "Counter target spell if its converted mana cost is X";

View file

@ -38,6 +38,48 @@ import org.mage.test.serverside.base.CardTestPlayerBase;
*/ */
public class DisruptingShoalTest extends CardTestPlayerBase { public class DisruptingShoalTest extends CardTestPlayerBase {
@Test
public void testWithManaPaymentEqual() {
addCard(Zone.HAND, playerA, "Silvercoat Lion");
addCard(Zone.BATTLEFIELD, playerA, "Plains", 2);
// You may exile a blue card with converted mana cost X from your hand rather than pay Disrupting Shoal's mana cost.
// Counter target spell if its converted mana cost is X.
addCard(Zone.HAND, playerB, "Disrupting Shoal");
addCard(Zone.BATTLEFIELD, playerB, "Island", 4); // {X}{U}{U}
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Silvercoat Lion");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Disrupting Shoal", "Silvercoat Lion");
setChoice(playerB, "X=2");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertGraveyardCount(playerB, "Disrupting Shoal", 1);
assertGraveyardCount(playerA, "Silvercoat Lion", 1);
}
@Test
public void testWithManaPaymentDifferent() {
addCard(Zone.HAND, playerA, "Silvercoat Lion");
addCard(Zone.BATTLEFIELD, playerA, "Plains", 2);
// You may exile a blue card with converted mana cost X from your hand rather than pay Disrupting Shoal's mana cost.
// Counter target spell if its converted mana cost is X.
addCard(Zone.HAND, playerB, "Disrupting Shoal");
addCard(Zone.BATTLEFIELD, playerB, "Island", 3); // {X}{U}{U}
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Silvercoat Lion");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Disrupting Shoal", "Silvercoat Lion");
setChoice(playerB, "X=1");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertGraveyardCount(playerB, "Disrupting Shoal", 1);
assertPermanentCount(playerA, "Silvercoat Lion", 1);
}
/** /**
* Test that Disrupting Shoal can be played with alternate casting costs And * 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 * the X Value is equal to the CMC of the exiled blue card

View file

@ -33,7 +33,6 @@ import mage.abilities.costs.common.ExileFromHandCost;
import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.SplitCard;
import mage.game.Game; import mage.game.Game;
/** /**
@ -60,38 +59,6 @@ public class ExileFromHandCostCardConvertedMana implements DynamicValue {
return sourceAbility.getManaCostsToPay().getX(); return sourceAbility.getManaCostsToPay().getX();
} }
/**
* This method does only work to compare the cmc for one (or the first card)
* exiled as a cost
*
* @param game
* @param sourceAbility
* @param effect
* @param amount cmc to compare against
* @return
*/
public boolean isConvertedManaCostEqual(Game game, Ability sourceAbility, Effect effect, int amount) {
for (Cost cost : sourceAbility.getCosts()) {
if (cost.isPaid() && cost instanceof ExileFromHandCost) {
for (Card card : ((ExileFromHandCost) cost).getCards()) {
if (card instanceof SplitCard) {
if (((SplitCard) card).getLeftHalfCard().getManaCost().convertedManaCost() == amount) {
return true;
}
if (((SplitCard) card).getRightHalfCard().getManaCost().convertedManaCost() == amount) {
return true;
}
} else if (card.getManaCost().convertedManaCost() == amount) {
return true;
}
return false;
}
}
}
return false;
}
@Override @Override
public ExileFromHandCostCardConvertedMana copy() { public ExileFromHandCostCardConvertedMana copy() {
return new ExileFromHandCostCardConvertedMana(); return new ExileFromHandCostCardConvertedMana();