From 8c725ef86b082f96ce2538276194dfc89aeae513 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 8 Jul 2015 00:05:52 +0200 Subject: [PATCH] * Hallowed Moonlight - Fixed exception if a token should be moved to exile. --- .../sets/magicorigins/HallowedMoonlight.java | 34 +++----- .../replacement/HallowedMoonlightTest.java | 79 +++++++++++++++++++ 2 files changed, 89 insertions(+), 24 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/replacement/HallowedMoonlightTest.java diff --git a/Mage.Sets/src/mage/sets/magicorigins/HallowedMoonlight.java b/Mage.Sets/src/mage/sets/magicorigins/HallowedMoonlight.java index 5bdd1d37f5e..069802820e9 100644 --- a/Mage.Sets/src/mage/sets/magicorigins/HallowedMoonlight.java +++ b/Mage.Sets/src/mage/sets/magicorigins/HallowedMoonlight.java @@ -31,16 +31,14 @@ import java.util.UUID; import mage.abilities.Ability; import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.effects.common.DrawCardSourceControllerEffect; -import mage.cards.Card; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Outcome; import mage.constants.Rarity; -import mage.constants.Zone; import mage.game.Game; +import mage.game.events.EntersTheBattlefieldEvent; import mage.game.events.GameEvent; -import mage.game.events.ZoneChangeEvent; import mage.players.Player; import mage.watchers.common.CreatureWasCastWatcher; @@ -91,38 +89,26 @@ class HallowedMoonlightEffect extends ReplacementEffectImpl { public boolean replaceEvent(GameEvent event, Ability source, Game game) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { - Card card = game.getCard(event.getTargetId()); - if (card != null) { - controller.moveCardToExileWithInfo(card, null, "", source.getSourceId(), game, Zone.BATTLEFIELD, true); - } + EntersTheBattlefieldEvent entersTheBattlefieldEvent = (EntersTheBattlefieldEvent) event; + controller.moveCardToExileWithInfo(entersTheBattlefieldEvent.getTarget(), null, "", + source.getSourceId(), game, entersTheBattlefieldEvent.getFromZone(), true); return true; - } return false; } @Override public boolean checksEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.ZONE_CHANGE || event.getType() == GameEvent.EventType.CREATE_TOKEN; + return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD; } @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.CREATE_TOKEN) { - // TODO: not clear how to check for creature type - // Tokens: Even though you’re probably casting a spell that makes tokens (Lingering Souls, Raise the Alarm, etc), - // the tokens themselves are not cast. As such, Hallowed Moonlight will stop ANY kind of creature tokens - // from entering the battlefield. - return true; - } - if (((ZoneChangeEvent) event).getToZone() == Zone.BATTLEFIELD) { - Card card = game.getCard(event.getTargetId()); - if (card != null && card.getCardType().contains(CardType.CREATURE)) { - // TODO: Bestow Card cast as Enchantment probably not handled correctly - CreatureWasCastWatcher watcher = (CreatureWasCastWatcher) game.getState().getWatchers().get("CreatureWasCast"); - if (watcher != null && !watcher.wasCreatureCastThisTurn(event.getTargetId())) { - return true; - } + EntersTheBattlefieldEvent entersTheBattlefieldEvent = (EntersTheBattlefieldEvent) event; + if (entersTheBattlefieldEvent.getTarget().getCardType().contains(CardType.CREATURE)) { + CreatureWasCastWatcher watcher = (CreatureWasCastWatcher) game.getState().getWatchers().get("CreatureWasCast"); + if (watcher != null && !watcher.wasCreatureCastThisTurn(event.getTargetId())) { + return true; } } return false; diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/replacement/HallowedMoonlightTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/replacement/HallowedMoonlightTest.java new file mode 100644 index 00000000000..739018feb35 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/replacement/HallowedMoonlightTest.java @@ -0,0 +1,79 @@ +/* + * 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.replacement; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author LevelX2 + */ +public class HallowedMoonlightTest extends CardTestPlayerBase { + + @Test + public void testGrindstoneProgenius() { + addCard(Zone.BATTLEFIELD, playerA, "Plains", 2); + + // Until end of turn, if a creature would enter the battlefield and it wasn't cast, exile it instead. + // Draw a card. + addCard(Zone.HAND, playerA, "Hallowed Moonlight"); + + addCard(Zone.BATTLEFIELD, playerB, "Plains", 3); + addCard(Zone.BATTLEFIELD, playerB, "Swamp", 1); + addCard(Zone.HAND, playerB, "Silvercoat Lion"); + addCard(Zone.GRAVEYARD, playerB, "Pillarfield Ox"); + // Put a 1/1 colorless Spirit creature token onto the battlefield. + // Splice onto Arcane {W} + addCard(Zone.HAND, playerB, "Spiritual Visit"); + // Put target creature card from a graveyard onto the battlefield under your control. You lose life equal to its converted mana cost. + addCard(Zone.HAND, playerB, "Reanimate"); + + castSpell(2, PhaseStep.DRAW, playerA, "Hallowed Moonlight"); + + castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Spiritual Visit"); + castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Reanimate", "Pillarfield Ox"); + castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Silvercoat Lion"); + + setStopAt(2, PhaseStep.END_TURN); + execute(); + + assertGraveyardCount(playerA, "Hallowed Moonlight", 1); + assertGraveyardCount(playerB, "Spiritual Visit", 1); + + assertPermanentCount(playerB, "Spirit", 0); + assertPermanentCount(playerB, "Silvercoat Lion", 1); + + assertExileCount(playerB, 1); + assertExileCount("Pillarfield Ox", 1); + + } + +}