From c7af24f5c5224c3d2bc7d73b746671622501f873 Mon Sep 17 00:00:00 2001
From: theelk801 <theelk801@gmail.com>
Date: Sat, 8 Apr 2023 15:33:42 -0400
Subject: [PATCH] [MOM] Implement Sunder the Gateway

---
 .../src/mage/cards/s/SunderTheGateway.java    | 99 +++++++++++++++++++
 .../src/mage/sets/MarchOfTheMachine.java      |  1 +
 2 files changed, 100 insertions(+)
 create mode 100644 Mage.Sets/src/mage/cards/s/SunderTheGateway.java

diff --git a/Mage.Sets/src/mage/cards/s/SunderTheGateway.java b/Mage.Sets/src/mage/cards/s/SunderTheGateway.java
new file mode 100644
index 0000000000..485bb734a2
--- /dev/null
+++ b/Mage.Sets/src/mage/cards/s/SunderTheGateway.java
@@ -0,0 +1,99 @@
+package mage.cards.s;
+
+import mage.abilities.Ability;
+import mage.abilities.Mode;
+import mage.abilities.effects.OneShotEffect;
+import mage.abilities.effects.common.DestroyTargetEffect;
+import mage.abilities.effects.keyword.IncubateEffect;
+import mage.cards.CardImpl;
+import mage.cards.CardSetInfo;
+import mage.constants.CardType;
+import mage.constants.Outcome;
+import mage.constants.SubType;
+import mage.constants.TargetController;
+import mage.filter.FilterPermanent;
+import mage.filter.common.FilterArtifactOrEnchantmentPermanent;
+import mage.filter.common.FilterControlledPermanent;
+import mage.filter.predicate.permanent.TokenPredicate;
+import mage.game.Game;
+import mage.game.permanent.Permanent;
+import mage.players.Player;
+import mage.target.TargetPermanent;
+
+import java.util.UUID;
+
+/**
+ * @author TheElk801
+ */
+public final class SunderTheGateway extends CardImpl {
+
+    private static final FilterPermanent filter
+            = new FilterArtifactOrEnchantmentPermanent("nontoken artifact or enchantment an opponent controls");
+
+    static {
+        filter.add(TargetController.OPPONENT.getControllerPredicate());
+        filter.add(TokenPredicate.FALSE);
+    }
+
+    public SunderTheGateway(UUID ownerId, CardSetInfo setInfo) {
+        super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{1}{W}");
+
+        // Choose one --
+        // * Destroy target nontoken artifact or enchantment an opponent controls. Incubate 2.
+        this.getSpellAbility().addEffect(new DestroyTargetEffect());
+        this.getSpellAbility().addEffect(new IncubateEffect(2));
+        this.getSpellAbility().addTarget(new TargetPermanent(filter));
+
+        // * Incubate 2, then transform an Incubator token you control.
+        this.getSpellAbility().addMode(new Mode(new IncubateEffect(2)).addEffect(new SunderTheGatewayEffect()));
+    }
+
+    private SunderTheGateway(final SunderTheGateway card) {
+        super(card);
+    }
+
+    @Override
+    public SunderTheGateway copy() {
+        return new SunderTheGateway(this);
+    }
+}
+
+class SunderTheGatewayEffect extends OneShotEffect {
+
+    private static final FilterPermanent filter
+            = new FilterControlledPermanent(SubType.INCUBATOR, "Incubator token you control");
+
+    static {
+        filter.add(TokenPredicate.TRUE);
+    }
+
+    SunderTheGatewayEffect() {
+        super(Outcome.Benefit);
+        staticText = ", then transform an Incubator token you control";
+    }
+
+    private SunderTheGatewayEffect(final SunderTheGatewayEffect effect) {
+        super(effect);
+    }
+
+    @Override
+    public SunderTheGatewayEffect copy() {
+        return new SunderTheGatewayEffect(this);
+    }
+
+    @Override
+    public boolean apply(Game game, Ability source) {
+        Player player = game.getPlayer(source.getControllerId());
+        if (player == null) {
+            return false;
+        }
+        TargetPermanent target = new TargetPermanent(filter);
+        target.setNotTarget(true);
+        if (!target.canChoose(source.getControllerId(), source, game)) {
+            return false;
+        }
+        player.choose(outcome, target, source, game);
+        Permanent permanent = game.getPermanent(target.getFirstTarget());
+        return permanent != null && permanent.transform(source, game);
+    }
+}
diff --git a/Mage.Sets/src/mage/sets/MarchOfTheMachine.java b/Mage.Sets/src/mage/sets/MarchOfTheMachine.java
index acef5fecb5..a847a4467b 100644
--- a/Mage.Sets/src/mage/sets/MarchOfTheMachine.java
+++ b/Mage.Sets/src/mage/sets/MarchOfTheMachine.java
@@ -198,6 +198,7 @@ public final class MarchOfTheMachine extends ExpansionSet {
         cards.add(new SetCardInfo("Storm the Seedcore", 206, Rarity.UNCOMMON, mage.cards.s.StormTheSeedcore.class));
         cards.add(new SetCardInfo("Stormclaw Rager", 254, Rarity.UNCOMMON, mage.cards.s.StormclawRager.class));
         cards.add(new SetCardInfo("Streetwise Negotiator", 207, Rarity.UNCOMMON, mage.cards.s.StreetwiseNegotiator.class));
+        cards.add(new SetCardInfo("Sunder the Gateway", 39, Rarity.COMMON, mage.cards.s.SunderTheGateway.class));
         cards.add(new SetCardInfo("Sunfall", 40, Rarity.RARE, mage.cards.s.Sunfall.class));
         cards.add(new SetCardInfo("Swamp", 279, Rarity.LAND, mage.cards.basiclands.Swamp.class, NON_FULL_USE_VARIOUS));
         cards.add(new SetCardInfo("Swiftwater Cliffs", 273, Rarity.COMMON, mage.cards.s.SwiftwaterCliffs.class));