From 0cf758ea5e6e5ff7fe244f5f17f94eb205fd1376 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Thu, 15 Aug 2019 21:26:43 -0400 Subject: [PATCH] Implemented Thieving Amalgam --- .../src/mage/cards/t/ThievingAmalgam.java | 142 ++++++++++++++++++ .../src/mage/sets/Commander2019Edition.java | 1 + 2 files changed, 143 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/t/ThievingAmalgam.java diff --git a/Mage.Sets/src/mage/cards/t/ThievingAmalgam.java b/Mage.Sets/src/mage/cards/t/ThievingAmalgam.java new file mode 100644 index 00000000000..161e8a6dfd6 --- /dev/null +++ b/Mage.Sets/src/mage/cards/t/ThievingAmalgam.java @@ -0,0 +1,142 @@ +package mage.cards.t; + +import mage.MageInt; +import mage.MageObjectReference; +import mage.abilities.Ability; +import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; +import mage.abilities.common.DiesCreatureTriggeredAbility; +import mage.abilities.costs.mana.ManaCosts; +import mage.abilities.costs.mana.ManaCostsImpl; +import mage.abilities.effects.Effect; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.GainLifeEffect; +import mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.filter.FilterPermanent; +import mage.filter.common.FilterControlledCreaturePermanent; +import mage.filter.predicate.other.OwnerPredicate; +import mage.game.Game; +import mage.players.Player; + +import java.util.Set; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class ThievingAmalgam extends CardImpl { + + private static final FilterPermanent filter + = new FilterControlledCreaturePermanent("a creature you control but don't own"); + + static { + filter.add(new OwnerPredicate(TargetController.NOT_YOU)); + } + + public ThievingAmalgam(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{5}{B}{B}"); + + this.subtype.add(SubType.APE); + this.subtype.add(SubType.SNAKE); + this.power = new MageInt(6); + this.toughness = new MageInt(7); + + // At the beginning of each opponent's upkeep, you manifest the top card of that player's library. + this.addAbility(new BeginningOfUpkeepTriggeredAbility( + new ThievingAmalgamManifestEffect(), TargetController.OPPONENT, false + )); + + // Whenever a creature you control but don't own dies, its owner loses 2 life and you gain 2 life. + this.addAbility(new DiesCreatureTriggeredAbility( + new ThievingAmalgamLifeLossEffect(), false, filter, true + )); + } + + private ThievingAmalgam(final ThievingAmalgam card) { + super(card); + } + + @Override + public ThievingAmalgam copy() { + return new ThievingAmalgam(this); + } +} + +class ThievingAmalgamManifestEffect extends OneShotEffect { + + ThievingAmalgamManifestEffect() { + super(Outcome.Benefit); + staticText = "you manifest the top card of that player's library"; + } + + private ThievingAmalgamManifestEffect(final ThievingAmalgamManifestEffect effect) { + super(effect); + } + + @Override + public ThievingAmalgamManifestEffect copy() { + return new ThievingAmalgamManifestEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + Player active = game.getPlayer(game.getActivePlayerId()); + if (controller == null || active == null) { + return false; + } + Ability newSource = source.copy(); + newSource.setWorksFaceDown(true); + Set cards = active.getLibrary().getTopCards(game, 1); + cards.stream().forEach(card -> { + ManaCosts manaCosts = null; + if (card.isCreature()) { + manaCosts = card.getSpellAbility() != null ? card.getSpellAbility().getManaCosts() : null; + if (manaCosts == null) { + manaCosts = new ManaCostsImpl("{0}"); + } + } + MageObjectReference objectReference = new MageObjectReference(card.getId(), card.getZoneChangeCounter(game) + 1, game); + game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference, Duration.Custom, BecomesFaceDownCreatureEffect.FaceDownType.MANIFESTED), newSource); + }); + controller.moveCards(cards, Zone.BATTLEFIELD, source, game, false, true, false, null); + cards.stream() + .map(Card::getId) + .map(game::getPermanent) + .filter(permanent -> permanent != null) + .forEach(permanent -> permanent.setManifested(true)); + return true; + } +} + +class ThievingAmalgamLifeLossEffect extends OneShotEffect { + + private static final Effect effect = new GainLifeEffect(2); + + ThievingAmalgamLifeLossEffect() { + super(Outcome.Benefit); + staticText = "its owner loses 2 life and you gain 2 life"; + } + + private ThievingAmalgamLifeLossEffect(final ThievingAmalgamLifeLossEffect effect) { + super(effect); + } + + @Override + public ThievingAmalgamLifeLossEffect copy() { + return new ThievingAmalgamLifeLossEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(game.getOwnerId(targetPointer.getFirst(game, source))); + if (player == null) { + return false; + } + player.loseLife(2, game, false); + return effect.apply(game, source); + } +} diff --git a/Mage.Sets/src/mage/sets/Commander2019Edition.java b/Mage.Sets/src/mage/sets/Commander2019Edition.java index 0e89c25b7af..3b6c32b3b6c 100644 --- a/Mage.Sets/src/mage/sets/Commander2019Edition.java +++ b/Mage.Sets/src/mage/sets/Commander2019Edition.java @@ -275,6 +275,7 @@ public final class Commander2019Edition extends ExpansionSet { cards.add(new SetCardInfo("The Eldest Reborn", 131, Rarity.UNCOMMON, mage.cards.t.TheEldestReborn.class)); cards.add(new SetCardInfo("Thelonite Hermit", 184, Rarity.RARE, mage.cards.t.TheloniteHermit.class)); cards.add(new SetCardInfo("Thespian's Stage", 282, Rarity.RARE, mage.cards.t.ThespiansStage.class)); + cards.add(new SetCardInfo("Thieving Amalgam", 21, Rarity.RARE, mage.cards.t.ThievingAmalgam.class)); cards.add(new SetCardInfo("Think Twice", 99, Rarity.COMMON, mage.cards.t.ThinkTwice.class)); cards.add(new SetCardInfo("Thornwood Falls", 283, Rarity.COMMON, mage.cards.t.ThornwoodFalls.class)); cards.add(new SetCardInfo("Thought Sponge", 12, Rarity.RARE, mage.cards.t.ThoughtSponge.class));