diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/HikariTwilightGuardian.java b/Mage.Sets/src/mage/sets/championsofkamigawa/HikariTwilightGuardian.java index e848c437702..b6da86b62e9 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/HikariTwilightGuardian.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/HikariTwilightGuardian.java @@ -25,26 +25,18 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. */ - package mage.sets.championsofkamigawa; import java.util.UUID; - -import mage.constants.CardType; -import mage.constants.Rarity; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.SpellCastControllerTriggeredAbility; -import mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility; -import mage.abilities.effects.OneShotEffect; -import mage.abilities.effects.common.ReturnFromExileEffect; +import mage.abilities.effects.Effect; +import mage.abilities.effects.common.ExileReturnToBattlefieldOwnerNextEndStepEffect; import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; -import mage.constants.Outcome; -import mage.constants.Zone; +import mage.constants.CardType; +import mage.constants.Rarity; import mage.filter.common.FilterSpiritOrArcaneCard; -import mage.game.Game; -import mage.game.permanent.Permanent; /** * @@ -54,7 +46,7 @@ public class HikariTwilightGuardian extends CardImpl { private static final FilterSpiritOrArcaneCard filter = new FilterSpiritOrArcaneCard(); - public HikariTwilightGuardian (UUID ownerId) { + public HikariTwilightGuardian(UUID ownerId) { super(ownerId, 12, "Hikari, Twilight Guardian", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{3}{W}{W}"); this.expansionSetCode = "CHK"; this.supertype.add("Legendary"); @@ -66,10 +58,12 @@ public class HikariTwilightGuardian extends CardImpl { this.addAbility(FlyingAbility.getInstance()); // Whenever you cast a Spirit or Arcane spell, you may exile Hikari, Twilight Guardian. If you do, return it to the battlefield under its owner's control at the beginning of the next end step. - this.addAbility(new SpellCastControllerTriggeredAbility(new HikariTwilightGuardianEffect(), filter, true)); + Effect effect = new ExileReturnToBattlefieldOwnerNextEndStepEffect(); + effect.setText("you may exile {this}. If you do, return it to the battlefield under its owner's control at the beginning of the next end step"); + this.addAbility(new SpellCastControllerTriggeredAbility(effect, filter, true)); } - public HikariTwilightGuardian (final HikariTwilightGuardian card) { + public HikariTwilightGuardian(final HikariTwilightGuardian card) { super(card); } @@ -79,41 +73,3 @@ public class HikariTwilightGuardian extends CardImpl { } } - -class HikariTwilightGuardianEffect extends OneShotEffect { - - private static final String effectText = "Exile {this}. Return it to the battlefield under your control at the beginning of the next end step"; - - HikariTwilightGuardianEffect ( ) { - super(Outcome.Benefit); - staticText = effectText; - } - - HikariTwilightGuardianEffect(HikariTwilightGuardianEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = game.getPermanent(source.getSourceId()); - if (permanent != null) { - if (permanent.moveToExile(source.getSourceId(), "Hikari, Twilight Guardian", source.getSourceId(), game)) { - //create delayed triggered ability - AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility( - new ReturnFromExileEffect(source.getSourceId(), Zone.BATTLEFIELD)); - delayedAbility.setSourceId(source.getSourceId()); - delayedAbility.setControllerId(source.getControllerId()); - delayedAbility.setSourceObject(source.getSourceObject(game), game); - game.addDelayedTriggeredAbility(delayedAbility); - return true; - } - } - return false; - } - - @Override - public HikariTwilightGuardianEffect copy() { - return new HikariTwilightGuardianEffect(this); - } - -} diff --git a/Mage.Sets/src/mage/sets/dragonsmaze/AEtherling.java b/Mage.Sets/src/mage/sets/dragonsmaze/AEtherling.java index e0f87fb4b96..a79869e862a 100644 --- a/Mage.Sets/src/mage/sets/dragonsmaze/AEtherling.java +++ b/Mage.Sets/src/mage/sets/dragonsmaze/AEtherling.java @@ -25,38 +25,28 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. */ - package mage.sets.dragonsmaze; import java.util.UUID; -import mage.constants.CardType; -import mage.constants.Duration; -import mage.constants.Outcome; -import mage.constants.Rarity; -import mage.constants.Zone; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; -import mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.OneShotEffect; -import mage.abilities.effects.common.ReturnFromExileEffect; +import mage.abilities.effects.common.ExileReturnToBattlefieldOwnerNextEndStepEffect; import mage.abilities.effects.common.combat.CantBeBlockedSourceEffect; import mage.abilities.effects.common.continuous.BoostSourceEffect; import mage.cards.CardImpl; -import mage.game.Game; -import mage.game.permanent.Permanent; - +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Rarity; +import mage.constants.Zone; /** * * @author LevelX2 */ - - public class AEtherling extends CardImpl { - public AEtherling (UUID ownerId) { + public AEtherling(UUID ownerId) { super(ownerId, 11, "AEtherling", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{4}{U}{U}"); this.expansionSetCode = "DGM"; this.subtype.add("Shapeshifter"); @@ -65,7 +55,7 @@ public class AEtherling extends CardImpl { this.toughness = new MageInt(5); // {U}: Exile AEtherling. Return it to the battlefield under its owner's control at the beginning of the next end step. - this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new AEherlingRemovingEffect(), new ManaCostsImpl("{U}"))); + this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new ExileReturnToBattlefieldOwnerNextEndStepEffect(), new ManaCostsImpl("{U}"))); // {U}: AEtherling can't be blocked this turn this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new CantBeBlockedSourceEffect(), new ManaCostsImpl("{U}"))); // {1}: AEtherling gets +1/-1 until end of turn. @@ -74,7 +64,7 @@ public class AEtherling extends CardImpl { this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new BoostSourceEffect(-1, 1, Duration.EndOfTurn), new ManaCostsImpl("{1}"))); } - public AEtherling (final AEtherling card) { + public AEtherling(final AEtherling card) { super(card); } @@ -84,40 +74,3 @@ public class AEtherling extends CardImpl { } } -class AEherlingRemovingEffect extends OneShotEffect { - - private static final String effectText = "Exile {this}. Return it to the battlefield under its owner's control at the beginning of the next end step"; - - AEherlingRemovingEffect () { - super(Outcome.Benefit); - staticText = effectText; - } - - AEherlingRemovingEffect(AEherlingRemovingEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = game.getPermanent(source.getSourceId()); - if (permanent != null) { - if (permanent.moveToExile(source.getSourceId(), "AEherling Exile", source.getSourceId(), game)) { - //create delayed triggered ability - AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility( - new ReturnFromExileEffect(source.getSourceId(), Zone.BATTLEFIELD)); - delayedAbility.setSourceId(source.getSourceId()); - delayedAbility.setControllerId(source.getControllerId()); - delayedAbility.setSourceObject(source.getSourceObject(game), game); - game.addDelayedTriggeredAbility(delayedAbility); - return true; - } - } - return false; - } - - @Override - public AEherlingRemovingEffect copy() { - return new AEherlingRemovingEffect(this); - } - -} diff --git a/Mage.Sets/src/mage/sets/gatecrash/Voidwalk.java b/Mage.Sets/src/mage/sets/gatecrash/Voidwalk.java index e23881336e6..1a03b4db210 100644 --- a/Mage.Sets/src/mage/sets/gatecrash/Voidwalk.java +++ b/Mage.Sets/src/mage/sets/gatecrash/Voidwalk.java @@ -28,20 +28,18 @@ package mage.sets.gatecrash; import java.util.UUID; - -import mage.constants.CardType; -import mage.constants.Rarity; import mage.abilities.Ability; import mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.CipherEffect; -import mage.abilities.effects.common.ReturnFromExileEffect; -import mage.cards.Card; +import mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlSourceEffect; import mage.cards.CardImpl; +import mage.constants.CardType; import mage.constants.Outcome; -import mage.constants.Zone; +import mage.constants.Rarity; import mage.game.Game; import mage.game.permanent.Permanent; +import mage.players.Player; import mage.target.common.TargetCreaturePermanent; /** @@ -54,7 +52,6 @@ public class Voidwalk extends CardImpl { super(ownerId, 55, "Voidwalk", Rarity.UNCOMMON, new CardType[]{CardType.SORCERY}, "{3}{U}"); this.expansionSetCode = "GTC"; - // Exile target creature. Return it to the battlefield under its owner's control at the beginning of the next end step. this.getSpellAbility().addEffect(new VoidwalkEffect()); this.getSpellAbility().addTarget(new TargetCreaturePermanent()); @@ -88,21 +85,23 @@ class VoidwalkEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - if (getTargetPointer().getFirst(game, source) != null) { - Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source)); - Card card = game.getCard(getTargetPointer().getFirst(game, source)); - if (permanent != null) { - if (permanent.moveToExile(source.getSourceId(), "Voidwalk", source.getSourceId(), game)) { - if (card != null) { - AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new ReturnFromExileEffect(source.getSourceId(), Zone.BATTLEFIELD)); + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + if (getTargetPointer().getFirst(game, source) != null) { + Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source)); + if (permanent != null) { + int zcc = game.getState().getZoneChangeCounter(permanent.getId()); + if (permanent.moveToExile(null, "", source.getSourceId(), game)) { + AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility( + new ReturnToBattlefieldUnderOwnerControlSourceEffect(false, zcc + 1)); delayedAbility.setSourceId(source.getSourceId()); - delayedAbility.setControllerId(card.getOwnerId()); + delayedAbility.setControllerId(source.getControllerId()); delayedAbility.setSourceObject(source.getSourceObject(game), game); game.addDelayedTriggeredAbility(delayedAbility); - return true; } } } + return true; } return false; } @@ -111,4 +110,4 @@ class VoidwalkEffect extends OneShotEffect { public VoidwalkEffect copy() { return new VoidwalkEffect(this); } -} \ No newline at end of file +} diff --git a/Mage.Sets/src/mage/sets/guildpact/GhostCouncilOfOrzhova.java b/Mage.Sets/src/mage/sets/guildpact/GhostCouncilOfOrzhova.java index 6dc19286a3a..d3e22b9121b 100644 --- a/Mage.Sets/src/mage/sets/guildpact/GhostCouncilOfOrzhova.java +++ b/Mage.Sets/src/mage/sets/guildpact/GhostCouncilOfOrzhova.java @@ -25,26 +25,23 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. */ - package mage.sets.guildpact; 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.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.SimpleActivatedAbility; -import mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility; import mage.abilities.costs.common.SacrificeTargetCost; import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.effects.OneShotEffect; -import mage.abilities.effects.common.ReturnFromExileEffect; +import mage.abilities.effects.common.ExileReturnToBattlefieldOwnerNextEndStepEffect; import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.Rarity; +import mage.constants.Zone; import mage.game.Game; -import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.common.TargetControlledCreaturePermanent; import mage.target.common.TargetOpponent; @@ -55,13 +52,12 @@ import mage.target.common.TargetOpponent; */ public class GhostCouncilOfOrzhova extends CardImpl { - public GhostCouncilOfOrzhova (UUID ownerId) { + public GhostCouncilOfOrzhova(UUID ownerId) { super(ownerId, 114, "Ghost Council of Orzhova", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{W}{W}{B}{B}"); this.expansionSetCode = "GPT"; this.supertype.add("Legendary"); this.subtype.add("Spirit"); - this.power = new MageInt(4); this.toughness = new MageInt(4); @@ -69,14 +65,14 @@ public class GhostCouncilOfOrzhova extends CardImpl { Ability ability = new EntersBattlefieldTriggeredAbility(new GhostCouncilOfOrzhovaEffect()); ability.addTarget(new TargetOpponent()); this.addAbility(ability); - + // {1}, Sacrifice a creature: Exile Ghost Council of Orzhova. Return it to the battlefield under its owner's control at the beginning of the next end step. - ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new GhostCouncilOfOrzhovaRemovingEffect(), new GenericManaCost(1)); + ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new ExileReturnToBattlefieldOwnerNextEndStepEffect(), new GenericManaCost(1)); ability.addCost(new SacrificeTargetCost(new TargetControlledCreaturePermanent())); this.addAbility(ability); } - public GhostCouncilOfOrzhova (final GhostCouncilOfOrzhova card) { + public GhostCouncilOfOrzhova(final GhostCouncilOfOrzhova card) { super(card); } @@ -88,6 +84,7 @@ public class GhostCouncilOfOrzhova extends CardImpl { } class GhostCouncilOfOrzhovaEffect extends OneShotEffect { + GhostCouncilOfOrzhovaEffect() { super(Outcome.Damage); staticText = "target opponent loses 1 life and you gain 1 life"; @@ -114,44 +111,3 @@ class GhostCouncilOfOrzhovaEffect extends OneShotEffect { } } - -class GhostCouncilOfOrzhovaRemovingEffect extends OneShotEffect { - - private static final String effectText = "Exile {this}. Return it to the battlefield under its owner's control at the beginning of the next end step"; - - GhostCouncilOfOrzhovaRemovingEffect () { - super(Outcome.Benefit); - staticText = effectText; - } - - GhostCouncilOfOrzhovaRemovingEffect(GhostCouncilOfOrzhovaRemovingEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - Permanent permanent = game.getPermanent(source.getSourceId()); - if (permanent != null) { - if (controller.moveCardToExileWithInfo(permanent, source.getSourceId(), permanent.getIdName(), source.getSourceId(), game, Zone.BATTLEFIELD, true)) { - //create delayed triggered ability - AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility( - new ReturnFromExileEffect(source.getSourceId(), Zone.BATTLEFIELD)); - delayedAbility.setSourceId(source.getSourceId()); - delayedAbility.setControllerId(source.getControllerId()); - delayedAbility.setSourceObject(source.getSourceObject(game), game); - game.addDelayedTriggeredAbility(delayedAbility); - return true; - } - } - } - return false; - } - - @Override - public GhostCouncilOfOrzhovaRemovingEffect copy() { - return new GhostCouncilOfOrzhovaRemovingEffect(this); - } - -} diff --git a/Mage.Sets/src/mage/sets/planarchaos/FreneticSliver.java b/Mage.Sets/src/mage/sets/planarchaos/FreneticSliver.java index 4098b0f065e..8a0c4422a4b 100644 --- a/Mage.Sets/src/mage/sets/planarchaos/FreneticSliver.java +++ b/Mage.Sets/src/mage/sets/planarchaos/FreneticSliver.java @@ -31,12 +31,11 @@ import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility; import mage.abilities.condition.common.SourceOnBattlefieldCondition; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.decorator.ConditionalActivatedAbility; import mage.abilities.effects.OneShotEffect; -import mage.abilities.effects.common.ReturnFromExileEffect; +import mage.abilities.effects.common.ExileReturnToBattlefieldOwnerNextEndStepEffect; import mage.abilities.effects.common.continuous.GainAbilityAllEffect; import mage.cards.CardImpl; import mage.constants.CardType; @@ -98,19 +97,7 @@ class FreneticSliverEffect extends OneShotEffect { Player player = game.getPlayer(source.getControllerId()); if (player != null) { if (player.flipCoin(game)) { - Permanent perm = game.getPermanent(source.getSourceId()); - if (perm != null) { - UUID exileZoneId = UUID.randomUUID(); - perm.moveToExile(exileZoneId, perm.getName(), source.getSourceId(), game); - // and return it to the battlefield under its owner's control at the beginning of the next end step. - AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility( - new ReturnFromExileEffect(exileZoneId, Zone.BATTLEFIELD)); - delayedAbility.setSourceId(source.getSourceId()); - delayedAbility.setControllerId(source.getControllerId()); - delayedAbility.setSourceObject(source.getSourceObject(game), game); - game.addDelayedTriggeredAbility(delayedAbility); - } - return true; + return new ExileReturnToBattlefieldOwnerNextEndStepEffect().apply(game, source); } else { Permanent perm = game.getPermanent(source.getSourceId()); if (perm != null) { diff --git a/Mage.Sets/src/mage/sets/timespiral/NorinTheWary.java b/Mage.Sets/src/mage/sets/timespiral/NorinTheWary.java index b94593b84ca..b87f928ade1 100644 --- a/Mage.Sets/src/mage/sets/timespiral/NorinTheWary.java +++ b/Mage.Sets/src/mage/sets/timespiral/NorinTheWary.java @@ -29,21 +29,15 @@ package mage.sets.timespiral; import java.util.UUID; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.TriggeredAbilityImpl; -import mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility; -import mage.abilities.effects.OneShotEffect; -import mage.abilities.effects.common.ReturnFromExileEffect; +import mage.abilities.effects.common.ExileReturnToBattlefieldOwnerNextEndStepEffect; import mage.cards.CardImpl; import mage.constants.CardType; -import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; -import mage.game.permanent.Permanent; -import mage.players.Player; /** * @@ -63,7 +57,7 @@ public class NorinTheWary extends CardImpl { // When a player casts a spell or a creature attacks, exile Norin the Wary. Return it to the battlefield under its owner's control at the beginning of the next end step. this.addAbility(new NorinTheWaryTriggeredAbility()); - + } public NorinTheWary(final NorinTheWary card) { @@ -79,7 +73,7 @@ public class NorinTheWary extends CardImpl { class NorinTheWaryTriggeredAbility extends TriggeredAbilityImpl { public NorinTheWaryTriggeredAbility() { - super(Zone.BATTLEFIELD, new NorinTheWaryRemovingEffect(), false); + super(Zone.BATTLEFIELD, new ExileReturnToBattlefieldOwnerNextEndStepEffect(), false); } public NorinTheWaryTriggeredAbility(final NorinTheWaryTriggeredAbility ability) { @@ -107,44 +101,3 @@ class NorinTheWaryTriggeredAbility extends TriggeredAbilityImpl { return new NorinTheWaryTriggeredAbility(this); } } - -class NorinTheWaryRemovingEffect extends OneShotEffect { - - private static final String effectText = "exile {this}. Return it to the battlefield under its owner's control at the beginning of the next end step"; - - NorinTheWaryRemovingEffect () { - super(Outcome.Benefit); - staticText = effectText; - } - - NorinTheWaryRemovingEffect(NorinTheWaryRemovingEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - Permanent permanent = game.getPermanent(source.getSourceId()); - if (permanent != null) { - if (controller.moveCardToExileWithInfo(permanent, source.getSourceId(), permanent.getIdName(), source.getSourceId(), game, Zone.BATTLEFIELD, true)) { - //create delayed triggered ability - AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility( - new ReturnFromExileEffect(source.getSourceId(), Zone.BATTLEFIELD)); - delayedAbility.setSourceId(source.getSourceId()); - delayedAbility.setControllerId(source.getControllerId()); - delayedAbility.setSourceObject(source.getSourceObject(game), game); - game.addDelayedTriggeredAbility(delayedAbility); - } - } - return true; - } - return false; - } - - @Override - public NorinTheWaryRemovingEffect copy() { - return new NorinTheWaryRemovingEffect(this); - } - -} diff --git a/Mage/src/mage/abilities/effects/common/ExileReturnToBattlefieldOwnerNextEndStepEffect.java b/Mage/src/mage/abilities/effects/common/ExileReturnToBattlefieldOwnerNextEndStepEffect.java new file mode 100644 index 00000000000..a49b20fd835 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/ExileReturnToBattlefieldOwnerNextEndStepEffect.java @@ -0,0 +1,83 @@ +/* + * 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.effects.common; + +import mage.abilities.Ability; +import mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility; +import mage.abilities.effects.OneShotEffect; +import mage.constants.Outcome; +import mage.constants.Zone; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; + +/** + * + * @author LevelX2 + */ +public class ExileReturnToBattlefieldOwnerNextEndStepEffect extends OneShotEffect { + + private static final String effectText = "exile {this}. Return it to the battlefield under its owner's control at the beginning of the next end step"; + + public ExileReturnToBattlefieldOwnerNextEndStepEffect() { + super(Outcome.Benefit); + staticText = effectText; + } + + public ExileReturnToBattlefieldOwnerNextEndStepEffect(ExileReturnToBattlefieldOwnerNextEndStepEffect effect) { + super(effect); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + Permanent permanent = game.getPermanent(source.getSourceId()); + if (permanent != null) { + int zcc = game.getState().getZoneChangeCounter(permanent.getId()); + if (controller.moveCardToExileWithInfo(permanent, source.getSourceId(), permanent.getIdName(), source.getSourceId(), game, Zone.BATTLEFIELD, true)) { + //create delayed triggered ability and return it from every public zone he was next moved to + AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility( + new ReturnToBattlefieldUnderOwnerControlSourceEffect(false, zcc + 1)); + delayedAbility.setSourceId(source.getSourceId()); + delayedAbility.setControllerId(source.getControllerId()); + delayedAbility.setSourceObject(source.getSourceObject(game), game); + game.addDelayedTriggeredAbility(delayedAbility); + } + } + return true; + } + return false; + } + + @Override + public ExileReturnToBattlefieldOwnerNextEndStepEffect copy() { + return new ExileReturnToBattlefieldOwnerNextEndStepEffect(this); + } + +} diff --git a/Mage/src/mage/abilities/effects/common/ReturnToBattlefieldUnderOwnerControlSourceEffect.java b/Mage/src/mage/abilities/effects/common/ReturnToBattlefieldUnderOwnerControlSourceEffect.java index fbf111508cf..124d893bc08 100644 --- a/Mage/src/mage/abilities/effects/common/ReturnToBattlefieldUnderOwnerControlSourceEffect.java +++ b/Mage/src/mage/abilities/effects/common/ReturnToBattlefieldUnderOwnerControlSourceEffect.java @@ -25,7 +25,6 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. */ - package mage.abilities.effects.common; import mage.abilities.Ability; @@ -42,20 +41,27 @@ import mage.game.Game; public class ReturnToBattlefieldUnderOwnerControlSourceEffect extends OneShotEffect { private boolean tapped; + private int zoneChangeCounter; public ReturnToBattlefieldUnderOwnerControlSourceEffect() { this(false); } public ReturnToBattlefieldUnderOwnerControlSourceEffect(boolean tapped) { + this(tapped, -1); + } + + public ReturnToBattlefieldUnderOwnerControlSourceEffect(boolean tapped, int zoneChangeCounter) { super(Outcome.Benefit); this.tapped = tapped; - staticText = new StringBuilder("return that card to the battlefield").append(tapped?" tapped":"").append(" under its owner's control").toString(); + this.zoneChangeCounter = zoneChangeCounter; + staticText = new StringBuilder("return that card to the battlefield").append(tapped ? " tapped" : "").append(" under its owner's control").toString(); } public ReturnToBattlefieldUnderOwnerControlSourceEffect(final ReturnToBattlefieldUnderOwnerControlSourceEffect effect) { super(effect); this.tapped = effect.tapped; + this.zoneChangeCounter = effect.zoneChangeCounter; } @Override @@ -67,12 +73,19 @@ public class ReturnToBattlefieldUnderOwnerControlSourceEffect extends OneShotEff public boolean apply(Game game, Ability source) { Card card = game.getCard(source.getSourceId()); if (card != null) { - Zone currentZone = game.getState().getZone(card.getId()); - if (card.putOntoBattlefield(game, currentZone, source.getSourceId(), card.getOwnerId(),tapped)) { - return true; + // return only from public zones + switch (game.getState().getZone(card.getId())) { + case EXILED: + case COMMAND: + case GRAVEYARD: + if (zoneChangeCounter < 0 || game.getState().getZoneChangeCounter(card.getId()) == zoneChangeCounter) { + Zone currentZone = game.getState().getZone(card.getId()); + card.putOntoBattlefield(game, currentZone, source.getSourceId(), card.getOwnerId(), tapped); + } + break; } + return true; } return false; } - }