diff --git a/Mage.Sets/src/mage/sets/commander2014/LifebloodHydra.java b/Mage.Sets/src/mage/sets/commander2014/LifebloodHydra.java index a0f13d131dd..9dad251209d 100644 --- a/Mage.Sets/src/mage/sets/commander2014/LifebloodHydra.java +++ b/Mage.Sets/src/mage/sets/commander2014/LifebloodHydra.java @@ -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); diff --git a/Mage.Sets/src/mage/sets/judgment/WormfangDrake.java b/Mage.Sets/src/mage/sets/judgment/WormfangDrake.java index f9c5f47a426..15d030afde7 100644 --- a/Mage.Sets/src/mage/sets/judgment/WormfangDrake.java +++ b/Mage.Sets/src/mage/sets/judgment/WormfangDrake.java @@ -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; @@ -56,9 +55,7 @@ import mage.util.CardUtil; * @author Temba21 */ 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"; @@ -66,7 +63,7 @@ public class WormfangDrake extends CardImpl { this.subtype.add("Drake"); this.power = new MageInt(3); this.toughness = new MageInt(4); - + // Flying this.addAbility(FlyingAbility.getInstance()); @@ -74,8 +71,8 @@ public class WormfangDrake extends CardImpl { this.addAbility(new EntersBattlefieldTriggeredAbility( 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)); + // When Wormfang Drake leaves the battlefield, return the exiled card to the battlefield under its owner's control. + 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}"; } @@ -125,11 +105,11 @@ class WormfangDrakeExileCost extends CostImpl { @Override public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana) { Player controller = game.getPlayer(controllerId); - MageObject sourceObject = ability.getSourceObject(game); + MageObject sourceObject = ability.getSourceObject(game); 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; diff --git a/Mage.Sets/src/mage/sets/magic2011/PrimevalTitan.java b/Mage.Sets/src/mage/sets/magic2011/PrimevalTitan.java index 60e79d7a2f1..71c58ed51f3 100644 --- a/Mage.Sets/src/mage/sets/magic2011/PrimevalTitan.java +++ b/Mage.Sets/src/mage/sets/magic2011/PrimevalTitan.java @@ -1,16 +1,16 @@ /* * 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 @@ -20,24 +20,23 @@ * 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.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()); } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/exile/FiendHunterTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/exile/FiendHunterTest.java new file mode 100644 index 00000000000..81a98e7ce54 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/exile/FiendHunterTest.java @@ -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); + + } + +} diff --git a/Mage/src/mage/abilities/common/DiesTriggeredAbility.java b/Mage/src/mage/abilities/common/DiesTriggeredAbility.java index 0efbd80e31e..04a19c3c971 100644 --- a/Mage/src/mage/abilities/common/DiesTriggeredAbility.java +++ b/Mage/src/mage/abilities/common/DiesTriggeredAbility.java @@ -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; } diff --git a/Mage/src/mage/abilities/common/LeavesBattlefieldTriggeredAbility.java b/Mage/src/mage/abilities/common/LeavesBattlefieldTriggeredAbility.java index 48ba332c550..23a867af0dd 100644 --- a/Mage/src/mage/abilities/common/LeavesBattlefieldTriggeredAbility.java +++ b/Mage/src/mage/abilities/common/LeavesBattlefieldTriggeredAbility.java @@ -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); diff --git a/Mage/src/mage/abilities/effects/common/ReturnFromExileEffect.java b/Mage/src/mage/abilities/effects/common/ReturnFromExileEffect.java index 58ebc6676bb..6d8b0880878 100644 --- a/Mage/src/mage/abilities/effects/common/ReturnFromExileEffect.java +++ b/Mage/src/mage/abilities/effects/common/ReturnFromExileEffect.java @@ -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; } diff --git a/Mage/src/mage/abilities/effects/common/ReturnFromExileForSourceEffect.java b/Mage/src/mage/abilities/effects/common/ReturnFromExileForSourceEffect.java index beefcf4ca7c..1f24d70ccb1 100644 --- a/Mage/src/mage/abilities/effects/common/ReturnFromExileForSourceEffect.java +++ b/Mage/src/mage/abilities/effects/common/ReturnFromExileForSourceEffect.java @@ -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);