diff --git a/Mage.Sets/src/mage/cards/c/CutShort.java b/Mage.Sets/src/mage/cards/c/CutShort.java new file mode 100644 index 0000000000..9b3f05536a --- /dev/null +++ b/Mage.Sets/src/mage/cards/c/CutShort.java @@ -0,0 +1,100 @@ +package mage.cards.c; + +import mage.MageObjectReference; +import mage.abilities.effects.common.DestroyTargetEffect; +import mage.abilities.keyword.ConvokeAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.WatcherScope; +import mage.filter.FilterPermanent; +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 CutShort extends CardImpl { + + private static final FilterPermanent filter + = new FilterPermanent("planeswalker that was activated this turn or tapped creature"); + + static { + filter.add(CutShortPredicate.instance); + } + + public CutShort(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{2}{W}"); + + // Convoke + this.addAbility(new ConvokeAbility()); + + // Destroy target planeswalker that was activated this turn or tapped creature. + this.getSpellAbility().addEffect(new DestroyTargetEffect()); + this.getSpellAbility().addTarget(new TargetPermanent(filter)); + this.getSpellAbility().addWatcher(new CutShortWatcher()); + } + + private CutShort(final CutShort card) { + super(card); + } + + @Override + public CutShort copy() { + return new CutShort(this); + } +} + +enum CutShortPredicate implements Predicate { + instance; + + @Override + public boolean apply(Permanent input, Game game) { + return input.isCreature(game) + && input.isTapped() + || input.isPlaneswalker(game) + && CutShortWatcher.checkPermanent(input, game); + } +} + +class CutShortWatcher extends Watcher { + + private final Set set = new HashSet<>(); + + CutShortWatcher() { + super(WatcherScope.GAME); + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() != GameEvent.EventType.ACTIVATED_ABILITY) { + return; + } + Permanent permanent = game.getPermanent(event.getSourceId()); + if (permanent != null) { + set.add(new MageObjectReference(permanent, game)); + } + } + + @Override + public void reset() { + super.reset(); + set.clear(); + } + + static boolean checkPermanent(Permanent permanent, Game game) { + return game + .getState() + .getWatcher(CutShortWatcher.class) + .set + .contains(new MageObjectReference(permanent, game)); + } +} diff --git a/Mage.Sets/src/mage/sets/MarchOfTheMachine.java b/Mage.Sets/src/mage/sets/MarchOfTheMachine.java index c4f19b083d..26be4e1634 100644 --- a/Mage.Sets/src/mage/sets/MarchOfTheMachine.java +++ b/Mage.Sets/src/mage/sets/MarchOfTheMachine.java @@ -68,6 +68,7 @@ public final class MarchOfTheMachine extends ExpansionSet { cards.add(new SetCardInfo("Cosmic Hunger", 182, Rarity.COMMON, mage.cards.c.CosmicHunger.class)); cards.add(new SetCardInfo("Cragsmasher Yeti", 333, Rarity.COMMON, mage.cards.c.CragsmasherYeti.class)); cards.add(new SetCardInfo("Crystal Carapace", 183, Rarity.COMMON, mage.cards.c.CrystalCarapace.class)); + cards.add(new SetCardInfo("Cut Short", 10, Rarity.COMMON, mage.cards.c.CutShort.class)); cards.add(new SetCardInfo("Deadly Derision", 99, Rarity.COMMON, mage.cards.d.DeadlyDerision.class)); cards.add(new SetCardInfo("Deeproot Wayfinder", 184, Rarity.RARE, mage.cards.d.DeeprootWayfinder.class)); cards.add(new SetCardInfo("Dismal Backwater", 269, Rarity.COMMON, mage.cards.d.DismalBackwater.class));