From ac89884087518f2371bca7034b378b219ae1f570 Mon Sep 17 00:00:00 2001 From: Susucre <34709007+Susucre@users.noreply.github.com> Date: Sat, 4 Nov 2023 17:59:39 +0100 Subject: [PATCH] [LCI] Implement Bringer of the Last Gift --- .../mage/cards/b/BringerOfTheLastGift.java | 112 ++++++++++++++++++ .../src/mage/sets/TheLostCavernsOfIxalan.java | 1 + 2 files changed, 113 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/b/BringerOfTheLastGift.java diff --git a/Mage.Sets/src/mage/cards/b/BringerOfTheLastGift.java b/Mage.Sets/src/mage/cards/b/BringerOfTheLastGift.java new file mode 100644 index 00000000000..e125c3d5384 --- /dev/null +++ b/Mage.Sets/src/mage/cards/b/BringerOfTheLastGift.java @@ -0,0 +1,112 @@ +package mage.cards.b; + +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.EntersBattlefieldTriggeredAbility; +import mage.abilities.condition.common.CastFromEverywhereSourceCondition; +import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.keyword.FlyingAbility; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.SubType; +import mage.constants.Zone; +import mage.filter.StaticFilters; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * @author Susucr + */ +public final class BringerOfTheLastGift extends CardImpl { + + public BringerOfTheLastGift(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{6}{B}{B}"); + + this.subtype.add(SubType.VAMPIRE); + this.subtype.add(SubType.DEMON); + this.power = new MageInt(6); + this.toughness = new MageInt(6); + + // Flying + this.addAbility(FlyingAbility.getInstance()); + + // When Bringer of the Last Gift enters the battlefield, if you cast it, each player sacrifices all other creatures they control. Then each player returns all creature cards from their graveyard that weren't put there this way to the battlefield. + this.addAbility(new ConditionalInterveningIfTriggeredAbility( + new EntersBattlefieldTriggeredAbility(new BringerOfTheLastGiftEffect()), + CastFromEverywhereSourceCondition.instance, + "When {this} enters the battlefield, if you cast it, each player sacrifices all other creatures they control. " + + "Then each player returns all creature cards from their graveyard that weren't put there this way to the battlefield." + )); + } + + private BringerOfTheLastGift(final BringerOfTheLastGift card) { + super(card); + } + + @Override + public BringerOfTheLastGift copy() { + return new BringerOfTheLastGift(this); + } +} + +class BringerOfTheLastGiftEffect extends OneShotEffect { + + BringerOfTheLastGiftEffect() { + super(Outcome.Benefit); + } + + private BringerOfTheLastGiftEffect(final BringerOfTheLastGiftEffect effect) { + super(effect); + } + + @Override + public BringerOfTheLastGiftEffect copy() { + return new BringerOfTheLastGiftEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller == null) { + return false; + } + + // per player affected, all cards that should not return on the second part. + List toSacrifice = new ArrayList<>(); + for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) { + toSacrifice.addAll(game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, playerId, game)); + } + + Set notReturned = new HashSet<>(); + for (Permanent p : toSacrifice) { + if (p.getId().equals(source.getSourceId())) { + continue; + } + p.sacrifice(source, game); + notReturned.add(p.getMainCard().getId()); + } + + Set toReturn = new HashSet<>(); + for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) { + Player player = game.getPlayer(playerId); + if (player == null) { + continue; + } + + toReturn.addAll(player.getGraveyard().getCards(StaticFilters.FILTER_CARD_CREATURE, game)); + } + + toReturn.removeAll(notReturned.stream().map(game::getCard).collect(Collectors.toSet())); + controller.moveCards(toReturn, Zone.BATTLEFIELD, source, game, false, false, true, null); + return true; + } + +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/TheLostCavernsOfIxalan.java b/Mage.Sets/src/mage/sets/TheLostCavernsOfIxalan.java index 6fa4965cda1..a4948271fe2 100644 --- a/Mage.Sets/src/mage/sets/TheLostCavernsOfIxalan.java +++ b/Mage.Sets/src/mage/sets/TheLostCavernsOfIxalan.java @@ -46,6 +46,7 @@ public final class TheLostCavernsOfIxalan extends ExpansionSet { cards.add(new SetCardInfo("Brackish Blunder", 46, Rarity.COMMON, mage.cards.b.BrackishBlunder.class)); cards.add(new SetCardInfo("Brazen Blademaster", 136, Rarity.COMMON, mage.cards.b.BrazenBlademaster.class)); cards.add(new SetCardInfo("Breeches, Eager Pillager", 137, Rarity.RARE, mage.cards.b.BreechesEagerPillager.class)); + cards.add(new SetCardInfo("Bringer of the Last Gift", 94, Rarity.RARE, mage.cards.b.BringerOfTheLastGift.class)); cards.add(new SetCardInfo("Broodrage Mycoid", 95, Rarity.COMMON, mage.cards.b.BroodrageMycoid.class)); cards.add(new SetCardInfo("Buried Treasure", 246, Rarity.COMMON, mage.cards.b.BuriedTreasure.class)); cards.add(new SetCardInfo("Burning Sun Cavalry", 138, Rarity.COMMON, mage.cards.b.BurningSunCavalry.class));