From b5e87050aef1f9f88ce2d12c306a746384fc8bd8 Mon Sep 17 00:00:00 2001 From: theelk801 Date: Thu, 4 May 2023 22:54:21 -0400 Subject: [PATCH] [MAT] Implement Narset, Enlightened Exile --- .../mage/cards/n/NarsetEnlightenedExile.java | 123 ++++++++++++++++++ .../sets/MarchOfTheMachineTheAftermath.java | 1 + 2 files changed, 124 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/n/NarsetEnlightenedExile.java diff --git a/Mage.Sets/src/mage/cards/n/NarsetEnlightenedExile.java b/Mage.Sets/src/mage/cards/n/NarsetEnlightenedExile.java new file mode 100644 index 0000000000..30b0cdc1f0 --- /dev/null +++ b/Mage.Sets/src/mage/cards/n/NarsetEnlightenedExile.java @@ -0,0 +1,123 @@ +package mage.cards.n; + +import mage.ApprovingObject; +import mage.MageInt; +import mage.MageObject; +import mage.abilities.Ability; +import mage.abilities.common.AttacksTriggeredAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.continuous.GainAbilityControlledEffect; +import mage.abilities.keyword.ProwessAbility; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.filter.FilterCard; +import mage.filter.StaticFilters; +import mage.filter.common.FilterNonlandCard; +import mage.filter.predicate.ObjectSourcePlayer; +import mage.filter.predicate.ObjectSourcePlayerPredicate; +import mage.filter.predicate.Predicates; +import mage.game.Game; +import mage.players.Player; +import mage.target.common.TargetCardInGraveyard; + +import java.util.Objects; +import java.util.Optional; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class NarsetEnlightenedExile extends CardImpl { + + private static final FilterCard filter + = new FilterNonlandCard("noncreature, nonland card with mana value less than this creature's power"); + + static { + filter.add(Predicates.not(CardType.CREATURE.getPredicate())); + filter.add(NarsetEnlightenedExilePredicate.instance); + } + + public NarsetEnlightenedExile(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{U}{R}{W}"); + + this.addSuperType(SuperType.LEGENDARY); + this.subtype.add(SubType.HUMAN); + this.subtype.add(SubType.MONK); + this.power = new MageInt(3); + this.toughness = new MageInt(4); + + // Creatures you control have prowess. + this.addAbility(new SimpleStaticAbility(new GainAbilityControlledEffect( + new ProwessAbility(), Duration.WhileOnBattlefield, + StaticFilters.FILTER_PERMANENT_CREATURES + ).setText("creatures you control have prowess"))); + + // Whenever Narset, Enlightened Exile attacks, exile target noncreature, nonland card with mana value less than Narset's power from a graveyard and copy it. You may cast the copy without paying its mana cost. + Ability ability = new AttacksTriggeredAbility(new NarsetEnlightenedExileEffect()); + ability.addTarget(new TargetCardInGraveyard(filter)); + this.addAbility(ability); + } + + private NarsetEnlightenedExile(final NarsetEnlightenedExile card) { + super(card); + } + + @Override + public NarsetEnlightenedExile copy() { + return new NarsetEnlightenedExile(this); + } +} + +enum NarsetEnlightenedExilePredicate implements ObjectSourcePlayerPredicate { + instance; + + @Override + public boolean apply(ObjectSourcePlayer input, Game game) { + return Optional + .ofNullable(input.getSource().getSourcePermanentOrLKI(game)) + .filter(Objects::nonNull) + .map(MageObject::getPower) + .map(MageInt::getValue) + .map(p -> input.getObject().getManaValue() < p) + .orElse(false); + } +} + +class NarsetEnlightenedExileEffect extends OneShotEffect { + + NarsetEnlightenedExileEffect() { + super(Outcome.Benefit); + staticText = "exile target noncreature, nonland card with mana value less than {this}'s power " + + "from a graveyard and copy it. You may cast the copy without paying its mana cost"; + } + + private NarsetEnlightenedExileEffect(final NarsetEnlightenedExileEffect effect) { + super(effect); + } + + @Override + public NarsetEnlightenedExileEffect copy() { + return new NarsetEnlightenedExileEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + Card card = game.getCard(getTargetPointer().getFirst(game, source)); + if (player == null || card == null) { + return false; + } + player.moveCards(card, Zone.EXILED, source, game); + Card copiedCard = game.copyCard(card, source, source.getControllerId()); + game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE); + player.cast( + player.chooseAbilityForCast(copiedCard, game, true), + game, true, new ApprovingObject(source, game) + ); + game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null); + return true; + } +} diff --git a/Mage.Sets/src/mage/sets/MarchOfTheMachineTheAftermath.java b/Mage.Sets/src/mage/sets/MarchOfTheMachineTheAftermath.java index bd5bd7f606..67bb3a408e 100644 --- a/Mage.Sets/src/mage/sets/MarchOfTheMachineTheAftermath.java +++ b/Mage.Sets/src/mage/sets/MarchOfTheMachineTheAftermath.java @@ -39,6 +39,7 @@ public final class MarchOfTheMachineTheAftermath extends ExpansionSet { cards.add(new SetCardInfo("Leyline Immersion", 21, Rarity.RARE, mage.cards.l.LeylineImmersion.class)); cards.add(new SetCardInfo("Markov Baron", 14, Rarity.UNCOMMON, mage.cards.m.MarkovBaron.class)); cards.add(new SetCardInfo("Metropolis Reformer", 4, Rarity.RARE, mage.cards.m.MetropolisReformer.class)); + cards.add(new SetCardInfo("Narset, Enlightened Exile", 38, Rarity.MYTHIC, mage.cards.n.NarsetEnlightenedExile.class)); cards.add(new SetCardInfo("Nissa, Resurgent Animist", 22, Rarity.MYTHIC, mage.cards.n.NissaResurgentAnimist.class)); cards.add(new SetCardInfo("Niv-Mizzet, Supreme", 40, Rarity.RARE, mage.cards.n.NivMizzetSupreme.class)); cards.add(new SetCardInfo("Open the Way", 23, Rarity.RARE, mage.cards.o.OpenTheWay.class));