From c958a1af2580cbabf98764dfa62cd937368b7c9b Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sat, 27 Dec 2014 02:19:33 +0100 Subject: [PATCH] * Persist - Fixed that the permanent returns now correctly under owner control after dying. --- .../control/GainControlTargetEffectTest.java | 39 +++++++++++++++ .../continious/GainControlTargetEffect.java | 4 +- .../abilities/keyword/PersistAbility.java | 48 +++++++++++++++---- 3 files changed, 81 insertions(+), 10 deletions(-) diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/control/GainControlTargetEffectTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/control/GainControlTargetEffectTest.java index 42779147c6c..3293ebacf13 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/control/GainControlTargetEffectTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/control/GainControlTargetEffectTest.java @@ -37,4 +37,43 @@ public class GainControlTargetEffectTest extends CardTestPlayerBase { assertPermanentCount(playerA, "Silvercoat Lion", 1); assertAbility(playerA, "Silvercoat Lion", HasteAbility.getInstance(), true); } + + /** + * I gained control of my opponent's Glen Elendra Archmage with Vedalken Shackles. + * After I sacrificed it to counter a spell, it Persisted back to my battlefield, + * but it should return under its owner's control. Maybe a Persist problem, but I + * am thinking Vedalken Shackles doesn't realize that it is a different object + * when it returns from the graveyard instead. + */ + + @Test + public void testGainControlOfCreatureWithPersistEffect() { + // {2},{T}: Gain control of target creature with power less than or equal to the number of Islands you control for as long as Vedalken Shackles remains tapped. + addCard(Zone.BATTLEFIELD, playerA, "Vedalken Shackles", 1); + addCard(Zone.BATTLEFIELD, playerA, "Island", 3); + + // Lightning Strike deals 3 damage to target creature or player. + addCard(Zone.HAND, playerB, "Lightning Strike", 1); + addCard(Zone.BATTLEFIELD, playerB, "Mountain", 2); + // Flying + // {U}, Sacrifice Glen Elendra Archmage: Counter target noncreature spell. + // Persist (When this creature dies, if it had no -1/-1 counters on it, return it to the battlefield under its owner's control with a -1/-1 counter on it.) + addCard(Zone.BATTLEFIELD, playerB, "Glen Elendra Archmage"); + + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{2},{T}: Gain control of target creature with power less than or equal to the number of Islands you control for as long as {this} remains tapped.","Glen Elendra Archmage"); + + castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerB, "Lightning Strike", playerA); + activateAbility(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "{U},Sacrifice {this}: Counter target noncreature spell.", "Lightning Strike"); + + setStopAt(1, PhaseStep.END_TURN); + execute(); + + assertGraveyardCount(playerB, "Lightning Strike", 1); + assertLife(playerA, 20); + assertLife(playerB, 20); + // under control of the owner after persist triggered + assertPermanentCount(playerA, "Glen Elendra Archmage", 0); + assertPermanentCount(playerB, "Glen Elendra Archmage", 1); + + } } diff --git a/Mage/src/mage/abilities/effects/common/continious/GainControlTargetEffect.java b/Mage/src/mage/abilities/effects/common/continious/GainControlTargetEffect.java index 79fcd0aa37c..43e9764b198 100644 --- a/Mage/src/mage/abilities/effects/common/continious/GainControlTargetEffect.java +++ b/Mage/src/mage/abilities/effects/common/continious/GainControlTargetEffect.java @@ -108,9 +108,11 @@ public class GainControlTargetEffect extends ContinuousEffectImpl { if (permanent != null) { targetStillExists = true; if (controllingPlayerId != null) { - permanent.changeControllerId(controllingPlayerId, game); + permanent.changeControllerId(controllingPlayerId, game); + permanent.getAbilities().setControllerId(controllingPlayerId); } else { permanent.changeControllerId(source.getControllerId(), game); + permanent.getAbilities().setControllerId(source.getControllerId()); } } } diff --git a/Mage/src/mage/abilities/keyword/PersistAbility.java b/Mage/src/mage/abilities/keyword/PersistAbility.java index 40de4bbb669..8cd4af7c304 100644 --- a/Mage/src/mage/abilities/keyword/PersistAbility.java +++ b/Mage/src/mage/abilities/keyword/PersistAbility.java @@ -1,12 +1,40 @@ +/* +* 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 mage.abilities.keyword; -import mage.constants.Duration; -import mage.constants.Outcome; import mage.abilities.Ability; import mage.abilities.common.DiesTriggeredAbility; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.effects.common.ReturnSourceFromGraveyardToBattlefieldEffect; +import mage.constants.Duration; +import mage.constants.Outcome; import mage.constants.Zone; import mage.counters.CounterType; import mage.game.Game; @@ -14,10 +42,13 @@ import mage.game.events.GameEvent; import mage.game.permanent.Permanent; import mage.target.targetpointer.FixedTarget; + + public class PersistAbility extends DiesTriggeredAbility { + public PersistAbility() { super(new PersistEffect()); - this.addEffect(new ReturnSourceFromGraveyardToBattlefieldEffect()); + this.addEffect(new ReturnSourceFromGraveyardToBattlefieldEffect(false, true)); } public PersistAbility(final PersistAbility ability) { @@ -34,7 +65,7 @@ public class PersistAbility extends DiesTriggeredAbility { if (super.checkTrigger(event, game)) { Permanent p = (Permanent) game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD); if (p.getCounters().getCount(CounterType.M1M1) == 0) { - game.getState().setValue(new StringBuilder("persist").append(getSourceId()).toString(), new FixedTarget(p.getId())); + game.getState().setValue("persist" + getSourceId().toString(), new FixedTarget(p.getId())); return true; } } @@ -96,6 +127,7 @@ class PersistReplacementEffect extends ReplacementEffectImpl { used = true; return false; } + @Override public boolean checksEventType(GameEvent event, Game game) { return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD; @@ -103,11 +135,9 @@ class PersistReplacementEffect extends ReplacementEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getTargetId().equals(source.getSourceId())) - { - Object fixedTarget = game.getState().getValue(new StringBuilder("persist").append(source.getSourceId()).toString()); - if (fixedTarget instanceof FixedTarget && ((FixedTarget) fixedTarget).getFirst(game, source).equals(source.getSourceId())) - { + if (event.getTargetId().equals(source.getSourceId())) { + Object fixedTarget = game.getState().getValue("persist" + source.getSourceId().toString()); + if (fixedTarget instanceof FixedTarget && ((FixedTarget) fixedTarget).getFirst(game, source).equals(source.getSourceId())) { return true; } }