From a1c067a8fbb05a4ab5aff954625116cc5ef06b35 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Thu, 16 Sep 2021 09:56:53 -0400 Subject: [PATCH] [MIC] Implemented Celestial Judgment --- .../src/mage/cards/c/CelestialJudgment.java | 102 ++++++++++++++++++ .../src/mage/sets/MidnightHuntCommander.java | 1 + 2 files changed, 103 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/c/CelestialJudgment.java diff --git a/Mage.Sets/src/mage/cards/c/CelestialJudgment.java b/Mage.Sets/src/mage/cards/c/CelestialJudgment.java new file mode 100644 index 0000000000..5ac6057ad2 --- /dev/null +++ b/Mage.Sets/src/mage/cards/c/CelestialJudgment.java @@ -0,0 +1,102 @@ +package mage.cards.c; + +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.ComparisonType; +import mage.constants.Outcome; +import mage.filter.FilterPermanent; +import mage.filter.StaticFilters; +import mage.filter.common.FilterCreaturePermanent; +import mage.filter.predicate.mageobject.PowerPredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.TargetPermanent; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * @author TheElk801 + */ +public final class CelestialJudgment extends CardImpl { + + public CelestialJudgment(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{4}{W}{W}"); + + // For each different power among creatures on the battlefield, choose a creature with that power. Destroy each creature not chosen this way. + this.getSpellAbility().addEffect(new CelestialJudgmentEffect()); + } + + private CelestialJudgment(final CelestialJudgment card) { + super(card); + } + + @Override + public CelestialJudgment copy() { + return new CelestialJudgment(this); + } +} + +class CelestialJudgmentEffect extends OneShotEffect { + + CelestialJudgmentEffect() { + super(Outcome.Benefit); + staticText = "for each different power among creatures on the battlefield, " + + "choose a creature with that power. Destroy each creature not chosen this way"; + } + + private CelestialJudgmentEffect(final CelestialJudgmentEffect effect) { + super(effect); + } + + @Override + public CelestialJudgmentEffect copy() { + return new CelestialJudgmentEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + if (player == null) { + return false; + } + List permanents = game + .getBattlefield() + .getActivePermanents( + StaticFilters.FILTER_PERMANENT_CREATURE, + source.getControllerId(), source.getSourceId(), game + ); + Map> powerMap = permanents + .stream() + .collect(Collectors.toMap( + permanent -> permanent.getPower().getValue(), + permanent -> Arrays.asList(permanent), + (a1, a2) -> { + a1.addAll(a2); + return a1; + })); + Set toKeep = new HashSet<>(); + for (Map.Entry> entry : powerMap.entrySet()) { + if (entry.getValue().size() == 1) { + toKeep.add(entry.getValue().get(0).getId()); + continue; + } + FilterPermanent filter = new FilterCreaturePermanent("creature with power " + entry.getKey() + " to save"); + filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, entry.getKey())); + TargetPermanent target = new TargetPermanent(filter); + target.setNotTarget(true); + player.choose(outcome, target, source.getSourceId(), game); + toKeep.add(target.getFirstTarget()); + } + for (Permanent permanent : permanents) { + if (!toKeep.contains(permanent.getId())) { + permanent.destroy(source, game); + } + } + return true; + } +} diff --git a/Mage.Sets/src/mage/sets/MidnightHuntCommander.java b/Mage.Sets/src/mage/sets/MidnightHuntCommander.java index 14cd84472b..3365f86286 100644 --- a/Mage.Sets/src/mage/sets/MidnightHuntCommander.java +++ b/Mage.Sets/src/mage/sets/MidnightHuntCommander.java @@ -36,6 +36,7 @@ public final class MidnightHuntCommander extends ExpansionSet { cards.add(new SetCardInfo("Butcher of Malakir", 107, Rarity.RARE, mage.cards.b.ButcherOfMalakir.class)); cards.add(new SetCardInfo("Canopy Vista", 168, Rarity.RARE, mage.cards.c.CanopyVista.class)); cards.add(new SetCardInfo("Celebrate the Harvest", 24, Rarity.RARE, mage.cards.c.CelebrateTheHarvest.class)); + cards.add(new SetCardInfo("Celestial Judgment", 5, Rarity.RARE, mage.cards.c.CelestialJudgment.class)); cards.add(new SetCardInfo("Cemetery Reaper", 108, Rarity.RARE, mage.cards.c.CemeteryReaper.class)); cards.add(new SetCardInfo("Champion of Lambholt", 136, Rarity.RARE, mage.cards.c.ChampionOfLambholt.class)); cards.add(new SetCardInfo("Charcoal Diamond", 158, Rarity.COMMON, mage.cards.c.CharcoalDiamond.class));