From 3c9272127a3a53995b63eafbbea81c449129bc2a Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Thu, 24 Jan 2019 10:16:24 -0500 Subject: [PATCH] fixed issues with Remembrance (fixes #5549) --- Mage.Sets/src/mage/cards/r/Remembrance.java | 85 ++++++--------------- 1 file changed, 24 insertions(+), 61 deletions(-) diff --git a/Mage.Sets/src/mage/cards/r/Remembrance.java b/Mage.Sets/src/mage/cards/r/Remembrance.java index 3ab60a2647..2a559585c8 100644 --- a/Mage.Sets/src/mage/cards/r/Remembrance.java +++ b/Mage.Sets/src/mage/cards/r/Remembrance.java @@ -1,33 +1,27 @@ package mage.cards.r; -import java.util.UUID; -import mage.MageObject; -import mage.abilities.Ability; import mage.abilities.TriggeredAbilityImpl; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.search.SearchLibraryPutInHandEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; -import mage.constants.TargetController; import mage.constants.Zone; import mage.filter.FilterCard; -import mage.filter.common.FilterCreaturePermanent; +import mage.filter.FilterPermanent; +import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.predicate.Predicates; import mage.filter.predicate.mageobject.NamePredicate; -import mage.filter.predicate.permanent.ControllerPredicate; import mage.filter.predicate.permanent.TokenPredicate; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.events.ZoneChangeEvent; import mage.game.permanent.Permanent; -import mage.players.Player; import mage.target.common.TargetCardInLibrary; +import java.util.UUID; + /** - * * @author TheElk801 */ public final class Remembrance extends CardImpl { @@ -39,7 +33,7 @@ public final class Remembrance extends CardImpl { this.addAbility(new RemembranceTriggeredAbility()); } - public Remembrance(final Remembrance card) { + private Remembrance(final Remembrance card) { super(card); } @@ -51,19 +45,17 @@ public final class Remembrance extends CardImpl { class RemembranceTriggeredAbility extends TriggeredAbilityImpl { - private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("nontoken creature you control"); + private static final FilterPermanent filter = new FilterControlledCreaturePermanent(); static { - filter.add(new ControllerPredicate(TargetController.YOU)); filter.add(Predicates.not(TokenPredicate.instance)); } - public RemembranceTriggeredAbility() { - super(Zone.BATTLEFIELD, new RemembranceEffect()); - this.optional = true; + RemembranceTriggeredAbility() { + super(Zone.BATTLEFIELD, null, true); } - public RemembranceTriggeredAbility(final RemembranceTriggeredAbility ability) { + private RemembranceTriggeredAbility(final RemembranceTriggeredAbility ability) { super(ability); } @@ -79,55 +71,26 @@ class RemembranceTriggeredAbility extends TriggeredAbilityImpl { @Override public boolean checkTrigger(GameEvent event, Game game) { - if (((ZoneChangeEvent) event).getToZone() == Zone.GRAVEYARD - && ((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) { - Permanent permanent = (Permanent) game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD); - MageObject mageObject = game.getObject(sourceId); - if (permanent != null - && filter.match(permanent, game)) { - game.getState().setValue(mageObject + "nameOfPermanent", permanent.getName()); - return true; - } + if (!((ZoneChangeEvent) event).isDiesEvent()) { + return false; + } + Permanent permanent = game.getPermanentOrLKIBattlefield(event.getTargetId()); + if (permanent != null && filter.match(permanent, game)) { + FilterCard filterCard = new FilterCard("card named " + permanent.getName()); + filterCard.add(new NamePredicate(permanent.getName())); + this.getEffects().clear(); + this.addEffect(new SearchLibraryPutInHandEffect( + new TargetCardInLibrary(filterCard), true, true + )); + return true; } return false; } @Override public String getRule() { - return "Whenever a nontoken creature you control dies, you may search your library for a card with the same name as that creature, reveal it, and put it into your hand. If you do, shuffle your library."; - } -} - -class RemembranceEffect extends OneShotEffect { - - private String cardName; - - RemembranceEffect() { - super(Outcome.Benefit); - } - - RemembranceEffect(final RemembranceEffect effect) { - super(effect); - } - - @Override - public RemembranceEffect copy() { - return new RemembranceEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - MageObject mageObject = game.getObject(source.getSourceId()); - if(mageObject != null) { - cardName = (String) game.getState().getValue(mageObject + "nameOfPermanent"); - if (controller != null - && cardName != null) { - FilterCard filterCard = new FilterCard("card named " + cardName); - filterCard.add(new NamePredicate(cardName)); - return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filterCard), true, true).apply(game, source); - } - } - return false; + return "Whenever a nontoken creature you control dies, " + + "you may search your library for a card with the same name as that creature, " + + "reveal it, and put it into your hand. If you do, shuffle your library."; } }