From 3c67694c7fc506bcac5d558d3866a827f96250cd Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Mon, 22 Jul 2019 11:48:49 -0400 Subject: [PATCH] implemented Mind Extraction --- .../src/mage/cards/m/MindExtraction.java | 107 ++++++++++++++++++ Mage.Sets/src/mage/sets/Apocalypse.java | 1 + 2 files changed, 108 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/m/MindExtraction.java diff --git a/Mage.Sets/src/mage/cards/m/MindExtraction.java b/Mage.Sets/src/mage/cards/m/MindExtraction.java new file mode 100644 index 00000000000..b92c5db95ff --- /dev/null +++ b/Mage.Sets/src/mage/cards/m/MindExtraction.java @@ -0,0 +1,107 @@ +package mage.cards.m; + +import mage.ObjectColor; +import mage.abilities.Ability; +import mage.abilities.costs.Cost; +import mage.abilities.costs.common.SacrificeTargetCost; +import mage.abilities.effects.OneShotEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.cards.Cards; +import mage.cards.CardsImpl; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.filter.StaticFilters; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.TargetPlayer; +import mage.target.common.TargetControlledCreaturePermanent; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class MindExtraction extends CardImpl { + + public MindExtraction(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{2}{B}"); + + // As an additional cost to cast this spell, sacrifice a creature. + this.getSpellAbility().addCost(new SacrificeTargetCost(new TargetControlledCreaturePermanent( + 1, 1, StaticFilters.FILTER_CONTROLLED_CREATURE_SHORT_TEXT, false + ))); + + // Target player reveals their hand and discards all cards of each of the sacrificed creature’s colors. + this.getSpellAbility().addEffect(new MindExtractionEffect()); + this.getSpellAbility().addTarget(new TargetPlayer()); + } + + private MindExtraction(final MindExtraction card) { + super(card); + } + + @Override + public MindExtraction copy() { + return new MindExtraction(this); + } +} + +class MindExtractionEffect extends OneShotEffect { + + MindExtractionEffect() { + super(Outcome.Benefit); + staticText = "Target player reveals their hand and discards all cards of each of the sacrificed creature’s colors."; + } + + private MindExtractionEffect(final MindExtractionEffect effect) { + super(effect); + } + + @Override + public MindExtractionEffect copy() { + return new MindExtractionEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + Player player = game.getPlayer(source.getFirstTarget()); + if (controller == null || player == null) { + return false; + } + Permanent sacrificedCreature = null; + for (Cost cost : source.getCosts()) { + if (!(cost instanceof SacrificeTargetCost)) { + continue; + } + SacrificeTargetCost sacCost = (SacrificeTargetCost) cost; + for (Permanent permanent : sacCost.getPermanents()) { + sacrificedCreature = permanent; + break; + } + } + if (sacrificedCreature == null) { + return false; + } + ObjectColor color = sacrificedCreature.getColor(game); + Cards cards = new CardsImpl(player.getHand()); + if (cards.isEmpty()) { + return true; + } + player.revealCards(source, cards, game); + if (color.isColorless()) { + return true; + } + Cards toDiscard = new CardsImpl(); + cards.getCards(game) + .stream() + .filter(card -> card.getColor(game).shares(color)) + .forEach(toDiscard::add); + toDiscard.getCards(game) + .stream() + .forEach(card -> player.discard(card, source, game)); + return true; + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/Apocalypse.java b/Mage.Sets/src/mage/sets/Apocalypse.java index b1453762a48..e327b2f80cf 100644 --- a/Mage.Sets/src/mage/sets/Apocalypse.java +++ b/Mage.Sets/src/mage/sets/Apocalypse.java @@ -99,6 +99,7 @@ public final class Apocalypse extends ExpansionSet { cards.add(new SetCardInfo("Manacles of Decay", 14, Rarity.COMMON, mage.cards.m.ManaclesOfDecay.class)); cards.add(new SetCardInfo("Martyrs' Tomb", 110, Rarity.UNCOMMON, mage.cards.m.MartyrsTomb.class)); cards.add(new SetCardInfo("Mask of Intolerance", 138, Rarity.RARE, mage.cards.m.MaskOfIntolerance.class)); + cards.add(new SetCardInfo("Mind Extraction", 42, Rarity.COMMON, mage.cards.m.MindExtraction.class)); cards.add(new SetCardInfo("Minotaur Illusionist", 111, Rarity.UNCOMMON, mage.cards.m.MinotaurIllusionist.class)); cards.add(new SetCardInfo("Minotaur Tactician", 65, Rarity.COMMON, mage.cards.m.MinotaurTactician.class)); cards.add(new SetCardInfo("Mournful Zombie", 43, Rarity.COMMON, mage.cards.m.MournfulZombie.class));