From 937fe8630b004bbcb0149a4e2e81b7c1f5e39eb5 Mon Sep 17 00:00:00 2001 From: theelk801 Date: Thu, 10 Apr 2025 18:45:08 -0400 Subject: [PATCH] [TDM] Implement Stalwart Successor --- .../src/mage/cards/s/StalwartSuccessor.java | 123 ++++++++++++++++++ .../src/mage/sets/TarkirDragonstorm.java | 1 + 2 files changed, 124 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/s/StalwartSuccessor.java diff --git a/Mage.Sets/src/mage/cards/s/StalwartSuccessor.java b/Mage.Sets/src/mage/cards/s/StalwartSuccessor.java new file mode 100644 index 00000000000..ae0fbeacb18 --- /dev/null +++ b/Mage.Sets/src/mage/cards/s/StalwartSuccessor.java @@ -0,0 +1,123 @@ +package mage.cards.s; + +import mage.MageInt; +import mage.MageObjectReference; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.common.counter.AddCountersTargetEffect; +import mage.abilities.keyword.MenaceAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.SubType; +import mage.constants.WatcherScope; +import mage.constants.Zone; +import mage.counters.CounterType; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.target.targetpointer.FixedTarget; +import mage.watchers.Watcher; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class StalwartSuccessor extends CardImpl { + + public StalwartSuccessor(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{B}{G}"); + + this.subtype.add(SubType.HUMAN); + this.subtype.add(SubType.WARRIOR); + this.power = new MageInt(3); + this.toughness = new MageInt(2); + + // Menace + this.addAbility(new MenaceAbility()); + + // Whenever one or more counters are put on a creature you control, if it's the first time counters have been put on that creature this turn, put a +1/+1 counter on that creature. + this.addAbility(new StalwartSuccessorTriggeredAbility()); + } + + private StalwartSuccessor(final StalwartSuccessor card) { + super(card); + } + + @Override + public StalwartSuccessor copy() { + return new StalwartSuccessor(this); + } +} + +class StalwartSuccessorTriggeredAbility extends TriggeredAbilityImpl { + + StalwartSuccessorTriggeredAbility() { + super(Zone.BATTLEFIELD, new AddCountersTargetEffect(CounterType.P1P1.createInstance())); + this.setTriggerPhrase("Whenever one or more counters are put on a creature you control, " + + "if it's the first time counters have been put on that creature this turn, "); + this.addWatcher(new StalwartSuccessorWatcher()); + } + + private StalwartSuccessorTriggeredAbility(final StalwartSuccessorTriggeredAbility ability) { + super(ability); + } + + @Override + public StalwartSuccessorTriggeredAbility copy() { + return new StalwartSuccessorTriggeredAbility(this); + } + + @Override + public boolean checkEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.COUNTERS_ADDED; + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + Permanent permanent = game.getPermanent(event.getTargetId()); + if (permanent == null + || !permanent.isCreature(game) + || !permanent.isControlledBy(getControllerId()) + || !StalwartSuccessorWatcher.checkCreature(permanent, event, game)) { + return false; + } + this.getEffects().setTargetPointer(new FixedTarget(permanent, game)); + return true; + } +} + +class StalwartSuccessorWatcher extends Watcher { + + private final Map map = new HashMap<>(); + + StalwartSuccessorWatcher() { + super(WatcherScope.GAME); + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.COUNTERS_ADDED) { + map.putIfAbsent(new MageObjectReference(event.getTargetId(), game), event.getId()); + } + } + + @Override + public void reset() { + super.reset(); + map.clear(); + } + + static boolean checkCreature(Permanent permanent, GameEvent event, Game game) { + return Objects.equals( + event.getId(), + game.getState() + .getWatcher(StalwartSuccessorWatcher.class) + .map + .getOrDefault(new MageObjectReference(permanent, game), null) + ); + } +} diff --git a/Mage.Sets/src/mage/sets/TarkirDragonstorm.java b/Mage.Sets/src/mage/sets/TarkirDragonstorm.java index f797ae0ada3..41fc545735f 100644 --- a/Mage.Sets/src/mage/sets/TarkirDragonstorm.java +++ b/Mage.Sets/src/mage/sets/TarkirDragonstorm.java @@ -236,6 +236,7 @@ public final class TarkirDragonstorm extends ExpansionSet { cards.add(new SetCardInfo("Sonic Shrieker", 226, Rarity.UNCOMMON, mage.cards.s.SonicShrieker.class)); cards.add(new SetCardInfo("Spectral Denial", 58, Rarity.UNCOMMON, mage.cards.s.SpectralDenial.class)); cards.add(new SetCardInfo("Stadium Headliner", 122, Rarity.RARE, mage.cards.s.StadiumHeadliner.class)); + cards.add(new SetCardInfo("Stalwart Successor", 227, Rarity.UNCOMMON, mage.cards.s.StalwartSuccessor.class)); cards.add(new SetCardInfo("Starry-Eyed Skyrider", 25, Rarity.UNCOMMON, mage.cards.s.StarryEyedSkyrider.class)); cards.add(new SetCardInfo("Static Snare", 26, Rarity.UNCOMMON, mage.cards.s.StaticSnare.class)); cards.add(new SetCardInfo("Stillness in Motion", 59, Rarity.RARE, mage.cards.s.StillnessInMotion.class));