From f9afd91209488c104130bdc50ab6bae3ab084277 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 23 Sep 2014 16:56:52 +0200 Subject: [PATCH] * Added a Misdirection test (#574). --- .../test/cards/single/MisdirectionTest.java | 73 +++++++++++++++++++ Mage/src/mage/game/stack/Spell.java | 14 ++-- 2 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/single/MisdirectionTest.java diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/MisdirectionTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/MisdirectionTest.java new file mode 100644 index 00000000000..b9a534ef03d --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/MisdirectionTest.java @@ -0,0 +1,73 @@ +/* + * 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 MisdirectionTest extends CardTestPlayerBase { + + /** + * Tests if Misdirection for target opponent works correctly + * https://github.com/magefree/mage/issues/574 + */ + @Test + public void testChangeTargetOpponent() { + // Target opponent discards two cards. Put the top two cards of your library into your graveyard. + addCard(Zone.HAND, playerA, "Rakshasa's Secret"); + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 3); + /* + Misdirection {3}{U}{U} + Instant + You may exile a blue card from your hand rather than pay Misdirection's mana cost. + Change the target of target spell with a single target. + */ + addCard(Zone.HAND, playerB, "Misdirection"); + addCard(Zone.HAND, playerB, "Silvercoat Lion", 2); + addCard(Zone.BATTLEFIELD, playerB, "Island", 5); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Rakshasa's Secret", playerB); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Misdirection", "Rakshasa's Secret", "Rakshasa's Secret"); + addTarget(playerA, playerA); // only possible target is player A + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertGraveyardCount(playerA, "Rakshasa's Secret", 1); + assertGraveyardCount(playerB, "Misdirection", 1); + assertHandCount(playerB, "Silvercoat Lion", 2); + + } +} \ No newline at end of file diff --git a/Mage/src/mage/game/stack/Spell.java b/Mage/src/mage/game/stack/Spell.java index 8183055d31b..84d83463592 100644 --- a/Mage/src/mage/game/stack/Spell.java +++ b/Mage/src/mage/game/stack/Spell.java @@ -73,6 +73,7 @@ public class Spell implements StackObject, Card { private final List spellAbilities = new ArrayList<>(); private final Card card; + private final ObjectColor color; private final SpellAbility ability; private final Zone fromZone; private final UUID id; @@ -83,6 +84,7 @@ public class Spell implements StackObject, Card { public Spell(Card card, SpellAbility ability, UUID controllerId, Zone fromZone) { this.card = card; + this.color = card.getColor().copy(); id = ability.getId(); this.ability = ability; this.ability.setControllerId(controllerId); @@ -121,6 +123,7 @@ public class Spell implements StackObject, Card { this.fromZone = spell.fromZone; this.copiedSpell = spell.copiedSpell; this.faceDown = spell.faceDown; + this.color = spell.color.copy(); } @@ -376,7 +379,7 @@ public class Spell implements StackObject, Card { * targets will be, the copy is put onto the stack with those targets. * * @param game - * @param playerId + * @param playerId - player that can/has to change the taregt of the spell * @param forceChange - does only work for targets with maximum of one * targetId * @param onlyOneTarget - 114.6b one target must be changed to another @@ -414,7 +417,7 @@ public class Spell implements StackObject, Card { /** * Handles the change of one target instance of a mode * - * @param player + * @param player - player that can choose the new target * @param spellAbility * @param mode * @param target @@ -431,7 +434,7 @@ public class Spell implements StackObject, Card { if (targetNames != null && (forceChange || player.chooseUse(mode.getEffects().get(0).getOutcome(), "Change this target: " + targetNames + "?", game))) { // choose exactly one other target - if (forceChange && target.possibleTargets(this.getSourceId(), player.getId(), game).size() > 1) { + if (forceChange && target.possibleTargets(this.getSourceId(), getControllerId(), game).size() > 1) { // controller of spell must be used (e.g. TargetOpponent) int iteration = 0; do { if (iteration > 0) { @@ -439,7 +442,8 @@ public class Spell implements StackObject, Card { } iteration++; newTarget.clearChosen(); - newTarget.chooseTarget(mode.getEffects().get(0).getOutcome(), player.getId(), spellAbility, game); + // TODO: Distinction between "spell controller" and "player that can change the target" - here player is used for both + newTarget.chooseTarget(mode.getEffects().get(0).getOutcome(), player.getId(), spellAbility, game); } while (player.isInGame() && (targetId.equals(newTarget.getFirstTarget()) || newTarget.getTargets().size() != 1)); // choose a new target } else { @@ -591,7 +595,7 @@ public class Spell implements StackObject, Card { @Override public ObjectColor getColor() { - return card.getColor(); + return color; } @Override