From 24d555f41ccd4c7859aecae9cdd10ac71596e701 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sun, 20 Sep 2015 09:46:19 +0200 Subject: [PATCH] * Emira Shepherd - Fixed that the returned card could be returned to battlefield if the played land was a Plains. --- .../battleforzendikar/EmeriaShepherd.java | 46 +++++++++++++++++-- .../abilities/common/LandfallAbility.java | 6 +++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/Mage.Sets/src/mage/sets/battleforzendikar/EmeriaShepherd.java b/Mage.Sets/src/mage/sets/battleforzendikar/EmeriaShepherd.java index 663f22d37c..b4322ab7f4 100644 --- a/Mage.Sets/src/mage/sets/battleforzendikar/EmeriaShepherd.java +++ b/Mage.Sets/src/mage/sets/battleforzendikar/EmeriaShepherd.java @@ -31,14 +31,20 @@ import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.LandfallAbility; -import mage.abilities.effects.common.ReturnToHandTargetEffect; +import mage.abilities.effects.OneShotEffect; import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; +import mage.cards.CardsImpl; import mage.constants.CardType; +import mage.constants.Outcome; import mage.constants.Rarity; +import mage.constants.Zone; import mage.filter.common.FilterPermanentCard; import mage.filter.predicate.Predicates; import mage.filter.predicate.mageobject.CardTypePredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; import mage.target.common.TargetCardInYourGraveyard; /** @@ -62,8 +68,9 @@ public class EmeriaShepherd extends CardImpl { // Flying this.addAbility(FlyingAbility.getInstance()); - // Landfall — Whenever a land enters the battlefield under your control, you may return target nonland permanent card from your graveyard to your hand. If that land is a Plains, you may return that nonland permanent card to the battlefield instead. - Ability ability = new LandfallAbility(new ReturnToHandTargetEffect(), true); + // Landfall — Whenever a land enters the battlefield under your control, you may return target nonland permanent card from your graveyard to your hand. + // If that land is a Plains, you may return that nonland permanent card to the battlefield instead. + Ability ability = new LandfallAbility(Zone.BATTLEFIELD, new EmeriaShepherdReturnToHandTargetEffect(), true); ability.addTarget(new TargetCardInYourGraveyard(new FilterPermanentCard(filter))); this.addAbility(ability); } @@ -77,3 +84,36 @@ public class EmeriaShepherd extends CardImpl { return new EmeriaShepherd(this); } } + +class EmeriaShepherdReturnToHandTargetEffect extends OneShotEffect { + + public EmeriaShepherdReturnToHandTargetEffect() { + super(Outcome.ReturnToHand); + staticText = "you may return target nonland permanent card from your graveyard to your hand. If that land is a Plains, you may return that nonland permanent card to the battlefield instead"; + } + + public EmeriaShepherdReturnToHandTargetEffect(final EmeriaShepherdReturnToHandTargetEffect effect) { + super(effect); + } + + @Override + public EmeriaShepherdReturnToHandTargetEffect copy() { + return new EmeriaShepherdReturnToHandTargetEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + Permanent triggeringLand = ((LandfallAbility) source).getTriggeringPermanent(); + if (controller == null || triggeringLand == null) { + return false; + } + Zone toZone = Zone.HAND; + if (triggeringLand.getSubtype().contains("Plains") + && controller.chooseUse(Outcome.PutCardInPlay, "Put the card to battlefield instead?", source, game)) { + toZone = Zone.BATTLEFIELD; + } + return controller.moveCards(new CardsImpl(targetPointer.getTargets(game, source)), null, toZone, source, game); + } + +} diff --git a/Mage/src/mage/abilities/common/LandfallAbility.java b/Mage/src/mage/abilities/common/LandfallAbility.java index 84f3e3087e..17560ca692 100644 --- a/Mage/src/mage/abilities/common/LandfallAbility.java +++ b/Mage/src/mage/abilities/common/LandfallAbility.java @@ -44,6 +44,7 @@ import mage.target.targetpointer.FixedTarget; public class LandfallAbility extends TriggeredAbilityImpl { protected SetTargetPointer setTargetPointer; + protected Permanent triggeringLand; public LandfallAbility(Effect effect, boolean optional) { this(Zone.BATTLEFIELD, effect, optional); @@ -61,6 +62,7 @@ public class LandfallAbility extends TriggeredAbilityImpl { public LandfallAbility(final LandfallAbility ability) { super(ability); this.setTargetPointer = ability.setTargetPointer; + this.triggeringLand = ability.triggeringLand; } @Override @@ -74,6 +76,7 @@ public class LandfallAbility extends TriggeredAbilityImpl { if (permanent != null && permanent.getCardType().contains(CardType.LAND) && permanent.getControllerId().equals(this.controllerId)) { + triggeringLand = permanent; if (setTargetPointer.equals(SetTargetPointer.PERMANENT)) { for (Effect effect : getEffects()) { effect.setTargetPointer(new FixedTarget(permanent, game)); @@ -94,4 +97,7 @@ public class LandfallAbility extends TriggeredAbilityImpl { return new LandfallAbility(this); } + public Permanent getTriggeringPermanent() { + return triggeringLand; + } }