From d3000da3a3e072cc90200947c59254a1b58052da Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sat, 14 Nov 2015 11:14:50 +0100 Subject: [PATCH] * Void Winnower - Fixed that the check for even casting costs did not work correctly. --- .../sets/battleforzendikar/VoidWinnower.java | 10 +- .../cards/abilities/keywords/EvolveTest.java | 5 +- .../mage/test/cards/rules/CantCastTest.java | 113 ++++++++++++++++++ Mage/src/mage/abilities/AbilityImpl.java | 5 +- Mage/src/mage/abilities/SpellAbility.java | 19 +++ Mage/src/mage/game/Game.java | 2 + Mage/src/mage/game/GameImpl.java | 5 + Mage/src/mage/game/GameState.java | 6 +- Mage/src/mage/game/events/GameEvent.java | 4 + Mage/src/mage/game/stack/Spell.java | 17 +-- Mage/src/mage/players/PlayerImpl.java | 2 +- 11 files changed, 163 insertions(+), 25 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/rules/CantCastTest.java diff --git a/Mage.Sets/src/mage/sets/battleforzendikar/VoidWinnower.java b/Mage.Sets/src/mage/sets/battleforzendikar/VoidWinnower.java index 0a15ab9ecf8..62998554aa6 100644 --- a/Mage.Sets/src/mage/sets/battleforzendikar/VoidWinnower.java +++ b/Mage.Sets/src/mage/sets/battleforzendikar/VoidWinnower.java @@ -31,6 +31,7 @@ import java.util.UUID; import mage.MageInt; import mage.MageObject; import mage.abilities.Ability; +import mage.abilities.SpellAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.abilities.effects.RestrictionEffect; @@ -44,7 +45,6 @@ import mage.game.Game; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; -import mage.game.stack.Spell; /** * @@ -109,16 +109,16 @@ class VoidWinnowerCantCastEffect extends ContinuousRuleModifyingEffectImpl { @Override public boolean checksEventType(GameEvent event, Game game) { - return event.getType() == EventType.CAST_SPELL; + return event.getType() == EventType.CAST_SPELL_LATE; } @Override public boolean applies(GameEvent event, Ability source, Game game) { if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { - MageObject object = game.getObject(event.getSourceId()); - if (object != null && (object instanceof Spell)) { + Ability ability = (Ability) getValue("targetAbility"); + if (ability != null && (ability instanceof SpellAbility)) { // the low bit will always be set on an odd number. - return (((Spell) object).getConvertedManaCost() & 1) == 0; + return (((SpellAbility) ability).getConvertedManaCost() & 1) == 0; } } return false; diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/EvolveTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/EvolveTest.java index 6aad4cc47e1..54826d01cad 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/EvolveTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/EvolveTest.java @@ -247,6 +247,7 @@ public class EvolveTest extends CardTestPlayerBase { castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Adaptive Snapjaw"); addTarget(playerA, "Adaptive Snapjaw"); addTarget(playerA, "Adaptive Snapjaw"); + setChoice(playerA, "Whenever {this} evolves"); setStopAt(1, PhaseStep.BEGIN_COMBAT); execute(); @@ -255,8 +256,8 @@ public class EvolveTest extends CardTestPlayerBase { assertPermanentCount(playerA, "Ivy Lane Denizen", 2); assertPermanentCount(playerA, "Adaptive Snapjaw", 1); - assertPowerToughness(playerA, "Adaptive Snapjaw", 9, 5); // +2 from Ivys +1 from add to all with +1/+1 counter - assertPowerToughness(playerA, "Renegade Krasis", 5, 4); // +1 Evolve by Ivy +1 Evolve by Snapjaw + assertPowerToughness(playerA, "Adaptive Snapjaw", 9, 5); // +2 from Ivys and +1 from add to all with +1/+1 counter + assertPowerToughness(playerA, "Renegade Krasis", 5, 4); // +1 Evolve by Ivy and +1 Evolve by Snapjaw assertPowerToughness(playerA, "Ivy Lane Denizen", 2, 3, Filter.ComparisonScope.Any); assertPowerToughness(playerA, "Ivy Lane Denizen", 5, 6, Filter.ComparisonScope.Any); // +1 from Other Ivy + 2 from Krasis diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/rules/CantCastTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/rules/CantCastTest.java new file mode 100644 index 00000000000..50972e0851d --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/rules/CantCastTest.java @@ -0,0 +1,113 @@ +/* + * 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.rules; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author LevelX2 + */ +public class CantCastTest extends CardTestPlayerBase { + + /** + * I control Void Winnower. But my opponent can cast Jayemdae Tome (that's + * converted mana cost is even) He can cast other even spell. + * + */ + @Test + public void testVoidWinnower() { + // Your opponent can't cast spells with even converted mana costs. (Zero is even.) + // Your opponents can't block with creatures with even converted mana costs. + addCard(Zone.BATTLEFIELD, playerB, "Void Winnower"); + + addCard(Zone.BATTLEFIELD, playerA, "Forest", 4); + + addCard(Zone.HAND, playerA, "Jayemdae Tome", 1); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Jayemdae Tome"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertHandCount(playerA, "Jayemdae Tome", 1); + + assertPermanentCount(playerA, "Jayemdae Tome", 0); + + } + + @Test + public void testVoidWinnower2() { + // Your opponent can't cast spells with even converted mana costs. (Zero is even.) + // Your opponents can't block with creatures with even converted mana costs. + addCard(Zone.BATTLEFIELD, playerB, "Void Winnower"); + + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 4); + + // Blaze deals X damage to target creature or player. + addCard(Zone.HAND, playerA, "Blaze", 1); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Blaze", playerA); + setChoice(playerA, "X=3"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertHandCount(playerA, "Blaze", 1); + + assertLife(playerB, 20); + + } + + @Test + public void testVoidWinnower3() { + // Your opponent can't cast spells with even converted mana costs. (Zero is even.) + // Your opponents can't block with creatures with even converted mana costs. + addCard(Zone.BATTLEFIELD, playerB, "Void Winnower"); + + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 5); + + // Blaze deals X damage to target creature or player. + addCard(Zone.HAND, playerA, "Blaze", 1); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Blaze", playerB); + setChoice(playerA, "X=4"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertHandCount(playerA, "Blaze", 0); + assertGraveyardCount(playerA, "Blaze", 1); + + assertLife(playerB, 16); + + } +} diff --git a/Mage/src/mage/abilities/AbilityImpl.java b/Mage/src/mage/abilities/AbilityImpl.java index 4efdb776847..4043b0701ea 100644 --- a/Mage/src/mage/abilities/AbilityImpl.java +++ b/Mage/src/mage/abilities/AbilityImpl.java @@ -317,7 +317,10 @@ public abstract class AbilityImpl implements Ability { // its mana cost; see rule 107.3), the player announces the value of that variable. VariableManaCost variableManaCost = handleManaXCosts(game, noMana, controller); String announceString = handleOtherXCosts(game, controller); - + // For effects from cards like Void Winnower x costs have to be set + if (game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.CAST_SPELL_LATE, getId(), getSourceId(), getControllerId()), this)) { + return false; + } for (Mode mode : this.getModes().getSelectedModes()) { this.getModes().setActiveMode(mode); //20121001 - 601.2c diff --git a/Mage/src/mage/abilities/SpellAbility.java b/Mage/src/mage/abilities/SpellAbility.java index 5106b8dc61c..01adf094ffe 100644 --- a/Mage/src/mage/abilities/SpellAbility.java +++ b/Mage/src/mage/abilities/SpellAbility.java @@ -178,4 +178,23 @@ public class SpellAbility extends ActivatedAbilityImpl { return cardName; } + public int getConvertedManaCost() { + int cmc = 0; + int xMultiplier = 0; + for (String symbolString : getManaCosts().getSymbols()) { + int index = symbolString.indexOf("{X}"); + while (index != -1) { + xMultiplier++; + symbolString = symbolString.substring(index + 3); + index = symbolString.indexOf("{X}"); + } + } + if (getSpellAbilityType().equals(SpellAbilityType.BASE_ALTERNATE)) { + cmc += getManaCostsToPay().getX() * xMultiplier; + } else { + cmc += getManaCosts().convertedManaCost() + getManaCostsToPay().getX() * xMultiplier; + } + return cmc; + + } } diff --git a/Mage/src/mage/game/Game.java b/Mage/src/mage/game/Game.java index 7171a59b1cb..fb2244bfaac 100644 --- a/Mage/src/mage/game/Game.java +++ b/Mage/src/mage/game/Game.java @@ -290,6 +290,8 @@ public interface Game extends MageItem, Serializable { boolean replaceEvent(GameEvent event); + boolean replaceEvent(GameEvent event, Ability targetAbility); + /** * Creates and fires an damage prevention event * diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index 6edfd87c44b..16c0b614e70 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -2291,6 +2291,11 @@ public abstract class GameImpl implements Game, Serializable { return state.replaceEvent(event, this); } + @Override + public boolean replaceEvent(GameEvent event, Ability targetAbility) { + return state.replaceEvent(event, targetAbility, this); + } + @Override public PreventionEffectData preventDamage(GameEvent event, Ability source, Game game, boolean preventAllDamage) { return preventDamage(event, source, game, Integer.MAX_VALUE); diff --git a/Mage/src/mage/game/GameState.java b/Mage/src/mage/game/GameState.java index d2af936c84d..0119c0920ee 100644 --- a/Mage/src/mage/game/GameState.java +++ b/Mage/src/mage/game/GameState.java @@ -668,7 +668,11 @@ public class GameState implements Serializable, Copyable { } public boolean replaceEvent(GameEvent event, Game game) { - if (effects.preventedByRuleModification(event, null, game, false)) { + return replaceEvent(event, null, game); + } + + public boolean replaceEvent(GameEvent event, Ability targetAbility, Game game) { + if (effects.preventedByRuleModification(event, targetAbility, game, false)) { return true; } return effects.replaceEvent(event, game); diff --git a/Mage/src/mage/game/events/GameEvent.java b/Mage/src/mage/game/events/GameEvent.java index 6b96c0a15a5..95b1a318e67 100644 --- a/Mage/src/mage/game/events/GameEvent.java +++ b/Mage/src/mage/game/events/GameEvent.java @@ -109,6 +109,10 @@ public class GameEvent implements Serializable { LOSE_LIFE, LOST_LIFE, PLAY_LAND, LAND_PLAYED, CAST_SPELL, + /* SPELL_CAST + x-Costs are already defined + */ + CAST_SPELL_LATE, /* SPELL_CAST targetId id of the spell that's cast sourceId sourceId of the spell that's cast diff --git a/Mage/src/mage/game/stack/Spell.java b/Mage/src/mage/game/stack/Spell.java index d2efaaaf155..5e23cf1f1d1 100644 --- a/Mage/src/mage/game/stack/Spell.java +++ b/Mage/src/mage/game/stack/Spell.java @@ -491,21 +491,8 @@ public class Spell extends StackObjImpl implements Card { if (faceDown) { return 0; } - for (Ability spellAbility : spellAbilities) { - 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}"); - } - } - if (this.getSpellAbility().getSpellAbilityType().equals(SpellAbilityType.BASE_ALTERNATE)) { - cmc += spellAbility.getManaCostsToPay().getX() * xMultiplier; - } else { - cmc += spellAbility.getManaCosts().convertedManaCost() + spellAbility.getManaCostsToPay().getX() * xMultiplier; - } + for (SpellAbility spellAbility : spellAbilities) { + cmc += spellAbility.getConvertedManaCost(); } if (this.getSpellAbility().getSpellAbilityType().equals(SpellAbilityType.BASE_ALTERNATE)) { cmc += getCard().getManaCost().convertedManaCost(); diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index d736afc3c72..7f2e1424af2 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -945,7 +945,7 @@ public abstract class PlayerImpl implements Player, Serializable { //20091005 - 601.2a Card card = game.getCard(ability.getSourceId()); if (card != null) { - if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, ability.getId(), ability.getSourceId(), playerId))) { + if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, ability.getId(), ability.getSourceId(), playerId), ability)) { int bookmark = game.bookmarkState(); Zone fromZone = game.getState().getZone(card.getMainCard().getId()); card.cast(game, fromZone, ability, playerId);