From d3cf599e3906588a7095e02edd8fc6f73eb85747 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Thu, 2 Jun 2022 08:35:46 -0400 Subject: [PATCH] [CLB] Implemented Dragon Cultist --- Mage.Sets/src/mage/cards/d/DragonCultist.java | 102 ++++++++++++++++++ .../CommanderLegendsBattleForBaldursGate.java | 1 + 2 files changed, 103 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/d/DragonCultist.java diff --git a/Mage.Sets/src/mage/cards/d/DragonCultist.java b/Mage.Sets/src/mage/cards/d/DragonCultist.java new file mode 100644 index 00000000000..07230149809 --- /dev/null +++ b/Mage.Sets/src/mage/cards/d/DragonCultist.java @@ -0,0 +1,102 @@ +package mage.cards.d; + +import mage.MageObjectReference; +import mage.abilities.Ability; +import mage.abilities.common.BeginningOfEndStepTriggeredAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.condition.Condition; +import mage.abilities.effects.common.CreateTokenEffect; +import mage.abilities.effects.common.continuous.GainAbilityAllEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.filter.StaticFilters; +import mage.game.Game; +import mage.game.events.DamagedEvent; +import mage.game.events.GameEvent; +import mage.game.permanent.token.DragonToken; +import mage.util.CardUtil; +import mage.watchers.Watcher; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class DragonCultist extends CardImpl { + + public DragonCultist(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{4}{R}"); + + this.addSuperType(SuperType.LEGENDARY); + this.subtype.add(SubType.BACKGROUND); + + // Commander creatures you own have "At the beginning of your end step, if a source you controlled dealt 5 or more damage this turn, create a 4/4 red Dragon creature token with flying." + this.addAbility(new SimpleStaticAbility(new GainAbilityAllEffect( + new BeginningOfEndStepTriggeredAbility( + new CreateTokenEffect(new DragonToken()), TargetController.YOU, + DragonCultistCondition.instance, false + ), Duration.WhileOnBattlefield, StaticFilters.FILTER_CREATURES_OWNED_COMMANDER + )), new DragonCultistWatcher()); + } + + private DragonCultist(final DragonCultist card) { + super(card); + } + + @Override + public DragonCultist copy() { + return new DragonCultist(this); + } +} + +enum DragonCultistCondition implements Condition { + instance; + + @Override + public boolean apply(Game game, Ability source) { + return DragonCultistWatcher.checkPlayer(source.getControllerId(), game); + } + + @Override + public String toString() { + return "if a source you controlled dealt 5 or more damage this turn"; + } +} + +class DragonCultistWatcher extends Watcher { + + private final Map> map = new HashMap<>(); + + DragonCultistWatcher() { + super(WatcherScope.GAME); + } + + @Override + public void watch(GameEvent event, Game game) { + if (event instanceof DamagedEvent) { + map.computeIfAbsent(game.getControllerId(event.getSourceId()), x -> new HashMap<>()) + .compute(new MageObjectReference(event.getSourceId(), game), CardUtil::setOrIncrementValue); + } + } + + @Override + public void reset() { + map.clear(); + super.reset(); + } + + static boolean checkPlayer(UUID playerId, Game game) { + return game + .getState() + .getWatcher(DragonCultistWatcher.class) + .map + .getOrDefault(playerId, Collections.emptyMap()) + .values() + .stream() + .anyMatch(x -> x >= 5); + } +} diff --git a/Mage.Sets/src/mage/sets/CommanderLegendsBattleForBaldursGate.java b/Mage.Sets/src/mage/sets/CommanderLegendsBattleForBaldursGate.java index 6563b2818cd..25aeab6669a 100644 --- a/Mage.Sets/src/mage/sets/CommanderLegendsBattleForBaldursGate.java +++ b/Mage.Sets/src/mage/sets/CommanderLegendsBattleForBaldursGate.java @@ -172,6 +172,7 @@ public final class CommanderLegendsBattleForBaldursGate extends ExpansionSet { cards.add(new SetCardInfo("Domineering Will", 719, Rarity.RARE, mage.cards.d.DomineeringWill.class)); cards.add(new SetCardInfo("Draconic Lore", 64, Rarity.COMMON, mage.cards.d.DraconicLore.class)); cards.add(new SetCardInfo("Draconic Muralists", 224, Rarity.UNCOMMON, mage.cards.d.DraconicMuralists.class)); + cards.add(new SetCardInfo("Dragon Cultist", 170, Rarity.UNCOMMON, mage.cards.d.DragonCultist.class)); cards.add(new SetCardInfo("Dragon's Hoard", 858, Rarity.RARE, mage.cards.d.DragonsHoard.class)); cards.add(new SetCardInfo("Dragonborn Looter", 65, Rarity.COMMON, mage.cards.d.DragonbornLooter.class)); cards.add(new SetCardInfo("Drakuseth, Maw of Flames", 790, Rarity.RARE, mage.cards.d.DrakusethMawOfFlames.class));