From d95c13c5633de3ed75cb3d11ed3cb9c0b594a7b8 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 6 Jul 2016 16:14:51 +0200 Subject: [PATCH] * Fixed a problem of Identity Thief (fixes ##2052). --- .../mage/sets/eldritchmoon/IdentityThief.java | 12 +-- .../src/mage/sets/ravnica/MoltenSentry.java | 8 +- .../test/cards/copy/IdentityThiefTest.java | 99 +++++++++++++++++++ 3 files changed, 107 insertions(+), 12 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/copy/IdentityThiefTest.java diff --git a/Mage.Sets/src/mage/sets/eldritchmoon/IdentityThief.java b/Mage.Sets/src/mage/sets/eldritchmoon/IdentityThief.java index e0bce17e46a..f8b144094ff 100644 --- a/Mage.Sets/src/mage/sets/eldritchmoon/IdentityThief.java +++ b/Mage.Sets/src/mage/sets/eldritchmoon/IdentityThief.java @@ -29,7 +29,6 @@ package mage.sets.eldritchmoon; import java.util.UUID; import mage.MageInt; -import mage.MageObject; import mage.abilities.Ability; import mage.abilities.TriggeredAbilityImpl; import mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility; @@ -46,8 +45,8 @@ import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.Predicates; import mage.filter.predicate.permanent.TokenPredicate; import mage.game.Game; -import mage.game.events.GameEvent.EventType; import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.common.TargetCreaturePermanent; @@ -58,7 +57,7 @@ import mage.target.common.TargetCreaturePermanent; */ public class IdentityThief extends CardImpl { - private static FilterCreaturePermanent filter = new FilterCreaturePermanent("target nontoken creature"); + private final static FilterCreaturePermanent filter = new FilterCreaturePermanent("target nontoken creature"); static { filter.add(Predicates.not(new TokenPredicate())); @@ -141,13 +140,10 @@ class IdentityThiefEffect extends OneShotEffect { Player controller = game.getPlayer(source.getControllerId()); Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId()); if (controller != null && permanent != null && sourcePermanent != null) { + CopyEffect copyEffect = new CopyEffect(Duration.EndOfTurn, permanent, source.getSourceId()); if (controller.moveCardToExileWithInfo(permanent, source.getSourceId(), sourcePermanent.getIdName(), source.getSourceId(), game, Zone.BATTLEFIELD, true)) { // Copy exiled permanent - MageObject mageObject = game.getObject(permanent.getId()); - if (mageObject != null) { - CopyEffect copyEffect = new CopyEffect(Duration.EndOfTurn, mageObject, source.getSourceId()); - game.addEffect(copyEffect, source); - } + game.addEffect(copyEffect, source); // Create delayed triggered ability AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new ReturnFromExileEffect(source.getSourceId(), Zone.BATTLEFIELD, false)); delayedAbility.setSourceId(source.getSourceId()); diff --git a/Mage.Sets/src/mage/sets/ravnica/MoltenSentry.java b/Mage.Sets/src/mage/sets/ravnica/MoltenSentry.java index 75acb0e3fae..53b7012a2ce 100644 --- a/Mage.Sets/src/mage/sets/ravnica/MoltenSentry.java +++ b/Mage.Sets/src/mage/sets/ravnica/MoltenSentry.java @@ -53,8 +53,8 @@ import mage.players.Player; */ public class MoltenSentry extends CardImpl { - private final static String rule = "As Molten Sentry enters the battlefield, flip a coin. If the coin comes up heads, Molten Sentry enters the battlefield as a " - + "5/2 creature with haste. If it comes up tails, Molten Sentry enters the battlefield as a 2/5 creature with defender."; + private final static String rule = "As {this} enters the battlefield, flip a coin. If the coin comes up heads, {this} enters the battlefield as a " + + "5/2 creature with haste. If it comes up tails, {this} enters the battlefield as a 2/5 creature with defender."; public MoltenSentry(UUID ownerId) { super(ownerId, 136, "Molten Sentry", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{3}{R}"); @@ -94,13 +94,13 @@ class MoltenSentryEffect extends OneShotEffect { Permanent permanent = game.getPermanentEntering(source.getSourceId()); if (controller != null && permanent != null) { if (controller.flipCoin(game)) { - game.informPlayers("Heads: Molten Sentry enters the battlefield as a 5/2 creature with haste"); + game.informPlayers("Heads: " + permanent.getLogName() + " enters the battlefield as a 5/2 creature with haste"); game.addEffect(new SetPowerSourceEffect(new StaticValue(5), Duration.WhileOnBattlefield), source); game.addEffect(new SetToughnessSourceEffect(new StaticValue(2), Duration.WhileOnBattlefield), source); game.addEffect(new GainAbilitySourceEffect(HasteAbility.getInstance(), Duration.WhileOnBattlefield), source); return true; } else { - game.informPlayers("Tails: Molten Sentry enters the battlefield as a 2/5 creature with defender"); + game.informPlayers("Tails: " + permanent.getLogName() + " enters the battlefield as a 2/5 creature with defender"); game.addEffect(new SetPowerSourceEffect(new StaticValue(2), Duration.WhileOnBattlefield), source); game.addEffect(new SetToughnessSourceEffect(new StaticValue(5), Duration.WhileOnBattlefield), source); game.addEffect(new GainAbilitySourceEffect(DefenderAbility.getInstance(), Duration.WhileOnBattlefield), source); diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/copy/IdentityThiefTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/copy/IdentityThiefTest.java new file mode 100644 index 00000000000..7c1ade66078 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/copy/IdentityThiefTest.java @@ -0,0 +1,99 @@ +/* + * 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.copy; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author LevelX2 + */ +public class IdentityThiefTest extends CardTestPlayerBase { + + /** + * This is probably a narrow case of a wider problem base. Identity Thief + * copied Molten Sentry and died immediately (should have been either a 5/2 + * or a 2/5, whatever the original Molten Sentry was). + */ + @Test + public void testCopyCreature() { + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 4); + // As Molten Sentry enters the battlefield, flip a coin. If the coin comes up heads, Molten Sentry enters the battlefield as a 5/2 creature with haste. + // If it comes up tails, Molten Sentry enters the battlefield as a 2/5 creature with defender. + addCard(Zone.HAND, playerA, "Molten Sentry"); // {3}{R} + + // Whenever Identity Thief attacks, you may exile another target nontoken creature. + // If you do, Identity Thief becomes a copy of that creature until end of turn. + // Return the exiled card to the battlefield under its owner's control at the beginning of the next end step. + addCard(Zone.BATTLEFIELD, playerB, "Identity Thief"); // {2}{U}{U} + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Molten Sentry"); + + attack(2, playerB, "Identity Thief"); + addTarget(playerB, "Molten Sentry"); + + setStopAt(2, PhaseStep.POSTCOMBAT_MAIN); + execute(); + + assertExileCount(playerA, 1); + assertExileCount("Molten Sentry", 1); + + assertPermanentCount(playerB, "Identity Thief", 0); + assertPermanentCount(playerB, "Molten Sentry", 1); + } + + @Test + public void testCopyPrimalClay() { + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 4); + // As Primal Clay enters the battlefield, it becomes your choice of a 3/3 artifact creature, a 2/2 artifact creature with flying, or a 1/6 Wall artifact creature with defender in addition to its other types. + addCard(Zone.HAND, playerA, "Primal Clay"); // {4} + + // Whenever Identity Thief attacks, you may exile another target nontoken creature. + // If you do, Identity Thief becomes a copy of that creature until end of turn. + // Return the exiled card to the battlefield under its owner's control at the beginning of the next end step. + addCard(Zone.BATTLEFIELD, playerB, "Identity Thief"); // {2}{U}{U} + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Primal Clay"); + + attack(2, playerB, "Identity Thief"); + addTarget(playerB, "Primal Clay"); + + setStopAt(2, PhaseStep.POSTCOMBAT_MAIN); + execute(); + + assertExileCount(playerA, 1); + assertExileCount("Primal Clay", 1); + + assertPermanentCount(playerB, "Identity Thief", 0); + assertPermanentCount(playerB, "Primal Clay", 1); + } + +}