* Fixed a problem of returning cards from exile (e.g. Fiend Hunter) if the triggering permanent made multiple zone changes before the left battlefield triggered ability resolved to return the exiled permanents.

This commit is contained in:
LevelX2 2015-11-21 23:41:41 +01:00
parent b84a315780
commit 96bc3172f5
8 changed files with 180 additions and 106 deletions

View file

@ -99,7 +99,7 @@ class LifebloodHydraEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent diedPermanent = (Permanent) getValue("diedPermanent");
Permanent diedPermanent = (Permanent) getValue("permanentLeftBattlefield");
if (diedPermanent != null) {
controller.gainLife(diedPermanent.getPower().getValue(), game);
controller.drawCards(diedPermanent.getPower().getValue(), game);

View file

@ -32,9 +32,8 @@ import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.common.ZoneChangeTriggeredAbility;
import mage.abilities.common.LeavesBattlefieldTriggeredAbility;
import mage.abilities.costs.CostImpl;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.ReturnFromExileForSourceEffect;
import mage.abilities.effects.common.SacrificeSourceUnlessPaysEffect;
import mage.abilities.keyword.FlyingAbility;
@ -57,8 +56,6 @@ import mage.util.CardUtil;
*/
public class WormfangDrake extends CardImpl {
public WormfangDrake(UUID ownerId) {
super(ownerId, 57, "Wormfang Drake", Rarity.COMMON, new CardType[]{CardType.CREATURE}, "{2}{U}");
this.expansionSetCode = "JUD";
@ -75,7 +72,7 @@ public class WormfangDrake extends CardImpl {
new SacrificeSourceUnlessPaysEffect(new WormfangDrakeExileCost()), false));
// When Wormfang Drake leaves the battlefield, return the exiled card to the battlefield under its owner's control.
this.addAbility(new WormfangDrakeTriggeredAbility(new ReturnFromExileForSourceEffect(Zone.BATTLEFIELD), false));
this.addAbility(new LeavesBattlefieldTriggeredAbility(new ReturnFromExileForSourceEffect(Zone.BATTLEFIELD), false));
}
public WormfangDrake(final WormfangDrake card) {
@ -88,23 +85,6 @@ public class WormfangDrake extends CardImpl {
}
}
class WormfangDrakeTriggeredAbility extends ZoneChangeTriggeredAbility {
public WormfangDrakeTriggeredAbility(Effect effect, boolean optional) {
super(Zone.BATTLEFIELD, null, effect, "When {this} leaves the battlefield, ", optional);
}
public WormfangDrakeTriggeredAbility(WormfangDrakeTriggeredAbility ability) {
super(ability);
}
@Override
public WormfangDrakeTriggeredAbility copy() {
return new WormfangDrakeTriggeredAbility(this);
}
}
class WormfangDrakeExileCost extends CostImpl {
private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
@ -114,7 +94,7 @@ class WormfangDrakeExileCost extends CostImpl {
}
public WormfangDrakeExileCost() {
this.addTarget(new TargetControlledCreaturePermanent(1,1,filter, true));
this.addTarget(new TargetControlledCreaturePermanent(1, 1, filter, true));
this.text = "Exile a creature you control other than {this}";
}
@ -129,7 +109,7 @@ class WormfangDrakeExileCost extends CostImpl {
if (controller != null && sourceObject != null) {
if (targets.choose(Outcome.Exile, controllerId, sourceId, game)) {
UUID exileId = CardUtil.getExileZoneId(game, ability.getSourceId(), ability.getSourceObjectZoneChangeCounter());
for (UUID targetId: targets.get(0).getTargets()) {
for (UUID targetId : targets.get(0).getTargets()) {
Permanent permanent = game.getPermanent(targetId);
if (permanent == null) {
return false;

View file

@ -25,19 +25,18 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.sets.magic2011;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.MageInt;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect;
import mage.abilities.keyword.TrampleAbility;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.filter.common.FilterLandCard;
import mage.game.Game;
import mage.game.events.GameEvent;
@ -58,7 +57,10 @@ public class PrimevalTitan extends CardImpl {
this.power = new MageInt(6);
this.toughness = new MageInt(6);
// Trample
this.addAbility(TrampleAbility.getInstance());
// Whenever Primeval Titan enters the battlefield or attacks, you may search your library for up to two land cards, put them onto the battlefield tapped, then shuffle your library.
this.addAbility(new PrimevalTitanAbility());
}

View file

@ -0,0 +1,106 @@
/*
* 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.abilities.oneshot.exile;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
*
* @author LevelX2
*/
public class FiendHunterTest extends CardTestPlayerBase {
/**
*
*
* Hi i rencently play against an opponent that when i did the bounce
* ability with Restoration Angel to Fiend hunter to Exile Primeval Titan
* the first primeval titan that i exiled didnt came back into play.
*
* Just to be sure i exile primeval titan the first time that fiend hunter
* came into play and i resto angel fiend hunter to exile another primeval
* titan Fiend hunter was on the battlefield for 4-6 rounds. When Fiend
* hunter is remove from the battlefield the exile ability is suppose lose
* his effect and the first Titan is suppose to come back.
*/
@Test
public void testExileWorks() {
addCard(Zone.BATTLEFIELD, playerA, "Plains", 3);
// When Fiend Hunter enters the battlefield, you may exile another target creature.
// When Fiend Hunter leaves the battlefield, return the exiled card to the battlefield under its owner's control.
addCard(Zone.HAND, playerA, "Fiend Hunter"); // Creature - Human Cleric 1/3 {1}{W}{W}
// At the beginning of your upkeep, you lose 1 life and put a 1/1 black Faerie Rogue creature token with flying onto the battlefield.
addCard(Zone.BATTLEFIELD, playerB, "Primeval Titan");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Fiend Hunter");
addTarget(playerA, "Primeval Titan");
setStopAt(2, PhaseStep.PRECOMBAT_MAIN);
execute();
assertExileCount("Primeval Titan", 1);
assertPermanentCount(playerA, "Fiend Hunter", 1);
}
@Test
public void testExileAndReturnWorks() {
addCard(Zone.BATTLEFIELD, playerA, "Plains", 4);
// When Fiend Hunter enters the battlefield, you may exile another target creature.
// When Fiend Hunter leaves the battlefield, return the exiled card to the battlefield under its owner's control.
addCard(Zone.HAND, playerA, "Fiend Hunter"); // Creature - Human Cleric 1/3 {1}{W}{W}
// When Restoration Angel enters the battlefield, you may exile target non-Angel creature you control, then return that card to the battlefield under your control
addCard(Zone.HAND, playerA, "Restoration Angel"); // Creature - Angel 3/4 {3}{W}
// At the beginning of your upkeep, you lose 1 life and put a 1/1 black Faerie Rogue creature token with flying onto the battlefield.
addCard(Zone.BATTLEFIELD, playerB, "Primeval Titan");
addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Fiend Hunter");
addTarget(playerA, "Primeval Titan");
// When Restoration Angel enters the battlefield, you may exile target non-Angel creature you control, then return that card to the battlefield under your control
castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Restoration Angel");
addTarget(playerA, "Fiend Hunter");
setStopAt(4, PhaseStep.PRECOMBAT_MAIN);
execute();
assertExileCount("Silvercoat Lion", 1);
assertPermanentCount(playerB, "Primeval Titan", 1);
assertPermanentCount(playerA, "Fiend Hunter", 1);
assertPermanentCount(playerA, "Restoration Angel", 1);
}
}

View file

@ -89,7 +89,7 @@ public class DiesTriggeredAbility extends ZoneChangeTriggeredAbility {
}
}
for (Effect effect : getEffects()) {
effect.setValue("diedPermanent", zEvent.getTarget());
effect.setValue("permanentLeftBattlefield", zEvent.getTarget());
}
return true;
}

View file

@ -1,36 +1,37 @@
/*
* 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.
*/
* 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.common;
import mage.abilities.effects.Effect;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
/**
*
@ -46,6 +47,17 @@ public class LeavesBattlefieldTriggeredAbility extends ZoneChangeTriggeredAbilit
super(ability);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (super.checkTrigger(event, game)) {
for (Effect effect : getEffects()) {
effect.setValue("permanentLeftBattlefield", ((ZoneChangeEvent) event).getTarget());
}
return true;
}
return false;
}
@Override
public LeavesBattlefieldTriggeredAbility copy() {
return new LeavesBattlefieldTriggeredAbility(this);

View file

@ -30,7 +30,6 @@ package mage.abilities.effects.common;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.constants.Outcome;
import mage.constants.Zone;
import static mage.constants.Zone.BATTLEFIELD;
@ -84,39 +83,12 @@ public class ReturnFromExileEffect extends OneShotEffect {
ExileZone exile = game.getExile().getExileZone(exileId);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && exile != null) {
if (zone == Zone.GRAVEYARD) {
controller.moveCards(exile, zone, Zone.EXILED, source, game);
} else {
exile = exile.copy();
for (UUID cardId : exile) {
Card card = game.getCard(cardId);
Player owner = game.getPlayer(card.getOwnerId());
if (owner != null) {
switch (zone) {
case BATTLEFIELD:
card.moveToZone(zone, source.getSourceId(), game, tapped);
if (!game.isSimulation()) {
game.informPlayers(controller.getLogName() + " moves " + card.getLogName() + " to " + zone.toString().toLowerCase());
}
break;
case HAND:
controller.moveCards(card, Zone.EXILED, Zone.HAND, source, game);
break;
case LIBRARY:
controller.moveCardToLibraryWithInfo(card, source.getSourceId(), game, Zone.EXILED, true, true);
break;
case GRAVEYARD:
controller.moveCards(card, Zone.EXILED, Zone.GRAVEYARD, source, game);
break;
default:
card.moveToZone(zone, source.getSourceId(), game, tapped);
if (!game.isSimulation()) {
game.informPlayers(controller.getLogName() + " moves " + card.getLogName() + " to " + zone.toString().toLowerCase());
}
}
}
}
game.getExile().getExileZone(exileId).clear();
switch (zone) {
case LIBRARY:
controller.putCardsOnTopOfLibrary(exile, game, source, false);
break;
default:
controller.moveCards(exile.getCards(game), zone, source, game, tapped, false, true, null);
}
return true;
}

View file

@ -37,9 +37,10 @@ import static mage.constants.Zone.GRAVEYARD;
import static mage.constants.Zone.HAND;
import mage.game.ExileZone;
import mage.game.Game;
import mage.game.permanent.PermanentToken;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.util.CardUtil;
import org.apache.log4j.Logger;
/**
*
@ -95,11 +96,12 @@ public class ReturnFromExileForSourceEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (sourceObject != null && controller != null) {
int zoneChangeCounter = source.getSourceObjectZoneChangeCounter();
if (zoneChangeCounter > 0 && previousZone && !(sourceObject instanceof PermanentToken)) {
zoneChangeCounter--;
Permanent permanentLeftBattlefield = (Permanent) getValue("permanentLeftBattlefield");
if (permanentLeftBattlefield == null) {
Logger.getLogger(ReturnFromExileForSourceEffect.class).error("Permanent not found: " + sourceObject.getName());
return false;
}
ExileZone exile = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source.getSourceId(), zoneChangeCounter));
ExileZone exile = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source.getSourceId(), permanentLeftBattlefield.getZoneChangeCounter(game)));
if (exile != null) { // null is valid if source left battlefield before enters the battlefield effect resolved
if (returnToZone.equals(Zone.BATTLEFIELD)) {
controller.moveCards(exile.getCards(game), returnToZone, source, game, false, false, true, null);