From 2ea6a85aec9800cc4575caf57666f3fa85364408 Mon Sep 17 00:00:00 2001 From: theelk801 Date: Sat, 22 Apr 2023 19:53:54 -0400 Subject: [PATCH] [LTR] Implement Gandalf the Grey --- Mage.Sets/src/mage/cards/y/YouCannotPass.java | 98 +++++++++++++++++++ .../TheLordOfTheRingsTalesOfMiddleEarth.java | 1 + 2 files changed, 99 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/y/YouCannotPass.java diff --git a/Mage.Sets/src/mage/cards/y/YouCannotPass.java b/Mage.Sets/src/mage/cards/y/YouCannotPass.java new file mode 100644 index 0000000000..5d17660883 --- /dev/null +++ b/Mage.Sets/src/mage/cards/y/YouCannotPass.java @@ -0,0 +1,98 @@ +package mage.cards.y; + +import mage.MageObjectReference; +import mage.abilities.effects.common.DestroyTargetEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.WatcherScope; +import mage.filter.FilterPermanent; +import mage.filter.common.FilterCreaturePermanent; +import mage.filter.predicate.Predicate; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.target.TargetPermanent; +import mage.watchers.Watcher; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class YouCannotPass extends CardImpl { + + private static final FilterPermanent filter + = new FilterCreaturePermanent("creature that blocked or was blocked by a legendary creature this turn"); + + static { + filter.add(YouCannotPassPredicate.instance); + } + + public YouCannotPass(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{W}"); + + // Destroy target creature that blocked or was blocked by a legendary creature this turn. + this.getSpellAbility().addEffect(new DestroyTargetEffect()); + this.getSpellAbility().addTarget(new TargetPermanent(filter)); + this.getSpellAbility().addWatcher(new YouCannotPassWatcher()); + } + + private YouCannotPass(final YouCannotPass card) { + super(card); + } + + @Override + public YouCannotPass copy() { + return new YouCannotPass(this); + } +} + +enum YouCannotPassPredicate implements Predicate { + instance; + + @Override + public boolean apply(Permanent input, Game game) { + return YouCannotPassWatcher.checkCreature(input, game); + } +} + +class YouCannotPassWatcher extends Watcher { + + private final Set set = new HashSet<>(); + + YouCannotPassWatcher() { + super(WatcherScope.GAME); + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() != GameEvent.EventType.CREATURE_BLOCKED) { + return; + } + Permanent permanent = game.getPermanent(event.getTargetId()); + if (permanent != null && permanent.isLegendary()) { + set.add(new MageObjectReference(event.getSourceId(), game)); + } + permanent = game.getPermanent(event.getSourceId()); + if (permanent != null && permanent.isLegendary()) { + set.add(new MageObjectReference(event.getTargetId(), game)); + } + } + + @Override + public void reset() { + super.reset(); + set.clear(); + } + + static boolean checkCreature(Permanent permanent, Game game) { + return game + .getState() + .getWatcher(YouCannotPassWatcher.class) + .set + .contains(new MageObjectReference(permanent, game)); + } +} diff --git a/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java b/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java index 5bc7606a8f..78d8d219ee 100644 --- a/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java +++ b/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java @@ -27,5 +27,6 @@ public final class TheLordOfTheRingsTalesOfMiddleEarth extends ExpansionSet { cards.add(new SetCardInfo("Reprieve", 26, Rarity.UNCOMMON, mage.cards.r.Reprieve.class)); cards.add(new SetCardInfo("Swamp", 276, Rarity.LAND, mage.cards.basiclands.Swamp.class, FULL_ART_BFZ_VARIOUS)); cards.add(new SetCardInfo("Trailblazer's Boots", 398, Rarity.RARE, mage.cards.t.TrailblazersBoots.class)); + cards.add(new SetCardInfo("You Cannot Pass!", 38, Rarity.UNCOMMON, mage.cards.y.YouCannotPass.class)); } }