* Persist - Fixed that the permanent returns now correctly under owner control after dying.

This commit is contained in:
LevelX2 2014-12-27 02:19:33 +01:00
parent 18e4bc7f18
commit c958a1af25
3 changed files with 81 additions and 10 deletions

View file

@ -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);
}
}

View file

@ -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());
}
}
}

View file

@ -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;
}
}