From 898f111533047ed87e0c3993a8917125b1ba7923 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sun, 21 Sep 2014 10:33:27 +0200 Subject: [PATCH] * Fixed calculation of converted mana costs of spells on the stack that include multiple {X} in casting costs. --- .../mage/sets/mirrodin/ChaliceOfTheVoid.java | 2 +- .../cards/single/ChaliceOfTheVoidTest.java | 65 +++++++++++++++++++ Mage/src/mage/game/stack/Spell.java | 13 +++- 3 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/single/ChaliceOfTheVoidTest.java diff --git a/Mage.Sets/src/mage/sets/mirrodin/ChaliceOfTheVoid.java b/Mage.Sets/src/mage/sets/mirrodin/ChaliceOfTheVoid.java index 0a71caca92f..c38d1ab32f3 100644 --- a/Mage.Sets/src/mage/sets/mirrodin/ChaliceOfTheVoid.java +++ b/Mage.Sets/src/mage/sets/mirrodin/ChaliceOfTheVoid.java @@ -139,7 +139,7 @@ class ChaliceOfTheVoidTriggeredAbility extends TriggeredAbilityImpl { @Override public String getRule() { - return "Whenever a player casts a spell with converted mana cost equal to the number of charge counters on Chalice of the Void, counter that spell."; + return "Whenever a player casts a spell with converted mana cost equal to the number of charge counters on {this}, counter that spell."; } } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/ChaliceOfTheVoidTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/ChaliceOfTheVoidTest.java new file mode 100644 index 00000000000..9d7d6ffcd08 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/ChaliceOfTheVoidTest.java @@ -0,0 +1,65 @@ +/* + * 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.single; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author LevelX2 + */ +public class ChaliceOfTheVoidTest extends CardTestPlayerBase { + + /** + * Theres a Chalice of the Void with 1 counter in play under my control. + * Then I cast second chalice with x=1. For spells on the stack the cmc is the base CMC + X value * {X} in casting costs on top right of card. + * So cmc should be 2 in this case, it shouldnt be countered. + * http://boardgames.stackexchange.com/questions/7327/what-is-the-converted-mana-cost-of-a-spell-with-x-when-cast-with-the-miracle-m + */ + + @Test + public void testCopiedSteelHellkite() { + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 4); + addCard(Zone.HAND, playerA, "Chalice of the Void", 2); + + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Chalice of the Void"); + setChoice(playerA, "X=1"); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Chalice of the Void"); + setChoice(playerA, "X=1"); + + setStopAt(4, PhaseStep.BEGIN_COMBAT); + execute(); + + assertPermanentCount(playerA, "Chalice of the Void", 2); + + } +} diff --git a/Mage/src/mage/game/stack/Spell.java b/Mage/src/mage/game/stack/Spell.java index 2e48c4ebf73..8183055d31b 100644 --- a/Mage/src/mage/game/stack/Spell.java +++ b/Mage/src/mage/game/stack/Spell.java @@ -606,9 +606,18 @@ public class Spell implements StackObject, Card { * @return */ public int getConvertedManaCost() { - int cmc = 0; + int cmc = 0; for (Ability spellAbility: spellAbilities) { - cmc += spellAbility.getManaCosts().convertedManaCost() + spellAbility.getManaCostsToPay().getX(); + int xMultiplier = 0; + for (String symbolString :spellAbility.getManaCosts().getSymbols()) { + int index = symbolString.indexOf("{X}"); + while (index != -1) { + xMultiplier++; + symbolString = symbolString.substring(index + 3); + index = symbolString.indexOf("{X}"); + } + } + cmc += spellAbility.getManaCosts().convertedManaCost() + spellAbility.getManaCostsToPay().getX() * xMultiplier; } return cmc; }