From 3407a3e7423a29f472f6d5210f0c56da4a0a8ab1 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Sat, 28 Jul 2018 20:10:24 -0400 Subject: [PATCH] Implemented Coveted Jewel --- Mage.Sets/src/mage/cards/c/CovetedJewel.java | 135 +++++++++++++++++++ Mage.Sets/src/mage/sets/Commander2018.java | 1 + 2 files changed, 136 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/c/CovetedJewel.java diff --git a/Mage.Sets/src/mage/cards/c/CovetedJewel.java b/Mage.Sets/src/mage/cards/c/CovetedJewel.java new file mode 100644 index 0000000000..63007242df --- /dev/null +++ b/Mage.Sets/src/mage/cards/c/CovetedJewel.java @@ -0,0 +1,135 @@ +package mage.cards.c; + +import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.EntersBattlefieldTriggeredAbility; +import mage.abilities.costs.common.TapSourceCost; +import mage.abilities.effects.ContinuousEffectImpl; +import mage.abilities.effects.common.DrawCardSourceControllerEffect; +import mage.abilities.effects.common.DrawCardTargetEffect; +import mage.abilities.effects.common.UntapSourceEffect; +import mage.abilities.effects.mana.AddManaOfAnyColorEffect; +import mage.abilities.mana.SimpleManaAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Layer; +import mage.constants.Outcome; +import mage.constants.SubLayer; +import mage.constants.Zone; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.targetpointer.FixedTarget; + +/** + * + * @author TheElk801 + */ +public final class CovetedJewel extends CardImpl { + + public CovetedJewel(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{6}"); + + // When Coveted Jewel enters the battlefield, draw three cards. + this.addAbility(new EntersBattlefieldTriggeredAbility( + new DrawCardSourceControllerEffect(3) + )); + + // {T}: Add three mana of any one color. + this.addAbility(new SimpleManaAbility( + Zone.BATTLEFIELD, + new AddManaOfAnyColorEffect(3), + new TapSourceCost() + )); + + // Whenever one or more creatures an opponent controls attack you and aren't blocked, that player draws three cards and gains control of Coveted Jewel. Untap it. + this.addAbility(new CovetedJewelTriggeredAbility()); + } + + public CovetedJewel(final CovetedJewel card) { + super(card); + } + + @Override + public CovetedJewel copy() { + return new CovetedJewel(this); + } +} + +class CovetedJewelTriggeredAbility extends TriggeredAbilityImpl { + + public CovetedJewelTriggeredAbility() { + super(Zone.BATTLEFIELD, new DrawCardTargetEffect(3), false); + this.addEffect(new CovetedJewelEffect()); + this.addEffect(new UntapSourceEffect()); + } + + public CovetedJewelTriggeredAbility(final CovetedJewelTriggeredAbility ability) { + super(ability); + } + + @Override + public CovetedJewelTriggeredAbility copy() { + return new CovetedJewelTriggeredAbility(this); + } + + @Override + public boolean checkEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DECLARE_BLOCKERS_STEP; + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + Player player = game.getPlayer(this.getControllerId()); + if (player == null) { + return false; + } + for (UUID attacker : game.getCombat().getAttackers()) { + Permanent creature = game.getPermanent(attacker); + if (creature != null + && player.hasOpponent(creature.getControllerId(), game) + && player.getId().equals(game.getCombat().getDefendingPlayerId(attacker, game)) + && !creature.isBlocked(game)) { + this.getEffects().setTargetPointer(new FixedTarget(this.getControllerId(), game)); + return true; + } + } + return false; + } + + @Override + public String getRule() { + return "Whenever one or more creatures an opponent controls attack you " + + "and aren't blocked, that player draws three cards " + + "and gains control of {this}. Untap it."; + } +} + +class CovetedJewelEffect extends ContinuousEffectImpl { + + public CovetedJewelEffect() { + super(Duration.Custom, Layer.ControlChangingEffects_2, SubLayer.NA, Outcome.GainControl); + } + + public CovetedJewelEffect(final CovetedJewelEffect effect) { + super(effect); + } + + @Override + public CovetedJewelEffect copy() { + return new CovetedJewelEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = game.getPermanent(source.getSourceId()); + if (permanent == null) { + return false; + } + return permanent.changeControllerId(source.getFirstTarget(), game); + } +} diff --git a/Mage.Sets/src/mage/sets/Commander2018.java b/Mage.Sets/src/mage/sets/Commander2018.java index 45fd3874db..c9e1253121 100644 --- a/Mage.Sets/src/mage/sets/Commander2018.java +++ b/Mage.Sets/src/mage/sets/Commander2018.java @@ -69,6 +69,7 @@ public final class Commander2018 extends ExpansionSet { cards.add(new SetCardInfo("Commander's Sphere", 200, Rarity.COMMON, mage.cards.c.CommandersSphere.class)); cards.add(new SetCardInfo("Consign to Dust", 136, Rarity.UNCOMMON, mage.cards.c.ConsignToDust.class)); cards.add(new SetCardInfo("Conundrum Sphinx", 84, Rarity.RARE, mage.cards.c.ConundrumSphinx.class)); + cards.add(new SetCardInfo("Coveted Jewel", 54, Rarity.RARE, mage.cards.c.CovetedJewel.class)); cards.add(new SetCardInfo("Crash of Rhino Beetles", 29, Rarity.RARE, mage.cards.c.CrashOfRhinoBeetles.class)); cards.add(new SetCardInfo("Creeping Renaissance", 137, Rarity.RARE, mage.cards.c.CreepingRenaissance.class)); cards.add(new SetCardInfo("Crib Swap", 65, Rarity.UNCOMMON, mage.cards.c.CribSwap.class));