From e310ede83710c853d4cc876c98b332cd2fecceb5 Mon Sep 17 00:00:00 2001 From: "Alex W. Jackson" Date: Tue, 6 Sep 2022 06:50:01 -0400 Subject: [PATCH] Replace many custom effects with ExileUntilSourceLeavesEffect --- .../mage/cards/a/AlignedHedronNetwork.java | 4 +- .../src/mage/cards/b/BanisherPriest.java | 45 +-------- Mage.Sets/src/mage/cards/b/Banishment.java | 5 +- .../src/mage/cards/c/ChainedToTheRocks.java | 80 ++------------- Mage.Sets/src/mage/cards/c/ColossalWhale.java | 99 ++++--------------- .../src/mage/cards/c/ConstrictingSliver.java | 43 +------- .../src/mage/cards/c/ConsulateCrackdown.java | 3 +- .../src/mage/cards/d/DeputyOfDetention.java | 2 +- .../src/mage/cards/d/DwarvenSeaClan.java | 6 +- .../src/mage/cards/f/FairgroundsWarden.java | 43 +------- Mage.Sets/src/mage/cards/f/FaithUnbroken.java | 45 ++------- .../src/mage/cards/g/GloriousProtector.java | 4 +- .../src/mage/cards/h/HixusPrisonWarden.java | 52 ++-------- Mage.Sets/src/mage/cards/h/HostageTaker.java | 4 +- Mage.Sets/src/mage/cards/i/IsolationZone.java | 39 +------- .../src/mage/cards/l/LagrellaTheMagpie.java | 8 +- .../src/mage/cards/m/MysteriousLimousine.java | 4 +- .../src/mage/cards/q/QuarantineField.java | 45 ++------- .../src/mage/cards/s/SigridGodFavored.java | 43 +------- Mage.Sets/src/mage/cards/s/Silkwrap.java | 40 +------- .../src/mage/cards/s/SuspensionField.java | 44 +-------- .../src/mage/cards/t/TakenosCavalry.java | 8 +- .../cards/y/YannikScavengingSentinel.java | 2 +- .../effects/common/ExileTargetEffect.java | 25 +---- .../TargetAttackingOrBlockingCreature.java | 12 +-- 25 files changed, 101 insertions(+), 604 deletions(-) diff --git a/Mage.Sets/src/mage/cards/a/AlignedHedronNetwork.java b/Mage.Sets/src/mage/cards/a/AlignedHedronNetwork.java index 6658b9c9e5..44f3f17f56 100644 --- a/Mage.Sets/src/mage/cards/a/AlignedHedronNetwork.java +++ b/Mage.Sets/src/mage/cards/a/AlignedHedronNetwork.java @@ -72,11 +72,9 @@ class AlignedHedronNetworkExileEffect extends OneShotEffect { Player controller = game.getPlayer(source.getControllerId()); if (controller == null) { return false;} - Permanent permanent = game.getPermanent(source.getSourceId()); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); if (permanent == null) { return false; } - // If Whale leaves the battlefield before its triggered ability resolves, - // the target creature won't be exiled. Set toExile = new LinkedHashSet<>(game.getBattlefield().getActivePermanents(filter, controller.getId(), source, game)); if (toExile.isEmpty()) { return false; } diff --git a/Mage.Sets/src/mage/cards/b/BanisherPriest.java b/Mage.Sets/src/mage/cards/b/BanisherPriest.java index 76c35eda02..8594c76aae 100644 --- a/Mage.Sets/src/mage/cards/b/BanisherPriest.java +++ b/Mage.Sets/src/mage/cards/b/BanisherPriest.java @@ -1,4 +1,3 @@ - package mage.cards.b; import java.util.UUID; @@ -6,23 +5,17 @@ import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect; -import mage.abilities.effects.common.ExileTargetEffect; +import mage.abilities.effects.common.ExileUntilSourceLeavesEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; import mage.constants.SubType; -import mage.filter.StaticFilters; -import mage.game.Game; -import mage.game.permanent.Permanent; -import mage.target.common.TargetCreaturePermanent; -import mage.util.CardUtil; +import mage.target.common.TargetOpponentsCreaturePermanent; /** * - * @author jeffwadsworth using LevelX2 tech + * @author awjackson */ public final class BanisherPriest extends CardImpl { @@ -34,8 +27,8 @@ public final class BanisherPriest extends CardImpl { this.toughness = new MageInt(2); // When Banisher Priest enters the battlefield, exile target creature an opponent controls until Banisher Priest leaves the battlefield. - Ability ability = new EntersBattlefieldTriggeredAbility(new BanisherPriestExileEffect()); - ability.addTarget(new TargetCreaturePermanent(StaticFilters.FILTER_OPPONENTS_PERMANENT_CREATURE)); + Ability ability = new EntersBattlefieldTriggeredAbility(new ExileUntilSourceLeavesEffect()); + ability.addTarget(new TargetOpponentsCreaturePermanent()); ability.addEffect(new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility())); this.addAbility(ability); } @@ -49,31 +42,3 @@ public final class BanisherPriest extends CardImpl { return new BanisherPriest(this); } } - -class BanisherPriestExileEffect extends OneShotEffect { - - public BanisherPriestExileEffect() { - super(Outcome.Benefit); - this.staticText = "exile target creature an opponent controls until {this} leaves the battlefield. (That creature returns under its owner's control.)"; - } - - public BanisherPriestExileEffect(final BanisherPriestExileEffect effect) { - super(effect); - } - - @Override - public BanisherPriestExileEffect copy() { - return new BanisherPriestExileEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game); - // If Banisher Priest leaves the battlefield before its triggered ability resolves, - // the target creature won't be exiled. - if (permanent != null) { - return new ExileTargetEffect(CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()), permanent.getIdName()).apply(game, source); - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/b/Banishment.java b/Mage.Sets/src/mage/cards/b/Banishment.java index 93ff0c997a..0eec3d2f04 100644 --- a/Mage.Sets/src/mage/cards/b/Banishment.java +++ b/Mage.Sets/src/mage/cards/b/Banishment.java @@ -78,7 +78,7 @@ class BanishmentEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - Permanent permanent = game.getPermanent(source.getSourceId()); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); Permanent targeted = game.getPermanent(source.getFirstTarget()); if (permanent == null || controller == null || targeted == null) { @@ -103,5 +103,4 @@ class BanishmentEffect extends OneShotEffect { public BanishmentEffect copy() { return new BanishmentEffect(this); } - -} \ No newline at end of file +} diff --git a/Mage.Sets/src/mage/cards/c/ChainedToTheRocks.java b/Mage.Sets/src/mage/cards/c/ChainedToTheRocks.java index 8d5f55731b..879ebaee49 100644 --- a/Mage.Sets/src/mage/cards/c/ChainedToTheRocks.java +++ b/Mage.Sets/src/mage/cards/c/ChainedToTheRocks.java @@ -1,66 +1,29 @@ - package mage.cards.c; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.AttachEffect; import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect; -import mage.abilities.effects.common.ExileTargetEffect; +import mage.abilities.effects.common.ExileUntilSourceLeavesEffect; import mage.abilities.keyword.EnchantAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.SubType; -import mage.filter.StaticFilters; +import mage.filter.FilterPermanent; import mage.filter.common.FilterControlledLandPermanent; -import mage.game.Game; -import mage.game.permanent.Permanent; import mage.target.TargetPermanent; -import mage.target.common.TargetCreaturePermanent; -import mage.util.CardUtil; +import mage.target.common.TargetOpponentsCreaturePermanent; /** - * If the land Chained to the Rocks is enchanting stops being a Mountain or - * another player gains control of it, Chained to the Rocks will be put into its - * owner's graveyard when state-based actions are performed. - * - * Chained to the Rocks's ability causes a zone change with a duration, a style - * of ability introduced in Magic 2014 that's somewhat reminiscent of older - * cards like Oblivion Ring. However, unlike Oblivion Ring, cards like Chained - * to the Rocks have a single ability that creates two one-shot effects: one - * that exiles the creature when the ability resolves, and another that returns - * the exiled card to the battlefield immediately after Chained to the Rocks - * leaves the battlefield. - * - * If Chained to the Rocks leaves the battlefield before its triggered ability - * resolves, the target creature won't be exiled. - * - * Auras attached to the exiled creature will be put into their owners' - * graveyards (unless they have bestow). Equipment attached to the exiled - * creature will become unattached and remain on the battlefield. Any counters - * on the exiled creature will cease to exist. - * - * If a creature token is exiled, it ceases to exist. It won't be returned to - * the battlefield. - * - * The exiled card returns to the battlefield immediately after Chained to the - * Rocks leaves the battlefield. Nothing happens between the two events, - * including state-based actions. - * - * In a multiplayer game, if Chained to the Rocks's owner leaves the game, the - * exiled card will return to the battlefield. Because the one-shot effect that - * returns the card isn't an ability that goes on the stack, it won't cease to - * exist along with the leaving player's spells and abilities on the stack. - * - * @author LevelX2 + * @author awjackson */ public final class ChainedToTheRocks extends CardImpl { - private static final FilterControlledLandPermanent filter = new FilterControlledLandPermanent("Mountain you control"); + private static final FilterPermanent filter = new FilterControlledLandPermanent("Mountain you control"); static { filter.add(SubType.MOUNTAIN.getPredicate()); @@ -78,11 +41,10 @@ public final class ChainedToTheRocks extends CardImpl { this.addAbility(ability); // When Chained to the Rocks enters the battlefield, exile target creature an opponent controls until Chained to the Rocks leaves the battlefield. (That creature returns under its owner's control.) - ability = new EntersBattlefieldTriggeredAbility(new ChainedToTheRocksEffect()); - ability.addTarget(new TargetCreaturePermanent(StaticFilters.FILTER_OPPONENTS_PERMANENT_CREATURE)); + ability = new EntersBattlefieldTriggeredAbility(new ExileUntilSourceLeavesEffect()); + ability.addTarget(new TargetOpponentsCreaturePermanent()); ability.addEffect(new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility())); this.addAbility(ability); - } private ChainedToTheRocks(final ChainedToTheRocks card) { @@ -94,31 +56,3 @@ public final class ChainedToTheRocks extends CardImpl { return new ChainedToTheRocks(this); } } - -class ChainedToTheRocksEffect extends OneShotEffect { - - public ChainedToTheRocksEffect() { - super(Outcome.Benefit); - this.staticText = "exile target creature an opponent controls until {this} leaves the battlefield. (That creature returns under its owner's control.)"; - } - - public ChainedToTheRocksEffect(final ChainedToTheRocksEffect effect) { - super(effect); - } - - @Override - public ChainedToTheRocksEffect copy() { - return new ChainedToTheRocksEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = game.getPermanent(source.getSourceId()); - // If Chained to the Rocks leaves the battlefield before its triggered ability resolves, - // the target creature won't be exiled. - if (permanent != null) { - return new ExileTargetEffect(CardUtil.getCardExileZoneId(game, source), permanent.getIdName()).apply(game, source); - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/c/ColossalWhale.java b/Mage.Sets/src/mage/cards/c/ColossalWhale.java index fd9c9d50b5..cdffc0cff6 100644 --- a/Mage.Sets/src/mage/cards/c/ColossalWhale.java +++ b/Mage.Sets/src/mage/cards/c/ColossalWhale.java @@ -1,36 +1,34 @@ - package mage.cards.c; import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; -import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.AttacksTriggeredAbility; import mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect; -import mage.abilities.effects.common.ExileTargetEffect; +import mage.abilities.effects.common.ExileUntilSourceLeavesEffect; import mage.abilities.keyword.IslandwalkAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; -import mage.constants.Outcome; -import mage.constants.Zone; +import mage.filter.FilterPermanent; import mage.filter.common.FilterCreaturePermanent; -import mage.filter.predicate.permanent.ControllerIdPredicate; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; -import mage.game.permanent.Permanent; -import mage.target.common.TargetCreaturePermanent; -import mage.util.CardUtil; +import mage.filter.predicate.permanent.DefendingPlayerControlsPredicate; +import mage.target.TargetPermanent; /** * - * @author LevelX2 + * @author awjackson */ public final class ColossalWhale extends CardImpl { + private static final FilterPermanent filter = new FilterCreaturePermanent("creature defending player controls"); + + static { + filter.add(DefendingPlayerControlsPredicate.instance); + } + public ColossalWhale(UUID ownerId, CardSetInfo setInfo) { super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{5}{U}{U}"); this.subtype.add(SubType.WHALE); @@ -40,8 +38,12 @@ public final class ColossalWhale extends CardImpl { // Islandwalk this.addAbility(new IslandwalkAbility()); + // Whenever Colossal Whale attacks, you may exile target creature defending player controls until Colossal Whale leaves the battlefield. - this.addAbility(new ColossalWhaleAbility()); + Ability ability = new AttacksTriggeredAbility(new ExileUntilSourceLeavesEffect(), true); + ability.addTarget(new TargetPermanent(filter)); + ability.addEffect(new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility())); + this.addAbility(ability); } @@ -54,70 +56,3 @@ public final class ColossalWhale extends CardImpl { return new ColossalWhale(this); } } - -class ColossalWhaleAbility extends TriggeredAbilityImpl { - - public ColossalWhaleAbility() { - super(Zone.BATTLEFIELD, null); - this.addEffect(new ColossalWhaleExileEffect()); - this.addEffect(new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility())); - setTriggerPhrase("Whenever {this} attacks, "); - } - - public ColossalWhaleAbility(final ColossalWhaleAbility ability) { - super(ability); - } - - @Override - public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.ATTACKER_DECLARED; - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - if (event.getSourceId().equals(this.getSourceId())) { - FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls"); - UUID defenderId = game.getCombat().getDefenderId(sourceId); - filter.add(new ControllerIdPredicate(defenderId)); - - this.getTargets().clear(); - TargetCreaturePermanent target = new TargetCreaturePermanent(filter); - this.addTarget(target); - return true; - } - return false; - } - - @Override - public ColossalWhaleAbility copy() { - return new ColossalWhaleAbility(this); - } -} - -class ColossalWhaleExileEffect extends OneShotEffect { - - public ColossalWhaleExileEffect() { - super(Outcome.Benefit); - this.staticText = "you may exile target creature defending player controls until {this} leaves the battlefield"; - } - - public ColossalWhaleExileEffect(final ColossalWhaleExileEffect effect) { - super(effect); - } - - @Override - public ColossalWhaleExileEffect copy() { - return new ColossalWhaleExileEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = game.getPermanent(source.getSourceId()); - // If Whale leaves the battlefield before its triggered ability resolves, - // the target creature won't be exiled. - if (permanent != null) { - return new ExileTargetEffect(CardUtil.getCardExileZoneId(game, source), permanent.getIdName()).apply(game, source); - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/c/ConstrictingSliver.java b/Mage.Sets/src/mage/cards/c/ConstrictingSliver.java index 4d352e5fda..727dbf7a72 100644 --- a/Mage.Sets/src/mage/cards/c/ConstrictingSliver.java +++ b/Mage.Sets/src/mage/cards/c/ConstrictingSliver.java @@ -6,22 +6,18 @@ import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect; -import mage.abilities.effects.common.ExileTargetEffect; +import mage.abilities.effects.common.ExileUntilSourceLeavesEffect; import mage.abilities.effects.common.continuous.GainAbilityControlledEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.*; import mage.filter.StaticFilters; -import mage.game.Game; -import mage.game.permanent.Permanent; -import mage.target.common.TargetCreaturePermanent; -import mage.util.CardUtil; +import mage.target.common.TargetOpponentsCreaturePermanent; /** * - * @author LevelX2 + * @author awjackson */ public final class ConstrictingSliver extends CardImpl { @@ -34,15 +30,14 @@ public final class ConstrictingSliver extends CardImpl { // Sliver creatures you control have "When this creature enters the battlefield, you may exile target creature an opponent controls // until this creature leaves the battlefield." - Ability ability = new EntersBattlefieldTriggeredAbility(new ConstrictingSliverExileEffect(), true); - ability.addTarget(new TargetCreaturePermanent(StaticFilters.FILTER_OPPONENTS_PERMANENT_CREATURE)); + Ability ability = new EntersBattlefieldTriggeredAbility(new ExileUntilSourceLeavesEffect(), true); + ability.addTarget(new TargetOpponentsCreaturePermanent()); ability.addEffect(new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility())); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityControlledEffect(ability, Duration.WhileOnBattlefield, StaticFilters.FILTER_PERMANENT_ALL_SLIVERS) .setText("Sliver creatures you control have \"When this creature enters the battlefield, " + "you may exile target creature an opponent controls until this creature leaves the battlefield.\""))); - } private ConstrictingSliver(final ConstrictingSliver card) { @@ -54,31 +49,3 @@ public final class ConstrictingSliver extends CardImpl { return new ConstrictingSliver(this); } } - -class ConstrictingSliverExileEffect extends OneShotEffect { - - public ConstrictingSliverExileEffect() { - super(Outcome.Benefit); - this.staticText = "you may exile target creature an opponent controls until this creature leaves the battlefield"; - } - - public ConstrictingSliverExileEffect(final ConstrictingSliverExileEffect effect) { - super(effect); - } - - @Override - public ConstrictingSliverExileEffect copy() { - return new ConstrictingSliverExileEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = game.getPermanent(source.getSourceId()); - // If the creature leaves the battlefield before its triggered ability resolves, - // the target creature won't be exiled. - if (permanent != null) { - return new ExileTargetEffect(CardUtil.getCardExileZoneId(game, source), permanent.getIdName()).apply(game, source); - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/c/ConsulateCrackdown.java b/Mage.Sets/src/mage/cards/c/ConsulateCrackdown.java index 6c14e19e5c..4439718ea6 100644 --- a/Mage.Sets/src/mage/cards/c/ConsulateCrackdown.java +++ b/Mage.Sets/src/mage/cards/c/ConsulateCrackdown.java @@ -64,7 +64,7 @@ class ConsulateCracksownExileEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - Permanent permanent = game.getPermanent(source.getSourceId()); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); //If the permanent leaves the battlefield before the ability resolves, artifacts won't be exiled. if (permanent == null || controller == null) return false; @@ -86,5 +86,4 @@ class ConsulateCracksownExileEffect extends OneShotEffect { public ConsulateCracksownExileEffect copy() { return new ConsulateCracksownExileEffect(this); } - } diff --git a/Mage.Sets/src/mage/cards/d/DeputyOfDetention.java b/Mage.Sets/src/mage/cards/d/DeputyOfDetention.java index 700ecf8eba..a9908d8f4c 100644 --- a/Mage.Sets/src/mage/cards/d/DeputyOfDetention.java +++ b/Mage.Sets/src/mage/cards/d/DeputyOfDetention.java @@ -78,7 +78,7 @@ class DeputyOfDetentionExileEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - Permanent permanent = game.getPermanent(source.getSourceId()); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); Permanent targeted = game.getPermanent(source.getFirstTarget()); if (permanent == null || controller == null || targeted == null) { diff --git a/Mage.Sets/src/mage/cards/d/DwarvenSeaClan.java b/Mage.Sets/src/mage/cards/d/DwarvenSeaClan.java index d831766e91..4f0c91b700 100644 --- a/Mage.Sets/src/mage/cards/d/DwarvenSeaClan.java +++ b/Mage.Sets/src/mage/cards/d/DwarvenSeaClan.java @@ -19,7 +19,7 @@ import mage.constants.Zone; import mage.filter.common.FilterAttackingOrBlockingCreature; import mage.filter.predicate.permanent.ControllerControlsIslandPredicate; import mage.game.Game; -import mage.target.common.TargetAttackingOrBlockingCreature; +import mage.target.TargetPermanent; /** * @@ -49,7 +49,7 @@ public final class DwarvenSeaClan extends CardImpl { new TapSourceCost(), BeforeEndCombatCondition.getInstance() ); - ability.addTarget(new TargetAttackingOrBlockingCreature(1, 1, filter, false)); + ability.addTarget(new TargetPermanent(filter)); addAbility(ability); } @@ -83,4 +83,4 @@ class BeforeEndCombatCondition implements Condition { public String toString() { return "before the end of combat step"; } -} \ No newline at end of file +} diff --git a/Mage.Sets/src/mage/cards/f/FairgroundsWarden.java b/Mage.Sets/src/mage/cards/f/FairgroundsWarden.java index e72a22e532..2c156fa09d 100644 --- a/Mage.Sets/src/mage/cards/f/FairgroundsWarden.java +++ b/Mage.Sets/src/mage/cards/f/FairgroundsWarden.java @@ -1,4 +1,3 @@ - package mage.cards.f; import java.util.UUID; @@ -6,19 +5,13 @@ import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect; -import mage.abilities.effects.common.ExileTargetEffect; +import mage.abilities.effects.common.ExileUntilSourceLeavesEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; -import mage.constants.Outcome; -import mage.filter.StaticFilters; -import mage.game.Game; -import mage.game.permanent.Permanent; -import mage.target.common.TargetCreaturePermanent; -import mage.util.CardUtil; +import mage.target.common.TargetOpponentsCreaturePermanent; /** * @@ -34,8 +27,8 @@ public final class FairgroundsWarden extends CardImpl { this.toughness = new MageInt(3); // When Fairgrounds Warden enters the battlefield, exile target creature an opponent controls until Fairgrounds Warden leaves the battlefield. - Ability ability = new EntersBattlefieldTriggeredAbility(new FairsgroundsWardenExileEffect()); - ability.addTarget(new TargetCreaturePermanent(StaticFilters.FILTER_OPPONENTS_PERMANENT_CREATURE)); + Ability ability = new EntersBattlefieldTriggeredAbility(new ExileUntilSourceLeavesEffect()); + ability.addTarget(new TargetOpponentsCreaturePermanent()); ability.addEffect(new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility())); this.addAbility(ability); } @@ -49,31 +42,3 @@ public final class FairgroundsWarden extends CardImpl { return new FairgroundsWarden(this); } } - -class FairsgroundsWardenExileEffect extends OneShotEffect { - - public FairsgroundsWardenExileEffect() { - super(Outcome.Benefit); - this.staticText = "exile target creature an opponent controls until {this} leaves the battlefield."; - } - - public FairsgroundsWardenExileEffect(final FairsgroundsWardenExileEffect effect) { - super(effect); - } - - @Override - public FairsgroundsWardenExileEffect copy() { - return new FairsgroundsWardenExileEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game); - // If Fairsgrounds Warden leaves the battlefield before its triggered ability resolves, - // the target creature won't be exiled. - if (permanent != null) { - return new ExileTargetEffect(CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()), permanent.getIdName()).apply(game, source); - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/f/FaithUnbroken.java b/Mage.Sets/src/mage/cards/f/FaithUnbroken.java index fb99686d4a..589510cfdd 100644 --- a/Mage.Sets/src/mage/cards/f/FaithUnbroken.java +++ b/Mage.Sets/src/mage/cards/f/FaithUnbroken.java @@ -1,4 +1,3 @@ - package mage.cards.f; import java.util.UUID; @@ -9,23 +8,19 @@ import mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.AttachEffect; import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect; -import mage.abilities.effects.common.ExileTargetEffect; +import mage.abilities.effects.common.ExileUntilSourceLeavesEffect; import mage.abilities.effects.common.continuous.BoostEnchantedEffect; import mage.abilities.keyword.EnchantAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.*; -import mage.filter.StaticFilters; -import mage.game.Game; -import mage.game.permanent.Permanent; import mage.target.TargetPermanent; import mage.target.common.TargetControlledCreaturePermanent; -import mage.target.common.TargetCreaturePermanent; -import mage.util.CardUtil; +import mage.target.common.TargetOpponentsCreaturePermanent; /** * - * @author LevelX2 + * @author awjackson */ public final class FaithUnbroken extends CardImpl { @@ -41,13 +36,13 @@ public final class FaithUnbroken extends CardImpl { this.addAbility(ability); // When Faith Unbroken enters the battlefield, exile target creature an opponent controls until Faith Unbroken leaves the battlefield. - ability = new EntersBattlefieldTriggeredAbility(new FaithUnbrokenEffect()); - ability.addTarget(new TargetCreaturePermanent(StaticFilters.FILTER_OPPONENTS_PERMANENT_CREATURE)); + ability = new EntersBattlefieldTriggeredAbility(new ExileUntilSourceLeavesEffect()); + ability.addTarget(new TargetOpponentsCreaturePermanent()); ability.addEffect(new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility())); this.addAbility(ability); // Enchanted creature gets +2/+2. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostEnchantedEffect(2, 2, Duration.WhileOnBattlefield))); + this.addAbility(new SimpleStaticAbility(new BoostEnchantedEffect(2, 2, Duration.WhileOnBattlefield))); } private FaithUnbroken(final FaithUnbroken card) { @@ -59,31 +54,3 @@ public final class FaithUnbroken extends CardImpl { return new FaithUnbroken(this); } } - -class FaithUnbrokenEffect extends OneShotEffect { - - public FaithUnbrokenEffect() { - super(Outcome.Benefit); - this.staticText = "exile target creature an opponent controls until {this} leaves the battlefield"; - } - - public FaithUnbrokenEffect(final FaithUnbrokenEffect effect) { - super(effect); - } - - @Override - public FaithUnbrokenEffect copy() { - return new FaithUnbrokenEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = game.getPermanent(source.getSourceId()); - // If Chained to the Rocks leaves the battlefield before its triggered ability resolves, - // the target creature won't be exiled. - if (permanent != null) { - return new ExileTargetEffect(CardUtil.getCardExileZoneId(game, source), permanent.getIdName()).apply(game, source); - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/g/GloriousProtector.java b/Mage.Sets/src/mage/cards/g/GloriousProtector.java index bdc56b54e0..d5ee8068c5 100644 --- a/Mage.Sets/src/mage/cards/g/GloriousProtector.java +++ b/Mage.Sets/src/mage/cards/g/GloriousProtector.java @@ -1,7 +1,6 @@ package mage.cards.g; import mage.MageInt; -import mage.MageObject; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility; @@ -20,6 +19,7 @@ import mage.filter.FilterPermanent; import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.predicate.Predicates; import mage.game.Game; +import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.TargetPermanent; import mage.util.CardUtil; @@ -90,7 +90,7 @@ class GloriousProtectorEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); - MageObject sourceObject = source.getSourceObject(game); + Permanent sourceObject = source.getSourcePermanentIfItStillExists(game); if (player == null || sourceObject == null) { return false; } diff --git a/Mage.Sets/src/mage/cards/h/HixusPrisonWarden.java b/Mage.Sets/src/mage/cards/h/HixusPrisonWarden.java index a100d064ff..77fad77158 100644 --- a/Mage.Sets/src/mage/cards/h/HixusPrisonWarden.java +++ b/Mage.Sets/src/mage/cards/h/HixusPrisonWarden.java @@ -1,4 +1,3 @@ - package mage.cards.h; import java.util.UUID; @@ -7,16 +6,13 @@ import mage.MageObject; import mage.abilities.Ability; import mage.abilities.TriggeredAbilityImpl; import mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility; -import mage.abilities.effects.Effect; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect; -import mage.abilities.effects.common.ExileTargetEffect; +import mage.abilities.effects.common.ExileUntilSourceLeavesEffect; import mage.abilities.keyword.FlashAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; -import mage.constants.Outcome; import mage.constants.SuperType; import mage.constants.Zone; import mage.game.Game; @@ -24,7 +20,6 @@ import mage.game.events.DamagedPlayerEvent; import mage.game.events.GameEvent; import mage.game.permanent.Permanent; import mage.target.targetpointer.FixedTarget; -import mage.util.CardUtil; /** * @@ -44,7 +39,7 @@ public final class HixusPrisonWarden extends CardImpl { this.addAbility(FlashAbility.getInstance()); // Whenever a creature deals combat damage to you, if Hixus, Prison Warden entered the battlefield this turn, exile that creature until Hixus leaves the battlefield. - this.addAbility(new HixusPrisonWardenTriggeredAbility(new HixusPrisonWardenExileEffect())); + this.addAbility(new HixusPrisonWardenTriggeredAbility()); } private HixusPrisonWarden(final HixusPrisonWarden card) { @@ -59,9 +54,10 @@ public final class HixusPrisonWarden extends CardImpl { class HixusPrisonWardenTriggeredAbility extends TriggeredAbilityImpl { - public HixusPrisonWardenTriggeredAbility(Effect effect) { - super(Zone.BATTLEFIELD, effect); - this.addEffect(new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility())); + public HixusPrisonWardenTriggeredAbility() { + super(Zone.BATTLEFIELD, new ExileUntilSourceLeavesEffect()); + addEffect(new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility())); + setTriggerPhrase("Whenever a creature deals combat damage to you, if {this} entered the battlefield this turn, "); } public HixusPrisonWardenTriggeredAbility(final HixusPrisonWardenTriggeredAbility ability) { @@ -97,40 +93,4 @@ class HixusPrisonWardenTriggeredAbility extends TriggeredAbilityImpl { } return false; } - - @Override - public String getRule() { - return "Whenever a creature deals combat damage to you, if {this} entered the battlefield this turn, exile that creature until {this} leaves the battlefield."; - } - -} - -class HixusPrisonWardenExileEffect extends OneShotEffect { - - public HixusPrisonWardenExileEffect() { - super(Outcome.Benefit); - this.staticText = "exile that creature until {this} leaves the battlefield"; - } - - public HixusPrisonWardenExileEffect(final HixusPrisonWardenExileEffect effect) { - super(effect); - } - - @Override - public HixusPrisonWardenExileEffect copy() { - return new HixusPrisonWardenExileEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game); - // If Prison Warden leaves the battlefield before its triggered ability resolves, - // the target creature won't be exiled. - if (permanent != null) { - Effect effect = new ExileTargetEffect(CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()), permanent.getIdName()); - effect.setTargetPointer(getTargetPointer()); - return effect.apply(game, source); - } - return false; - } } diff --git a/Mage.Sets/src/mage/cards/h/HostageTaker.java b/Mage.Sets/src/mage/cards/h/HostageTaker.java index 73803f2413..e170e5f982 100644 --- a/Mage.Sets/src/mage/cards/h/HostageTaker.java +++ b/Mage.Sets/src/mage/cards/h/HostageTaker.java @@ -81,7 +81,7 @@ class HostageTakerExileEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Permanent card = game.getPermanent(getTargetPointer().getFirst(game, source)); - Permanent permanent = game.getPermanent(source.getSourceId()); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); if (permanent == null || card == null) { return false; } @@ -96,4 +96,4 @@ class HostageTakerExileEffect extends OneShotEffect { CardUtil.makeCardPlayable(game, source, card, Duration.Custom, true); return true; } -} \ No newline at end of file +} diff --git a/Mage.Sets/src/mage/cards/i/IsolationZone.java b/Mage.Sets/src/mage/cards/i/IsolationZone.java index d79d5b29b4..a833eb5efe 100644 --- a/Mage.Sets/src/mage/cards/i/IsolationZone.java +++ b/Mage.Sets/src/mage/cards/i/IsolationZone.java @@ -5,24 +5,19 @@ import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect; -import mage.abilities.effects.common.ExileTargetEffect; +import mage.abilities.effects.common.ExileUntilSourceLeavesEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; import mage.constants.TargetController; import mage.filter.FilterPermanent; import mage.filter.predicate.Predicates; -import mage.game.Game; -import mage.game.permanent.Permanent; import mage.target.TargetPermanent; -import mage.util.CardUtil; /** * - * @author fireshoes + * @author awjackson */ public final class IsolationZone extends CardImpl { @@ -38,7 +33,7 @@ public final class IsolationZone extends CardImpl { super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{2}{W}{W}"); // When Isolation Zone enters the battlefield, exile target creature or enchantment an opponent controls until Isolation Zone leaves the battlefield. - Ability ability = new EntersBattlefieldTriggeredAbility(new IsolationZoneExileEffect()); + Ability ability = new EntersBattlefieldTriggeredAbility(new ExileUntilSourceLeavesEffect()); ability.addTarget(new TargetPermanent(filter)); ability.addEffect(new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility())); this.addAbility(ability); @@ -53,31 +48,3 @@ public final class IsolationZone extends CardImpl { return new IsolationZone(this); } } - -class IsolationZoneExileEffect extends OneShotEffect { - - public IsolationZoneExileEffect() { - super(Outcome.Benefit); - this.staticText = "exile target creature or enchantment an opponent controls until {this} leaves the battlefield"; - } - - public IsolationZoneExileEffect(final IsolationZoneExileEffect effect) { - super(effect); - } - - @Override - public IsolationZoneExileEffect copy() { - return new IsolationZoneExileEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = game.getPermanent(source.getSourceId()); - // If Stasis Snare leaves the battlefield before its triggered ability resolves, - // the target won't be exiled. - if (permanent != null) { - return new ExileTargetEffect(CardUtil.getCardExileZoneId(game, source), permanent.getIdName()).apply(game, source); - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/l/LagrellaTheMagpie.java b/Mage.Sets/src/mage/cards/l/LagrellaTheMagpie.java index 1a9c3627e7..df4b723d00 100644 --- a/Mage.Sets/src/mage/cards/l/LagrellaTheMagpie.java +++ b/Mage.Sets/src/mage/cards/l/LagrellaTheMagpie.java @@ -66,7 +66,7 @@ public final class LagrellaTheMagpie extends CardImpl { class LagrellaTheMagpieEffect extends OneShotEffect { LagrellaTheMagpieEffect() { - super(Outcome.Benefit); + super(Outcome.Exile); staticText = "exile any number of other target creatures controlled by different players " + "until {this} leaves the battlefield. When an exiled card enters the battlefield " + "under your control this way, put two +1/+1 counters on it"; @@ -84,11 +84,7 @@ class LagrellaTheMagpieEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); - if (player == null) { - return false; - } - // Like other Banishing Light effects, no permanents get exiled if Lagrella is not in the battlefield when this ability resolves. - if (game.getPermanent(source.getSourceId()) == null) { + if (player == null || source.getSourcePermanentIfItStillExists(game) == null) { return false; } diff --git a/Mage.Sets/src/mage/cards/m/MysteriousLimousine.java b/Mage.Sets/src/mage/cards/m/MysteriousLimousine.java index e266bf2d23..7236d32dbb 100644 --- a/Mage.Sets/src/mage/cards/m/MysteriousLimousine.java +++ b/Mage.Sets/src/mage/cards/m/MysteriousLimousine.java @@ -68,7 +68,7 @@ public final class MysteriousLimousine extends CardImpl { class MysteriousLimousineEffect extends OneShotEffect { MysteriousLimousineEffect() { - super(Outcome.Benefit); + super(Outcome.Exile); staticText = "exile up to one other target creature until {this} leaves the battlefield. " + "If a creature is put into exile this way, return each other card exiled " + "with {this} to the battlefield under its owner's control"; @@ -87,7 +87,7 @@ class MysteriousLimousineEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source)); - if (player == null || permanent == null) { + if (player == null || permanent == null || source.getSourcePermanentIfItStillExists(game) == null) { return false; } UUID exileId = CardUtil.getExileZoneId(game, source); diff --git a/Mage.Sets/src/mage/cards/q/QuarantineField.java b/Mage.Sets/src/mage/cards/q/QuarantineField.java index 4191184dd4..1b27e49a86 100644 --- a/Mage.Sets/src/mage/cards/q/QuarantineField.java +++ b/Mage.Sets/src/mage/cards/q/QuarantineField.java @@ -5,14 +5,12 @@ import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldAbility; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect; import mage.abilities.effects.common.EntersBattlefieldWithXCountersEffect; -import mage.abilities.effects.common.ExileTargetEffect; +import mage.abilities.effects.common.ExileUntilSourceLeavesEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; import mage.constants.TargetController; import mage.counters.CounterType; import mage.filter.common.FilterNonlandPermanent; @@ -20,12 +18,11 @@ import mage.game.Game; import mage.game.permanent.Permanent; import mage.target.TargetPermanent; import mage.target.targetadjustment.TargetAdjuster; -import mage.util.CardUtil; import java.util.UUID; /** - * @author LevelX2 + * @author awjackson */ public final class QuarantineField extends CardImpl { @@ -36,7 +33,9 @@ public final class QuarantineField extends CardImpl { this.addAbility(new EntersBattlefieldAbility(new EntersBattlefieldWithXCountersEffect(CounterType.ISOLATION.createInstance()))); // When Quarantine Field enters the battlefield, for each isolation counter on it, exile up to one target nonland permanent an opponent controls until Quarantine Field leaves the battlefield. - Ability ability = new EntersBattlefieldTriggeredAbility(new QuarantineFieldEffect(), false); + Ability ability = new EntersBattlefieldTriggeredAbility(new ExileUntilSourceLeavesEffect() + .setText("for each isolation counter on it, exile up to one target nonland permanent an opponent controls until {this} leaves the battlefield") + ); ability.addEffect(new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility())); ability.setTargetAdjuster(QuarantineFieldAdjuster.instance); this.addAbility(ability); @@ -59,38 +58,10 @@ enum QuarantineFieldAdjuster implements TargetAdjuster { public void adjustTargets(Ability ability, Game game) { Permanent sourceObject = game.getPermanent(ability.getSourceId()); if (sourceObject != null) { - int isolationCounters = sourceObject.getCounters(game).getCount(CounterType.ISOLATION); - FilterNonlandPermanent filter = new FilterNonlandPermanent("up to " + isolationCounters + " nonland permanents controlled by an opponent"); + int counters = sourceObject.getCounters(game).getCount(CounterType.ISOLATION); + FilterNonlandPermanent filter = new FilterNonlandPermanent("nonland permanent" + (counters > 1 ? "s" : "") + " an opponent controls"); filter.add(TargetController.OPPONENT.getControllerPredicate()); - ability.addTarget(new TargetPermanent(0, isolationCounters, filter, false)); + ability.addTarget(new TargetPermanent(0, counters, filter)); } } } - -class QuarantineFieldEffect extends OneShotEffect { - - public QuarantineFieldEffect() { - super(Outcome.Exile); - this.staticText = "for each isolation counter on it, exile up to one target nonland permanent an opponent controls until {this} leaves the battlefield"; - } - - public QuarantineFieldEffect(final QuarantineFieldEffect effect) { - super(effect); - } - - @Override - public QuarantineFieldEffect copy() { - return new QuarantineFieldEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = game.getPermanent(source.getSourceId()); - // If the source permanent leaves the battlefield before its triggered ability resolves, - // the targets won't be exiled. - if (permanent != null) { - return new ExileTargetEffect(CardUtil.getCardExileZoneId(game, source), permanent.getIdName()).apply(game, source); - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/s/SigridGodFavored.java b/Mage.Sets/src/mage/cards/s/SigridGodFavored.java index b13d2b72fc..25aa1ad476 100644 --- a/Mage.Sets/src/mage/cards/s/SigridGodFavored.java +++ b/Mage.Sets/src/mage/cards/s/SigridGodFavored.java @@ -4,30 +4,24 @@ import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect; -import mage.abilities.effects.common.ExileTargetEffect; +import mage.abilities.effects.common.ExileUntilSourceLeavesEffect; import mage.abilities.keyword.FirstStrikeAbility; import mage.abilities.keyword.FlashAbility; import mage.abilities.keyword.ProtectionAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; import mage.constants.SubType; import mage.constants.SuperType; -import mage.filter.common.FilterAttackingOrBlockingCreature; import mage.filter.common.FilterCreaturePermanent; -import mage.game.Game; -import mage.game.permanent.Permanent; -import mage.target.TargetPermanent; -import mage.util.CardUtil; +import mage.target.common.TargetAttackingOrBlockingCreature; import java.util.UUID; /** * - * @author ciaccona007 + * @author awjackson */ public final class SigridGodFavored extends CardImpl { @@ -55,8 +49,8 @@ public final class SigridGodFavored extends CardImpl { this.addAbility(new ProtectionAbility(filterGod)); // When Sigrid, God-Favored enters the battlefield, exile up to one target attacking or blocking creature until Sigrid leaves the battlefield. - Ability ability = new EntersBattlefieldTriggeredAbility(new SigridGodFavoredExileEffect()); - ability.addTarget(new TargetPermanent(0,1,new FilterAttackingOrBlockingCreature(), false)); + Ability ability = new EntersBattlefieldTriggeredAbility(new ExileUntilSourceLeavesEffect()); + ability.addTarget(new TargetAttackingOrBlockingCreature(0, 1)); ability.addEffect(new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility())); this.addAbility(ability); } @@ -70,30 +64,3 @@ public final class SigridGodFavored extends CardImpl { return new SigridGodFavored(this); } } - -class SigridGodFavoredExileEffect extends OneShotEffect { - - SigridGodFavoredExileEffect() { - super(Outcome.Exile); - this.staticText = "exile up to one target attacking or blocking creature until {this} leaves the battlefield. (That creature returns under its owner's control.)"; - } - - SigridGodFavoredExileEffect(final SigridGodFavoredExileEffect effect) { - super(effect); - } - - @Override - public SigridGodFavoredExileEffect copy() { - return new SigridGodFavoredExileEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent sourcePermanent = game.getPermanent(source.getSourceId()); - // If Sigrid, God-Favored leaves the battlefield before its triggered ability resolves, the target won't be exiled. - if (sourcePermanent != null) { - return new ExileTargetEffect(CardUtil.getCardExileZoneId(game, source), sourcePermanent.getIdName()).apply(game, source); - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/s/Silkwrap.java b/Mage.Sets/src/mage/cards/s/Silkwrap.java index ad197d354a..45a739a969 100644 --- a/Mage.Sets/src/mage/cards/s/Silkwrap.java +++ b/Mage.Sets/src/mage/cards/s/Silkwrap.java @@ -1,29 +1,23 @@ - package mage.cards.s; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect; -import mage.abilities.effects.common.ExileTargetEffect; +import mage.abilities.effects.common.ExileUntilSourceLeavesEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.ComparisonType; -import mage.constants.Outcome; import mage.constants.TargetController; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.mageobject.ManaValuePredicate; -import mage.game.Game; -import mage.game.permanent.Permanent; import mage.target.TargetPermanent; -import mage.util.CardUtil; /** * - * @author jeffwadsworth + * @author awjackson */ public final class Silkwrap extends CardImpl { @@ -37,8 +31,8 @@ public final class Silkwrap extends CardImpl { public Silkwrap(UUID ownerId, CardSetInfo setInfo) { super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{W}"); - // When Silkwrap enters the battlefield, exile target creature with converted mana cost 3 or less an opponent controls until Silkwrap leaves the battlefield. - Ability ability = new EntersBattlefieldTriggeredAbility(new SilkwrapEffect()); + // When Silkwrap enters the battlefield, exile target creature with mana value 3 or less an opponent controls until Silkwrap leaves the battlefield. + Ability ability = new EntersBattlefieldTriggeredAbility(new ExileUntilSourceLeavesEffect()); ability.addTarget(new TargetPermanent(filter)); ability.addEffect(new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility())); this.addAbility(ability); @@ -54,29 +48,3 @@ public final class Silkwrap extends CardImpl { return new Silkwrap(this); } } - -class SilkwrapEffect extends OneShotEffect { - - public SilkwrapEffect() { - super(Outcome.Neutral); - this.staticText = "exile target creature with mana value 3 or less an opponent controls until {this} leaves the battlefield. (That creature returns under its owner's control.)"; - } - - public SilkwrapEffect(final SilkwrapEffect effect) { - super(effect); - } - - @Override - public SilkwrapEffect copy() { - return new SilkwrapEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = game.getPermanent(source.getSourceId()); - if (permanent != null) { - return new ExileTargetEffect(CardUtil.getCardExileZoneId(game, source), permanent.getIdName()).apply(game, source); - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/s/SuspensionField.java b/Mage.Sets/src/mage/cards/s/SuspensionField.java index 4a8d6d020b..08373547d3 100644 --- a/Mage.Sets/src/mage/cards/s/SuspensionField.java +++ b/Mage.Sets/src/mage/cards/s/SuspensionField.java @@ -1,28 +1,22 @@ - package mage.cards.s; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect; -import mage.abilities.effects.common.ExileTargetEffect; +import mage.abilities.effects.common.ExileUntilSourceLeavesEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.ComparisonType; -import mage.constants.Outcome; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.mageobject.ToughnessPredicate; -import mage.game.Game; -import mage.game.permanent.Permanent; -import mage.target.common.TargetCreaturePermanent; -import mage.util.CardUtil; +import mage.target.TargetPermanent; /** * - * @author emerald000 + * @author awjackson */ public final class SuspensionField extends CardImpl { @@ -36,11 +30,10 @@ public final class SuspensionField extends CardImpl { super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{W}"); // When Suspension Field enters the battlefield, you may exile target creature with toughness 3 or greater until Suspension Field leaves the battlefield. - Ability ability = new EntersBattlefieldTriggeredAbility(new SuspensionFieldExileEffect(), true); - ability.addTarget(new TargetCreaturePermanent(filter)); + Ability ability = new EntersBattlefieldTriggeredAbility(new ExileUntilSourceLeavesEffect(), true); + ability.addTarget(new TargetPermanent(filter)); ability.addEffect(new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility())); this.addAbility(ability); - } private SuspensionField(final SuspensionField card) { @@ -52,30 +45,3 @@ public final class SuspensionField extends CardImpl { return new SuspensionField(this); } } - -class SuspensionFieldExileEffect extends OneShotEffect { - - SuspensionFieldExileEffect() { - super(Outcome.Exile); - this.staticText = "you may exile target creature with toughness 3 or greater until {this} leaves the battlefield. (That creature returns under its owner's control.)"; - } - - SuspensionFieldExileEffect(final SuspensionFieldExileEffect effect) { - super(effect); - } - - @Override - public SuspensionFieldExileEffect copy() { - return new SuspensionFieldExileEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent sourcePermanent = game.getPermanent(source.getSourceId()); - // If Suspension Field leaves the battlefield before its triggered ability resolves, the target won't be exiled. - if (sourcePermanent != null) { - return new ExileTargetEffect(CardUtil.getCardExileZoneId(game, source), sourcePermanent.getIdName()).apply(game, source); - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/t/TakenosCavalry.java b/Mage.Sets/src/mage/cards/t/TakenosCavalry.java index e85509296b..58d666badd 100644 --- a/Mage.Sets/src/mage/cards/t/TakenosCavalry.java +++ b/Mage.Sets/src/mage/cards/t/TakenosCavalry.java @@ -1,4 +1,3 @@ - package mage.cards.t; import java.util.UUID; @@ -12,9 +11,8 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; -import mage.constants.Zone; import mage.filter.common.FilterAttackingOrBlockingCreature; -import mage.target.common.TargetAttackingOrBlockingCreature; +import mage.target.TargetPermanent; /** * @@ -38,8 +36,8 @@ public final class TakenosCavalry extends CardImpl { this.toughness = new MageInt(1); this.addAbility(new BushidoAbility(1)); // {tap}: Takeno's Cavalry deals 1 damage to target attacking or blocking Spirit. - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new DamageTargetEffect(1), new TapSourceCost()); - ability.addTarget(new TargetAttackingOrBlockingCreature(1, 1, filter, false)); + Ability ability = new SimpleActivatedAbility(new DamageTargetEffect(1), new TapSourceCost()); + ability.addTarget(new TargetPermanent(filter)); this.addAbility(ability); } diff --git a/Mage.Sets/src/mage/cards/y/YannikScavengingSentinel.java b/Mage.Sets/src/mage/cards/y/YannikScavengingSentinel.java index f5140515d9..28862b950a 100644 --- a/Mage.Sets/src/mage/cards/y/YannikScavengingSentinel.java +++ b/Mage.Sets/src/mage/cards/y/YannikScavengingSentinel.java @@ -89,7 +89,7 @@ class YannikScavengingSentinelEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); - Permanent sourcePermanent = game.getPermanent(source.getSourceId()); + Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game); if (player == null || sourcePermanent == null || game.getBattlefield().count(filter, source.getControllerId(), source, game) < 1) { return false; diff --git a/Mage/src/main/java/mage/abilities/effects/common/ExileTargetEffect.java b/Mage/src/main/java/mage/abilities/effects/common/ExileTargetEffect.java index 16efa14271..23a013e458 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/ExileTargetEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/ExileTargetEffect.java @@ -129,29 +129,6 @@ public class ExileTargetEffect extends OneShotEffect { if (staticText != null && !staticText.isEmpty()) { return staticText; } - StringBuilder sb = new StringBuilder(); - if (mode.getTargets().isEmpty()) { - sb.append("exile that permanent"); // this will be used if the target is set by target pointer and staticText not set. - } else { - Target target; - if (targetPointer instanceof SecondTargetPointer && mode.getTargets().size() > 1) { - target = mode.getTargets().get(1); - } else { - target = mode.getTargets().get(0); - } - if (target.getNumberOfTargets() == 1) { - String targetName = target.getTargetName(); - sb.append("exile "); - if (!targetName.startsWith("another")) { - sb.append("target "); - } - sb.append(targetName); - } else if (target.getNumberOfTargets() == 0 && target.getMaxNumberOfTargets() > 0) { - sb.append("exile up to ").append(CardUtil.numberToText(target.getMaxNumberOfTargets())).append(" target ").append(target.getTargetName()); - } else { - sb.append("exile ").append(CardUtil.numberToText(target.getNumberOfTargets())).append(" target ").append(target.getTargetName()); - } - } - return sb.toString(); + return "exile " + getTargetPointer().describeTargets(mode.getTargets(), "that permanent"); } } diff --git a/Mage/src/main/java/mage/target/common/TargetAttackingOrBlockingCreature.java b/Mage/src/main/java/mage/target/common/TargetAttackingOrBlockingCreature.java index 53ba110652..3769c28e9c 100644 --- a/Mage/src/main/java/mage/target/common/TargetAttackingOrBlockingCreature.java +++ b/Mage/src/main/java/mage/target/common/TargetAttackingOrBlockingCreature.java @@ -1,25 +1,24 @@ package mage.target.common; import mage.filter.StaticFilters; -import mage.filter.common.FilterAttackingOrBlockingCreature; import mage.target.TargetPermanent; /** * - * @author nantuko + * @author awjackson */ public class TargetAttackingOrBlockingCreature extends TargetPermanent { public TargetAttackingOrBlockingCreature() { - this(1, 1, StaticFilters.FILTER_ATTACKING_OR_BLOCKING_CREATURE, false); + this(1); } public TargetAttackingOrBlockingCreature(int numTargets) { - this(numTargets, numTargets, StaticFilters.FILTER_ATTACKING_OR_BLOCKING_CREATURE, false); + this(numTargets, numTargets); } - public TargetAttackingOrBlockingCreature(int minNumTargets, int maxNumTargets, FilterAttackingOrBlockingCreature filter, boolean notTarget) { - super(minNumTargets, maxNumTargets, filter, notTarget); + public TargetAttackingOrBlockingCreature(int minNumTargets, int maxNumTargets) { + super(minNumTargets, maxNumTargets, maxNumTargets > 1 ? StaticFilters.FILTER_ATTACKING_OR_BLOCKING_CREATURES : StaticFilters.FILTER_ATTACKING_OR_BLOCKING_CREATURE); } public TargetAttackingOrBlockingCreature(final TargetAttackingOrBlockingCreature target) { @@ -30,5 +29,4 @@ public class TargetAttackingOrBlockingCreature extends TargetPermanent { public TargetAttackingOrBlockingCreature copy() { return new TargetAttackingOrBlockingCreature(this); } - }