From 093f37b8bdee81c032d601339d04fe5533b55b70 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Wed, 7 Jul 2021 20:46:14 -0400 Subject: [PATCH] [AFR] Implemented Sphere of Annihilation --- .../mage/cards/s/SphereOfAnnihilation.java | 97 +++++++++++++++++++ .../sets/AdventuresInTheForgottenRealms.java | 1 + 2 files changed, 98 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/s/SphereOfAnnihilation.java diff --git a/Mage.Sets/src/mage/cards/s/SphereOfAnnihilation.java b/Mage.Sets/src/mage/cards/s/SphereOfAnnihilation.java new file mode 100644 index 00000000000..aaadd0bb4da --- /dev/null +++ b/Mage.Sets/src/mage/cards/s/SphereOfAnnihilation.java @@ -0,0 +1,97 @@ +package mage.cards.s; + +import mage.abilities.Ability; +import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; +import mage.abilities.common.EntersBattlefieldAbility; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.EntersBattlefieldWithXCountersEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.cards.Cards; +import mage.cards.CardsImpl; +import mage.constants.*; +import mage.counters.CounterType; +import mage.filter.FilterPermanent; +import mage.filter.StaticFilters; +import mage.filter.predicate.mageobject.ManaValuePredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; + +import java.util.Collection; +import java.util.Objects; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class SphereOfAnnihilation extends CardImpl { + + public SphereOfAnnihilation(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{X}{B}"); + + // Sphere of Annihilation enters the battlefield with X void counters on it. + this.addAbility(new EntersBattlefieldAbility( + new EntersBattlefieldWithXCountersEffect(CounterType.VOID.createInstance()) + )); + + // At the beginning of your upkeep, exile Sphere of Annihilation, all creatures and planeswalkers with mana value less than or equal to the number of void counters on it, and all creature and planeswalker cards in all graveyards with mana value less than or equal to the number of void counters on it. + this.addAbility(new BeginningOfUpkeepTriggeredAbility( + new SphereOfAnnihilationEffect(), TargetController.YOU, false + )); + } + + private SphereOfAnnihilation(final SphereOfAnnihilation card) { + super(card); + } + + @Override + public SphereOfAnnihilation copy() { + return new SphereOfAnnihilation(this); + } +} + +class SphereOfAnnihilationEffect extends OneShotEffect { + + SphereOfAnnihilationEffect() { + super(Outcome.Benefit); + staticText = "exile {this}, all creatures and planeswalkers with mana value less than or equal to " + + "the number of void counters on it, and all creature and planeswalker cards in all graveyards " + + "with mana value less than or equal to the number of void counters on it"; + } + + private SphereOfAnnihilationEffect(final SphereOfAnnihilationEffect effect) { + super(effect); + } + + @Override + public SphereOfAnnihilationEffect copy() { + return new SphereOfAnnihilationEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + Permanent permanent = source.getSourcePermanentOrLKI(game); + if (player == null || permanent == null) { + return false; + } + Cards cards = new CardsImpl(permanent); + int counters = permanent.getCounters(game).getCount(CounterType.VOID); + FilterPermanent filter = StaticFilters.FILTER_PERMANENT_CREATURE_OR_PLANESWALKER.copy(); + filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, counters + 1)); + cards.addAll(game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)); + game.getState() + .getPlayersInRange(source.getControllerId(), game) + .stream() + .map(game::getPlayer) + .filter(Objects::nonNull) + .map(Player::getGraveyard) + .map(g -> g.getCards(game)) + .flatMap(Collection::stream) + .filter(card -> card.isCreature() || card.isPlaneswalker()) + .filter(card -> card.getManaValue() <= counters) + .forEach(cards::add); + return player.moveCards(cards, Zone.EXILED, source, game); + } +} diff --git a/Mage.Sets/src/mage/sets/AdventuresInTheForgottenRealms.java b/Mage.Sets/src/mage/sets/AdventuresInTheForgottenRealms.java index 132d3e6073a..f56701775bf 100644 --- a/Mage.Sets/src/mage/sets/AdventuresInTheForgottenRealms.java +++ b/Mage.Sets/src/mage/sets/AdventuresInTheForgottenRealms.java @@ -190,6 +190,7 @@ public final class AdventuresInTheForgottenRealms extends ExpansionSet { cards.add(new SetCardInfo("Skeletal Swarming", 232, Rarity.RARE, mage.cards.s.SkeletalSwarming.class)); cards.add(new SetCardInfo("Skullport Merchant", 120, Rarity.UNCOMMON, mage.cards.s.SkullportMerchant.class)); cards.add(new SetCardInfo("Soulknife Spy", 75, Rarity.COMMON, mage.cards.s.SoulknifeSpy.class)); + cards.add(new SetCardInfo("Sphere of Annihilation", 121, Rarity.RARE, mage.cards.s.SphereOfAnnihilation.class)); cards.add(new SetCardInfo("Spike Pit Trap", 251, Rarity.COMMON, mage.cards.s.SpikePitTrap.class)); cards.add(new SetCardInfo("Split the Party", 76, Rarity.UNCOMMON, mage.cards.s.SplitTheParty.class)); cards.add(new SetCardInfo("Steadfast Paladin", 38, Rarity.COMMON, mage.cards.s.SteadfastPaladin.class));