From 4d7ef06586b3252369bf17dacef8bcc15aad04d6 Mon Sep 17 00:00:00 2001 From: xenohedron Date: Sun, 4 Feb 2024 16:46:11 -0500 Subject: [PATCH] implement [MKM] Assemble the Players --- .../src/mage/cards/a/AssembleThePlayers.java | 159 ++++++++++++++++++ .../cards/j/JohannApprenticeSorcerer.java | 2 +- .../src/mage/sets/MurdersAtKarlovManor.java | 1 + Mage/src/main/java/mage/MageIdentifier.java | 1 + 4 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 Mage.Sets/src/mage/cards/a/AssembleThePlayers.java diff --git a/Mage.Sets/src/mage/cards/a/AssembleThePlayers.java b/Mage.Sets/src/mage/cards/a/AssembleThePlayers.java new file mode 100644 index 00000000000..18b2dddf2d3 --- /dev/null +++ b/Mage.Sets/src/mage/cards/a/AssembleThePlayers.java @@ -0,0 +1,159 @@ +package mage.cards.a; + +import mage.MageIdentifier; +import mage.MageObjectReference; +import mage.abilities.Ability; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.AsThoughEffectImpl; +import mage.abilities.effects.common.continuous.LookAtTopCardOfLibraryAnyTimeEffect; +import mage.abilities.hint.Hint; +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.players.Player; +import mage.watchers.Watcher; + +import java.util.*; + +/** + * @author xenohedron + */ +public final class AssembleThePlayers extends CardImpl { + + public AssembleThePlayers(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{1}{W}"); + + // You may look at the top card of your library any time. + this.addAbility(new SimpleStaticAbility(new LookAtTopCardOfLibraryAnyTimeEffect())); + + // Once each turn, you may cast a creature spell with power 2 or less from the top of your library. + this.addAbility( + new SimpleStaticAbility(new AssembleThePlayersPlayTopEffect()) + .setIdentifier(MageIdentifier.AssembleThePlayersWatcher) + .addHint(AssembleThePlayersHint.instance), + new AssembleThePlayersWatcher() + // all based on Johann, Apprentice Sorcerer + ); + + } + + private AssembleThePlayers(final AssembleThePlayers card) { + super(card); + } + + @Override + public AssembleThePlayers copy() { + return new AssembleThePlayers(this); + } +} + +enum AssembleThePlayersHint implements Hint { + instance; + + @Override + public String getText(Game game, Ability ability) { + AssembleThePlayersWatcher watcher = game.getState().getWatcher(AssembleThePlayersWatcher.class); + if (watcher != null) { + boolean used = watcher.isAbilityUsed(ability.getControllerId(), new MageObjectReference(ability.getSourceId(), game)); + if (used) { + Player player = game.getPlayer(ability.getControllerId()); + if (player != null) { + return "A spell has been cast by " + player.getLogName() + " with {this} this turn."; + } + } + } + return ""; + } + + @Override + public AssembleThePlayersHint copy() { + return this; + } +} + +class AssembleThePlayersPlayTopEffect extends AsThoughEffectImpl { + + AssembleThePlayersPlayTopEffect() { + super(AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, Duration.WhileOnBattlefield, Outcome.Benefit); + staticText = "Once each turn, you may cast a creature spell with power 2 or less from the top of your library"; + } + + private AssembleThePlayersPlayTopEffect(final AssembleThePlayersPlayTopEffect effect) { + super(effect); + } + + @Override + public AssembleThePlayersPlayTopEffect copy() { + return new AssembleThePlayersPlayTopEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + return true; + } + + @Override + public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { + // Only applies for the controller of the ability. + if (!affectedControllerId.equals(source.getControllerId())) { + return false; + } + + Player controller = game.getPlayer(source.getControllerId()); + AssembleThePlayersWatcher watcher = game.getState().getWatcher(AssembleThePlayersWatcher.class); + Permanent sourceObject = game.getPermanent(source.getSourceId()); + if (controller == null || watcher == null || sourceObject == null) { + return false; + } + + // Has the ability already been used this turn by the player? + if (watcher.isAbilityUsed(controller.getId(), new MageObjectReference(sourceObject, game))) { + return false; + } + + Card card = game.getCard(objectId); + Card topCard = controller.getLibrary().getFromTop(game); + // Is the card attempted to be played the top card of the library? + if (card == null || topCard == null || !topCard.getId().equals(card.getMainCard().getId())) { + return false; + } + + // Only works for creatures with power 2 or less + return card.isCreature(game) && card.getPower().getValue() <=2; + } +} + +class AssembleThePlayersWatcher extends Watcher { + + // player -> set of all permanent's mor that already used their once per turn Approval. + private final Map> usedFrom = new HashMap<>(); + + public AssembleThePlayersWatcher() { + super(WatcherScope.GAME); + } + + @Override + public void watch(GameEvent event, Game game) { + UUID playerId = event.getPlayerId(); + if (event.getType() == GameEvent.EventType.SPELL_CAST + && event.hasApprovingIdentifier(MageIdentifier.AssembleThePlayersWatcher) + && playerId != null) { + usedFrom.computeIfAbsent(playerId, k -> new HashSet<>()) + .add(event.getAdditionalReference().getApprovingMageObjectReference()); + } + } + + @Override + public void reset() { + super.reset(); + usedFrom.clear(); + } + + public boolean isAbilityUsed(UUID playerId, MageObjectReference mor) { + return usedFrom.getOrDefault(playerId, Collections.emptySet()).contains(mor); + } +} diff --git a/Mage.Sets/src/mage/cards/j/JohannApprenticeSorcerer.java b/Mage.Sets/src/mage/cards/j/JohannApprenticeSorcerer.java index 2773fdb5864..227cb3bcded 100644 --- a/Mage.Sets/src/mage/cards/j/JohannApprenticeSorcerer.java +++ b/Mage.Sets/src/mage/cards/j/JohannApprenticeSorcerer.java @@ -160,6 +160,6 @@ class JohannApprenticeSorcererWatcher extends Watcher { } public boolean isAbilityUsed(UUID playerId, MageObjectReference mor) { - return usedFrom.getOrDefault(playerId, new HashSet<>()).contains(mor); + return usedFrom.getOrDefault(playerId, Collections.emptySet()).contains(mor); } } diff --git a/Mage.Sets/src/mage/sets/MurdersAtKarlovManor.java b/Mage.Sets/src/mage/sets/MurdersAtKarlovManor.java index e3a7c3e705b..36261bfc314 100644 --- a/Mage.Sets/src/mage/sets/MurdersAtKarlovManor.java +++ b/Mage.Sets/src/mage/sets/MurdersAtKarlovManor.java @@ -38,6 +38,7 @@ public final class MurdersAtKarlovManor extends ExpansionSet { cards.add(new SetCardInfo("Anzrag, the Quake-Mole", 186, Rarity.MYTHIC, mage.cards.a.AnzragTheQuakeMole.class)); cards.add(new SetCardInfo("Archdruid's Charm", 151, Rarity.RARE, mage.cards.a.ArchdruidsCharm.class)); cards.add(new SetCardInfo("Assassin's Trophy", 187, Rarity.RARE, mage.cards.a.AssassinsTrophy.class)); + cards.add(new SetCardInfo("Assemble the Players", 3, Rarity.RARE, mage.cards.a.AssembleThePlayers.class)); cards.add(new SetCardInfo("Audience with Trostani", 152, Rarity.RARE, mage.cards.a.AudienceWithTrostani.class)); cards.add(new SetCardInfo("Aurelia, the Law Above", 188, Rarity.RARE, mage.cards.a.AureliaTheLawAbove.class)); cards.add(new SetCardInfo("Auspicious Arrival", 5, Rarity.COMMON, mage.cards.a.AuspiciousArrival.class)); diff --git a/Mage/src/main/java/mage/MageIdentifier.java b/Mage/src/main/java/mage/MageIdentifier.java index baca1c2db65..a95128241c9 100644 --- a/Mage/src/main/java/mage/MageIdentifier.java +++ b/Mage/src/main/java/mage/MageIdentifier.java @@ -34,6 +34,7 @@ public enum MageIdentifier { SerraParagonWatcher, OneWithTheMultiverseWatcher("Without paying manacost"), JohannApprenticeSorcererWatcher, + AssembleThePlayersWatcher, KaghaShadowArchdruidWatcher, CourtOfLocthwainWatcher("Without paying manacost"),