From 04141a1132471914095dd029ec18e17fb060e4eb Mon Sep 17 00:00:00 2001 From: theelk801 Date: Thu, 4 May 2023 09:08:59 -0400 Subject: [PATCH] [MAT] Implement Open the Way --- Mage.Sets/src/mage/cards/o/OpenTheWay.java | 102 ++++++++++++++++++ .../sets/MarchOfTheMachineTheAftermath.java | 1 + 2 files changed, 103 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/o/OpenTheWay.java diff --git a/Mage.Sets/src/mage/cards/o/OpenTheWay.java b/Mage.Sets/src/mage/cards/o/OpenTheWay.java new file mode 100644 index 0000000000..68c4896fc8 --- /dev/null +++ b/Mage.Sets/src/mage/cards/o/OpenTheWay.java @@ -0,0 +1,102 @@ +package mage.cards.o; + +import mage.abilities.Ability; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.costs.CostAdjuster; +import mage.abilities.costs.mana.VariableManaCost; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.InfoEffect; +import mage.cards.*; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.Zone; +import mage.game.Game; +import mage.players.Player; +import mage.util.CardUtil; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class OpenTheWay extends CardImpl { + + public OpenTheWay(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{X}{G}{G}"); + + // X can't be greater than the number of players in the game. + this.addAbility(new SimpleStaticAbility( + Zone.ALL, new InfoEffect("X can't be greater than the number of players in the game") + ).setRuleAtTheTop(true)); + this.getSpellAbility().setCostAdjuster(OpenTheWayAdjuster.instance); + + // Reveal cards from the top of your library until you reveal X land cards. Put those land cards onto the battlefield tapped and the rest on the bottom of your library in a random order. + this.getSpellAbility().addEffect(new OpenTheWayEffect()); + } + + private OpenTheWay(final OpenTheWay card) { + super(card); + } + + @Override + public OpenTheWay copy() { + return new OpenTheWay(this); + } +} + +enum OpenTheWayAdjuster implements CostAdjuster { + instance; + + @Override + public void adjustCosts(Ability ability, Game game) { + int playerCount = game.getPlayers().size(); + CardUtil.castStream(ability.getCosts().stream(), VariableManaCost.class) + .forEach(cost -> cost.setMaxX(playerCount)); + } +} + +class OpenTheWayEffect extends OneShotEffect { + + OpenTheWayEffect() { + super(Outcome.Benefit); + staticText = "reveal cards from the top of your library until you reveal X land cards. Put those " + + "land cards onto the battlefield tapped and the rest on the bottom of your library in a random order"; + } + + private OpenTheWayEffect(final OpenTheWayEffect effect) { + super(effect); + } + + @Override + public OpenTheWayEffect copy() { + return new OpenTheWayEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + int xValue = source.getManaCostsToPay().getX(); + if (player == null || xValue < 1) { + return false; + } + Cards toReveal = new CardsImpl(); + Cards lands = new CardsImpl(); + for (Card card : player.getLibrary().getCards(game)) { + toReveal.add(card); + if (card.isLand(game)) { + lands.add(card); + } + if (lands.size() >= xValue) { + break; + } + } + player.revealCards(source, toReveal, game); + player.moveCards( + lands.getCards(game), Zone.BATTLEFIELD, source, game, + true, false, false, null + ); + toReveal.retainZone(Zone.LIBRARY, game); + player.putCardsOnBottomOfLibrary(toReveal, game, source, false); + return true; + } +} diff --git a/Mage.Sets/src/mage/sets/MarchOfTheMachineTheAftermath.java b/Mage.Sets/src/mage/sets/MarchOfTheMachineTheAftermath.java index 42ca048d2d..a90df79ba0 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("Metropolis Reformer", 4, Rarity.RARE, mage.cards.m.MetropolisReformer.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)); cards.add(new SetCardInfo("Rebuild the City", 43, Rarity.RARE, mage.cards.r.RebuildTheCity.class)); cards.add(new SetCardInfo("Reckless Handling", 19, Rarity.UNCOMMON, mage.cards.r.RecklessHandling.class)); cards.add(new SetCardInfo("Samut, Vizier of Naktamun", 45, Rarity.MYTHIC, mage.cards.s.SamutVizierOfNaktamun.class));