From b57dccf10a3b396cc3989eddff155b6e37aa7b1c Mon Sep 17 00:00:00 2001
From: Daniel Bomar <dbdaniel42@gmail.com>
Date: Tue, 8 Nov 2022 13:50:20 -0600
Subject: [PATCH] [BRO] Implemented Legions to Ashes

---
 .../src/mage/cards/l/LegionsToAshes.java      | 79 +++++++++++++++++++
 Mage.Sets/src/mage/sets/TheBrothersWar.java   |  1 +
 2 files changed, 80 insertions(+)
 create mode 100644 Mage.Sets/src/mage/cards/l/LegionsToAshes.java

diff --git a/Mage.Sets/src/mage/cards/l/LegionsToAshes.java b/Mage.Sets/src/mage/cards/l/LegionsToAshes.java
new file mode 100644
index 0000000000..f823782a86
--- /dev/null
+++ b/Mage.Sets/src/mage/cards/l/LegionsToAshes.java
@@ -0,0 +1,79 @@
+package mage.cards.l;
+
+import java.util.HashSet;
+import java.util.UUID;
+
+import mage.abilities.Ability;
+import mage.abilities.effects.OneShotEffect;
+import mage.cards.CardImpl;
+import mage.cards.CardSetInfo;
+import mage.constants.CardType;
+import mage.constants.Outcome;
+import mage.constants.Zone;
+import mage.filter.FilterPermanent;
+import mage.filter.StaticFilters;
+import mage.filter.predicate.mageobject.NamePredicate;
+import mage.filter.predicate.permanent.ControllerIdPredicate;
+import mage.filter.predicate.permanent.TokenPredicate;
+import mage.game.Game;
+import mage.game.permanent.Permanent;
+import mage.players.Player;
+import mage.target.common.TargetNonlandPermanent;
+
+/**
+ *
+ * @author weirddan455
+ */
+public final class LegionsToAshes extends CardImpl {
+
+    public LegionsToAshes(UUID ownerId, CardSetInfo setInfo) {
+        super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{1}{W}{B}");
+
+        // Exile target nonland permanent an opponent controls and all tokens that player controls with the same name as that permanent.
+        this.getSpellAbility().addEffect(new LegionsToAshesEffect());
+        this.getSpellAbility().addTarget(new TargetNonlandPermanent(StaticFilters.FILTER_OPPONENTS_PERMANENT_NON_LAND));
+    }
+
+    private LegionsToAshes(final LegionsToAshes card) {
+        super(card);
+    }
+
+    @Override
+    public LegionsToAshes copy() {
+        return new LegionsToAshes(this);
+    }
+}
+
+class LegionsToAshesEffect extends OneShotEffect {
+
+    public LegionsToAshesEffect() {
+        super(Outcome.Exile);
+        this.staticText = "Exile target nonland permanent an opponent controls and all tokens that player controls with the same name as that permanent.";
+    }
+
+    private LegionsToAshesEffect(final LegionsToAshesEffect effect) {
+        super(effect);
+    }
+
+    @Override
+    public LegionsToAshesEffect copy() {
+        return new LegionsToAshesEffect(this);
+    }
+
+    @Override
+    public boolean apply(Game game, Ability source) {
+        Player controller = game.getPlayer(source.getControllerId());
+        Permanent targetPermanent = game.getPermanent(source.getFirstTarget());
+        if (controller == null || targetPermanent == null) {
+            return false;
+        }
+        FilterPermanent filter = new FilterPermanent();
+        filter.add(TokenPredicate.TRUE);
+        filter.add(new ControllerIdPredicate(targetPermanent.getControllerId()));
+        filter.add(new NamePredicate(targetPermanent.getName()));
+        HashSet<Permanent> toExile = new HashSet<>(game.getBattlefield().getActivePermanents(filter, controller.getId(), source, game));
+        toExile.add(targetPermanent);
+        controller.moveCards(toExile, Zone.EXILED, source, game);
+        return true;
+    }
+}
diff --git a/Mage.Sets/src/mage/sets/TheBrothersWar.java b/Mage.Sets/src/mage/sets/TheBrothersWar.java
index f8dca9065b..5f1528935f 100644
--- a/Mage.Sets/src/mage/sets/TheBrothersWar.java
+++ b/Mage.Sets/src/mage/sets/TheBrothersWar.java
@@ -153,6 +153,7 @@ public final class TheBrothersWar extends ExpansionSet {
         cards.add(new SetCardInfo("Koilos Roc", 55, Rarity.COMMON, mage.cards.k.KoilosRoc.class));
         cards.add(new SetCardInfo("Lat-Nam Adept", 56, Rarity.COMMON, mage.cards.l.LatNamAdept.class));
         cards.add(new SetCardInfo("Lay Down Arms", 11, Rarity.UNCOMMON, mage.cards.l.LayDownArms.class));
+        cards.add(new SetCardInfo("Legions to Ashes", 215, Rarity.RARE, mage.cards.l.LegionsToAshes.class));
         cards.add(new SetCardInfo("Levitating Statue", 236, Rarity.UNCOMMON, mage.cards.l.LevitatingStatue.class));
         cards.add(new SetCardInfo("Liberator, Urza's Battlethopter", 237, Rarity.RARE, mage.cards.l.LiberatorUrzasBattlethopter.class));
         cards.add(new SetCardInfo("Llanowar Wastes", 264, Rarity.RARE, mage.cards.l.LlanowarWastes.class));