diff --git a/Mage.Sets/src/mage/cards/r/RushedRebirth.java b/Mage.Sets/src/mage/cards/r/RushedRebirth.java new file mode 100644 index 00000000000..340361e45aa --- /dev/null +++ b/Mage.Sets/src/mage/cards/r/RushedRebirth.java @@ -0,0 +1,137 @@ +package mage.cards.r; + +import mage.MageObjectReference; +import mage.abilities.Ability; +import mage.abilities.DelayedTriggeredAbility; +import mage.abilities.effects.Effect; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.filter.FilterCard; +import mage.filter.common.FilterCreatureCard; +import mage.filter.predicate.Predicate; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.ZoneChangeEvent; +import mage.game.permanent.Permanent; +import mage.target.common.TargetCardInLibrary; +import mage.target.common.TargetCreaturePermanent; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class RushedRebirth extends CardImpl { + + public RushedRebirth(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{B}{G}"); + + // Choose target creature. When that creature dies this turn, search your library for a creature card with lesser mana value, put it onto the battlefield tapped, then shuffle. + this.getSpellAbility().addEffect(new RushedRebirthEffect()); + this.getSpellAbility().addTarget(new TargetCreaturePermanent()); + } + + private RushedRebirth(final RushedRebirth card) { + super(card); + } + + @Override + public RushedRebirth copy() { + return new RushedRebirth(this); + } +} + +class RushedRebirthEffect extends OneShotEffect { + + RushedRebirthEffect() { + super(Outcome.Benefit); + staticText = "choose target creature. When that creature dies this turn, " + + "search your library for a creature card with lesser mana value, " + + "put it onto the battlefield tapped, then shuffle"; + } + + private RushedRebirthEffect(final RushedRebirthEffect effect) { + super(effect); + } + + @Override + public RushedRebirthEffect copy() { + return new RushedRebirthEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = game.getPermanent(source.getFirstTarget()); + if (permanent == null) { + return false; + } + game.addDelayedTriggeredAbility(new RushedRebirthDelayedTriggeredAbility(permanent, game)); + return true; + } +} + +class RushedRebirthDelayedTriggeredAbility extends DelayedTriggeredAbility { + + private static final class RushedRebirthPredicate implements Predicate { + + private final Permanent permanent; + + private RushedRebirthPredicate(Permanent permanent) { + this.permanent = permanent; + } + + @Override + public boolean apply(Card input, Game game) { + return input.getConvertedManaCost() < permanent.getConvertedManaCost(); + } + } + + private final MageObjectReference mor; + + RushedRebirthDelayedTriggeredAbility(Permanent permanent, Game game) { + super(makeEffect(permanent), Duration.EndOfTurn, false, false); + this.mor = new MageObjectReference(permanent, game); + } + + private RushedRebirthDelayedTriggeredAbility(final RushedRebirthDelayedTriggeredAbility ability) { + super(ability); + this.mor = ability.mor; + } + + @Override + public boolean checkEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.ZONE_CHANGE; + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + ZoneChangeEvent zEvent = (ZoneChangeEvent) event; + return zEvent.isDiesEvent() && mor.refersTo(zEvent.getTarget(), game); + } + + private static Effect makeEffect(Permanent permanent) { + FilterCard filter = new FilterCreatureCard( + "creature card with lesser mana value than " + permanent.getIdName() + ); + filter.add(new RushedRebirthPredicate(permanent)); + return new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(filter), true); + } + + @Override + public RushedRebirthDelayedTriggeredAbility copy() { + return new RushedRebirthDelayedTriggeredAbility(this); + } + + @Override + public String getRule() { + return "When that creature dies this turn, search your library for a creature card " + + "with lesser mana value, put it onto the battlefield tapped, then shuffle."; + } + +} diff --git a/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java b/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java index 6fd1464ac33..c741508e017 100644 --- a/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java +++ b/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java @@ -192,6 +192,7 @@ public final class StrixhavenSchoolOfMages extends ExpansionSet { cards.add(new SetCardInfo("Rip Apart", 225, Rarity.UNCOMMON, mage.cards.r.RipApart.class)); cards.add(new SetCardInfo("Rise of Extus", 226, Rarity.COMMON, mage.cards.r.RiseOfExtus.class)); cards.add(new SetCardInfo("Rootha, Mercurial Artist", 227, Rarity.UNCOMMON, mage.cards.r.RoothaMercurialArtist.class)); + cards.add(new SetCardInfo("Rushed Rebirth", 228, Rarity.RARE, mage.cards.r.RushedRebirth.class)); cards.add(new SetCardInfo("Scurrid Colony", 142, Rarity.COMMON, mage.cards.s.ScurridColony.class)); cards.add(new SetCardInfo("Secret Rendezvous", 26, Rarity.UNCOMMON, mage.cards.s.SecretRendezvous.class)); cards.add(new SetCardInfo("Sedgemoor Witch", 86, Rarity.RARE, mage.cards.s.SedgemoorWitch.class));