From 9e7b2d1b5794f8d9c2ebf1cff846437a66cec99f Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Wed, 7 Apr 2021 20:00:53 -0400 Subject: [PATCH] [STX] Implemented Emergent Sequence --- .../src/mage/cards/e/EmergentSequence.java | 138 ++++++++++++++++++ .../mage/sets/StrixhavenSchoolOfMages.java | 1 + 2 files changed, 139 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/e/EmergentSequence.java diff --git a/Mage.Sets/src/mage/cards/e/EmergentSequence.java b/Mage.Sets/src/mage/cards/e/EmergentSequence.java new file mode 100644 index 0000000000..d833ea5b38 --- /dev/null +++ b/Mage.Sets/src/mage/cards/e/EmergentSequence.java @@ -0,0 +1,138 @@ +package mage.cards.e; + +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.continuous.BecomesCreatureTargetEffect; +import mage.abilities.hint.Hint; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.counters.CounterType; +import mage.filter.StaticFilters; +import mage.game.Game; +import mage.game.events.EntersTheBattlefieldEvent; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.game.permanent.token.QuandrixToken; +import mage.players.Player; +import mage.target.common.TargetCardInLibrary; +import mage.target.targetpointer.FixedTarget; +import mage.watchers.Watcher; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class EmergentSequence extends CardImpl { + + public EmergentSequence(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{1}{G}"); + + // Search your library for a basic land card, put it onto the battlefield tapped, then shuffle. That land becomes a 0/0 green and blue Fractal creature that's still a land. Put a +1/+1 counter on it for each land you had enter the battlefield under your control this turn. + this.getSpellAbility().addEffect(new EmergentSequenceEffect()); + this.getSpellAbility().addWatcher(new EmergentSequenceWatcher()); + this.getSpellAbility().addHint(EmergentSequenceHint.instance); + } + + private EmergentSequence(final EmergentSequence card) { + super(card); + } + + @Override + public EmergentSequence copy() { + return new EmergentSequence(this); + } +} + +class EmergentSequenceEffect extends OneShotEffect { + + EmergentSequenceEffect() { + super(Outcome.Benefit); + staticText = "search your library for a basic land card, put it onto the battlefield tapped, then shuffle. " + + "That land becomes a 0/0 green and blue Fractal creature that's still a land. " + + "Put a +1/+1 counter on it for each land you had enter the battlefield under your control this turn"; + } + + private EmergentSequenceEffect(final EmergentSequenceEffect effect) { + super(effect); + } + + @Override + public EmergentSequenceEffect copy() { + return new EmergentSequenceEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + if (player == null) { + return false; + } + TargetCardInLibrary target = new TargetCardInLibrary(StaticFilters.FILTER_CARD_BASIC_LAND_A); + player.searchLibrary(target, source, game); + Card card = player.getLibrary().getCard(target.getFirstTarget(), game); + Permanent permanent = null; + if (card != null) { + player.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null); + permanent = game.getPermanent(target.getFirstTarget()); + } + player.shuffleLibrary(source, game); + if (permanent == null) { + return true; + } + game.addEffect(new BecomesCreatureTargetEffect( + new QuandrixToken(), true, true, Duration.Custom + ).setTargetPointer(new FixedTarget(permanent, game)), source); + permanent.addCounters(CounterType.P1P1.createInstance( + EmergentSequenceWatcher.getAmount(source.getControllerId(), game) + ), source.getControllerId(), source, game); + return true; + } +} + +class EmergentSequenceWatcher extends Watcher { + + private final Map playerMap = new HashMap<>(); + + EmergentSequenceWatcher() { + super(WatcherScope.GAME); + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD + && ((EntersTheBattlefieldEvent) event).getTarget().isLand()) { + playerMap.compute(event.getPlayerId(), (u, i) -> i == null ? 1 : Integer.sum(i, 1)); + } + } + + @Override + public void reset() { + super.reset(); + playerMap.clear(); + } + + static int getAmount(UUID playerId, Game game) { + EmergentSequenceWatcher watcher = game.getState().getWatcher(EmergentSequenceWatcher.class); + return watcher != null ? watcher.playerMap.getOrDefault(playerId, 0) : 0; + } +} + +enum EmergentSequenceHint implements Hint { + instance; + + @Override + public String getText(Game game, Ability ability) { + return "Lands entered under your control this turn: " + + EmergentSequenceWatcher.getAmount(ability.getControllerId(), game); + } + + @Override + public EmergentSequenceHint copy() { + return instance; + } +} diff --git a/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java b/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java index aaedd824d7..318e0b7e2a 100644 --- a/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java +++ b/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java @@ -86,6 +86,7 @@ public final class StrixhavenSchoolOfMages extends ExpansionSet { cards.add(new SetCardInfo("Eager First-Year", 16, Rarity.COMMON, mage.cards.e.EagerFirstYear.class)); cards.add(new SetCardInfo("Elemental Masterpiece", 182, Rarity.COMMON, mage.cards.e.ElementalMasterpiece.class)); cards.add(new SetCardInfo("Elemental Summoning", 183, Rarity.COMMON, mage.cards.e.ElementalSummoning.class)); + cards.add(new SetCardInfo("Emergent Sequence", 129, Rarity.UNCOMMON, mage.cards.e.EmergentSequence.class)); cards.add(new SetCardInfo("Enthusiastic Study", 99, Rarity.COMMON, mage.cards.e.EnthusiasticStudy.class)); cards.add(new SetCardInfo("Environmental Sciences", 1, Rarity.COMMON, mage.cards.e.EnvironmentalSciences.class)); cards.add(new SetCardInfo("Essence Infusion", 69, Rarity.COMMON, mage.cards.e.EssenceInfusion.class));