From 6e838869233b5943d7ec1617bffaad312840499a Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Tue, 6 Apr 2021 21:31:29 -0400 Subject: [PATCH] [STX] Implemented Maelstrom Muse --- Mage.Sets/src/mage/cards/m/MaelstromMuse.java | 142 ++++++++++++++++++ .../mage/sets/StrixhavenSchoolOfMages.java | 1 + 2 files changed, 143 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/m/MaelstromMuse.java diff --git a/Mage.Sets/src/mage/cards/m/MaelstromMuse.java b/Mage.Sets/src/mage/cards/m/MaelstromMuse.java new file mode 100644 index 0000000000..f590efbe39 --- /dev/null +++ b/Mage.Sets/src/mage/cards/m/MaelstromMuse.java @@ -0,0 +1,142 @@ +package mage.cards.m; + +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.SpellAbility; +import mage.abilities.common.AttacksTriggeredAbility; +import mage.abilities.effects.common.cost.CostModificationEffectImpl; +import mage.abilities.keyword.FlyingAbility; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.game.stack.Spell; +import mage.util.CardUtil; +import mage.watchers.Watcher; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class MaelstromMuse extends CardImpl { + + public MaelstromMuse(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{U}{U/R}{R}"); + + this.subtype.add(SubType.DJINN); + this.subtype.add(SubType.WIZARD); + this.power = new MageInt(2); + this.toughness = new MageInt(4); + + // Flying + this.addAbility(FlyingAbility.getInstance()); + + // Whenever Maelstrom Muse attacks, the next instant or sorcery spell you cast this turn costs {X} less to cast, where X is Maelstrom Muse's power as this ability resolves. + this.addAbility(new AttacksTriggeredAbility( + new MaelstromMuseEffect(), false + ), new MaelstromMuseWatcher()); + } + + private MaelstromMuse(final MaelstromMuse card) { + super(card); + } + + @Override + public MaelstromMuse copy() { + return new MaelstromMuse(this); + } +} + +class MaelstromMuseEffect extends CostModificationEffectImpl { + + private int spellsCast; + private int sourcePower = 0; + + MaelstromMuseEffect() { + super(Duration.EndOfTurn, Outcome.Benefit, CostModificationType.REDUCE_COST); + staticText = "the next instant or sorcery spell you cast this turn costs {X} less to cast, " + + "where X is {this}'s power as this ability resolves"; + } + + private MaelstromMuseEffect(final MaelstromMuseEffect effect) { + super(effect); + this.spellsCast = effect.spellsCast; + this.sourcePower = effect.sourcePower; + } + + @Override + public void init(Ability source, Game game) { + super.init(source, game); + MaelstromMuseWatcher watcher = game.getState().getWatcher(MaelstromMuseWatcher.class); + if (watcher != null) { + spellsCast = watcher.getCount(source.getControllerId()); + } + Permanent permanent = source.getSourcePermanentOrLKI(game); + sourcePower = permanent != null ? Math.max(permanent.getPower().getValue(), 0) : 0; + } + + @Override + public boolean apply(Game game, Ability source, Ability abilityToModify) { + CardUtil.reduceCost(abilityToModify, sourcePower); + return true; + } + + @Override + public boolean applies(Ability abilityToModify, Ability source, Game game) { + MaelstromMuseWatcher watcher = game.getState().getWatcher(MaelstromMuseWatcher.class); + if (watcher == null) { + return false; + } + if (watcher.getCount(source.getControllerId()) > spellsCast) { + discard(); // only one use + return false; + } + if (!(abilityToModify instanceof SpellAbility) + || !abilityToModify.isControlledBy(source.getControllerId())) { + return false; + } + Card spellCard = ((SpellAbility) abilityToModify).getCharacteristics(game); + return spellCard != null && spellCard.isInstantOrSorcery(); + } + + @Override + public MaelstromMuseEffect copy() { + return new MaelstromMuseEffect(this); + } +} + +class MaelstromMuseWatcher extends Watcher { + + private final Map playerMap = new HashMap<>(); + + MaelstromMuseWatcher() { + super(WatcherScope.GAME); + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() != GameEvent.EventType.SPELL_CAST) { + return; + } + Spell spell = game.getSpell(event.getSourceId()); + if (spell != null && spell.isInstantOrSorcery()) { + playerMap.compute(event.getPlayerId(), (u, i) -> i == null ? 1 : Integer.sum(i, 1)); + } + } + + @Override + public void reset() { + super.reset(); + playerMap.clear(); + } + + int getCount(UUID playerId) { + return playerMap.getOrDefault(playerId, 0); + } +} diff --git a/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java b/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java index 2378af5ad9..844e267c0f 100644 --- a/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java +++ b/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java @@ -141,6 +141,7 @@ public final class StrixhavenSchoolOfMages extends ExpansionSet { cards.add(new SetCardInfo("Lorehold Command", 199, Rarity.RARE, mage.cards.l.LoreholdCommand.class)); cards.add(new SetCardInfo("Lorehold Excavation", 200, Rarity.UNCOMMON, mage.cards.l.LoreholdExcavation.class)); cards.add(new SetCardInfo("Lorehold Pledgemage", 201, Rarity.COMMON, mage.cards.l.LoreholdPledgemage.class)); + cards.add(new SetCardInfo("Maelstrom Muse", 202, Rarity.UNCOMMON, mage.cards.m.MaelstromMuse.class)); cards.add(new SetCardInfo("Mage Hunter", 76, Rarity.UNCOMMON, mage.cards.m.MageHunter.class)); cards.add(new SetCardInfo("Mage Hunters' Onslaught", 77, Rarity.COMMON, mage.cards.m.MageHuntersOnslaught.class)); cards.add(new SetCardInfo("Magma Opus", 203, Rarity.MYTHIC, mage.cards.m.MagmaOpus.class));