From 2f9644b7eec2fc51fbf937c8583b424fb5a37f0b Mon Sep 17 00:00:00 2001
From: Evan Kranzler <theelk801@gmail.com>
Date: Tue, 31 May 2022 21:21:05 -0400
Subject: [PATCH] [CLB] Implemented Acolyte of Bahamut

---
 .../src/mage/cards/a/AcolyteOfBahamut.java    | 102 ++++++++++++++++++
 .../src/mage/cards/a/ArtificerClass.java      |   4 +-
 .../CommanderLegendsBattleForBaldursGate.java |   1 +
 3 files changed, 105 insertions(+), 2 deletions(-)
 create mode 100644 Mage.Sets/src/mage/cards/a/AcolyteOfBahamut.java

diff --git a/Mage.Sets/src/mage/cards/a/AcolyteOfBahamut.java b/Mage.Sets/src/mage/cards/a/AcolyteOfBahamut.java
new file mode 100644
index 0000000000..5aa6298e89
--- /dev/null
+++ b/Mage.Sets/src/mage/cards/a/AcolyteOfBahamut.java
@@ -0,0 +1,102 @@
+package mage.cards.a;
+
+import mage.abilities.common.SimpleStaticAbility;
+import mage.abilities.effects.common.continuous.GainAbilityAllEffect;
+import mage.abilities.effects.common.cost.SpellsCostReductionControllerEffect;
+import mage.cards.Card;
+import mage.cards.CardImpl;
+import mage.cards.CardSetInfo;
+import mage.constants.*;
+import mage.filter.FilterCard;
+import mage.filter.StaticFilters;
+import mage.filter.predicate.ObjectSourcePlayer;
+import mage.filter.predicate.ObjectSourcePlayerPredicate;
+import mage.game.Game;
+import mage.game.events.GameEvent;
+import mage.game.stack.Spell;
+import mage.watchers.Watcher;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.UUID;
+
+/**
+ * @author TheElk801
+ */
+public final class AcolyteOfBahamut extends CardImpl {
+
+    private static final FilterCard filter = new FilterCard();
+
+    static {
+        filter.add(SubType.DRAGON.getPredicate());
+        filter.add(AcolyteOfBahamutPredicate.instance);
+    }
+
+    public AcolyteOfBahamut(UUID ownerId, CardSetInfo setInfo) {
+        super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{1}{G}");
+
+        this.addSuperType(SuperType.LEGENDARY);
+        this.subtype.add(SubType.BACKGROUND);
+
+        // Commander creatures you own have "The first Dragon spell you cast each turn costs {2} less to cast."
+        this.addAbility(new SimpleStaticAbility(new GainAbilityAllEffect(
+                new SimpleStaticAbility(
+                        new SpellsCostReductionControllerEffect(filter, 2)
+                                .setText("the first Dragon spell you cast each turn costs {2} less to cast")
+                ), Duration.WhileOnBattlefield, StaticFilters.FILTER_CREATURES_OWNED_COMMANDER
+        )), new AcolyteOfBahamutWatcher());
+    }
+
+    private AcolyteOfBahamut(final AcolyteOfBahamut card) {
+        super(card);
+    }
+
+    @Override
+    public AcolyteOfBahamut copy() {
+        return new AcolyteOfBahamut(this);
+    }
+}
+
+enum AcolyteOfBahamutPredicate implements ObjectSourcePlayerPredicate<Card> {
+    instance;
+
+    @Override
+    public boolean apply(ObjectSourcePlayer<Card> input, Game game) {
+        return input.getObject().hasSubtype(SubType.DRAGON, game)
+                && !AcolyteOfBahamutWatcher.checkPlayer(input.getPlayerId(), game);
+    }
+}
+
+class AcolyteOfBahamutWatcher extends Watcher {
+
+    private final Set<UUID> playerSet = new HashSet<>();
+
+    AcolyteOfBahamutWatcher() {
+        super(WatcherScope.GAME);
+    }
+
+    @Override
+    public void watch(GameEvent event, Game game) {
+        if (event.getType() != GameEvent.EventType.SPELL_CAST) {
+            return;
+        }
+        Spell spell = game.getStack().getSpell(event.getTargetId());
+        if (spell != null && spell.hasSubtype(SubType.DRAGON, game)) {
+            playerSet.add(event.getPlayerId());
+        }
+    }
+
+    @Override
+    public void reset() {
+        super.reset();
+        playerSet.clear();
+    }
+
+    public static boolean checkPlayer(UUID playerId, Game game) {
+        return game
+                .getState()
+                .getWatcher(AcolyteOfBahamutWatcher.class)
+                .playerSet
+                .contains(playerId);
+    }
+}
diff --git a/Mage.Sets/src/mage/cards/a/ArtificerClass.java b/Mage.Sets/src/mage/cards/a/ArtificerClass.java
index 1e110185df..b0d0a8e7f9 100644
--- a/Mage.Sets/src/mage/cards/a/ArtificerClass.java
+++ b/Mage.Sets/src/mage/cards/a/ArtificerClass.java
@@ -7,7 +7,7 @@ import mage.abilities.common.SimpleStaticAbility;
 import mage.abilities.effects.common.CreateTokenCopyTargetEffect;
 import mage.abilities.effects.common.RevealCardsFromLibraryUntilEffect;
 import mage.abilities.effects.common.continuous.GainClassAbilitySourceEffect;
-import mage.abilities.effects.common.cost.SpellsCostReductionAllEffect;
+import mage.abilities.effects.common.cost.SpellsCostReductionControllerEffect;
 import mage.abilities.keyword.ClassLevelAbility;
 import mage.abilities.keyword.ClassReminderAbility;
 import mage.cards.Card;
@@ -50,7 +50,7 @@ public final class ArtificerClass extends CardImpl {
 
         // The first artifact spell you cast each turn costs {1} less to cast.
         this.addAbility(new SimpleStaticAbility(
-                new SpellsCostReductionAllEffect(filter, 1)
+                new SpellsCostReductionControllerEffect(filter, 1)
                         .setText("the first artifact spell you cast each turn costs {1} less to cast")
         ), new ArtificerClassWatcher());
 
diff --git a/Mage.Sets/src/mage/sets/CommanderLegendsBattleForBaldursGate.java b/Mage.Sets/src/mage/sets/CommanderLegendsBattleForBaldursGate.java
index 1ed539f798..ecba35bdc3 100644
--- a/Mage.Sets/src/mage/sets/CommanderLegendsBattleForBaldursGate.java
+++ b/Mage.Sets/src/mage/sets/CommanderLegendsBattleForBaldursGate.java
@@ -22,6 +22,7 @@ public final class CommanderLegendsBattleForBaldursGate extends ExpansionSet {
         this.hasBoosters = false; // temporary
 
         cards.add(new SetCardInfo("Aarakocra Sneak", 54, Rarity.COMMON, mage.cards.a.AarakocraSneak.class));
+        cards.add(new SetCardInfo("Acolyte of Bahamut", 212, Rarity.UNCOMMON, mage.cards.a.AcolyteOfBahamut.class));
         cards.add(new SetCardInfo("Agent of the Iron Throne", 107, Rarity.UNCOMMON, mage.cards.a.AgentOfTheIronThrone.class));
         cards.add(new SetCardInfo("Agent of the Shadow Thieves", 108, Rarity.UNCOMMON, mage.cards.a.AgentOfTheShadowThieves.class));
         cards.add(new SetCardInfo("Alora, Merry Thief", 55, Rarity.UNCOMMON, mage.cards.a.AloraMerryThief.class));