From d2a74e90621128f1c43f20f430504c232234f4a4 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Thu, 18 Apr 2019 19:51:25 -0400 Subject: [PATCH] Implemented Ugin, the Ineffable --- .../src/mage/cards/u/UginTheIneffable.java | 161 ++++++++++++++++++ Mage.Sets/src/mage/sets/WarOfTheSpark.java | 1 + .../token/UginTheIneffableToken.java | 29 ++++ .../target/targetpointer/FixedTarget.java | 14 +- 4 files changed, 201 insertions(+), 4 deletions(-) create mode 100644 Mage.Sets/src/mage/cards/u/UginTheIneffable.java create mode 100644 Mage/src/main/java/mage/game/permanent/token/UginTheIneffableToken.java diff --git a/Mage.Sets/src/mage/cards/u/UginTheIneffable.java b/Mage.Sets/src/mage/cards/u/UginTheIneffable.java new file mode 100644 index 0000000000..59aa2e74e5 --- /dev/null +++ b/Mage.Sets/src/mage/cards/u/UginTheIneffable.java @@ -0,0 +1,161 @@ +package mage.cards.u; + +import mage.MageObjectReference; +import mage.abilities.Ability; +import mage.abilities.DelayedTriggeredAbility; +import mage.abilities.LoyaltyAbility; +import mage.abilities.common.PlaneswalkerEntersWithLoyaltyCountersAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.Effect; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.DestroyTargetEffect; +import mage.abilities.effects.common.ReturnToHandTargetEffect; +import mage.abilities.effects.common.cost.SpellsCostReductionControllerEffect; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.filter.FilterCard; +import mage.filter.FilterPermanent; +import mage.filter.predicate.Predicates; +import mage.filter.predicate.mageobject.ColorlessPredicate; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.ZoneChangeEvent; +import mage.game.permanent.Permanent; +import mage.game.permanent.token.Token; +import mage.game.permanent.token.UginTheIneffableToken; +import mage.players.Player; +import mage.target.TargetPermanent; +import mage.target.targetpointer.FixedTarget; + +import java.util.UUID; + +import static mage.constants.Outcome.Benefit; + +/** + * @author TheElk801 + */ +public final class UginTheIneffable extends CardImpl { + + private static final FilterCard filter = new FilterCard(); + private static final FilterPermanent filter2 = new FilterPermanent("permanent that's one or more colors"); + + static { + filter.add(ColorlessPredicate.instance); + filter2.add(Predicates.not(ColorlessPredicate.instance)); + } + + public UginTheIneffable(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.PLANESWALKER}, "{6}"); + + this.addSuperType(SuperType.LEGENDARY); + this.subtype.add(SubType.UGIN); + this.addAbility(new PlaneswalkerEntersWithLoyaltyCountersAbility(4)); + + // Colorless spells you cast cost {2} less to cast. + this.addAbility(new SimpleStaticAbility(new SpellsCostReductionControllerEffect( + filter, 2 + ).setText("Colorless spells you cast cost {2} less to cast."))); + + // +1: Exile the top card of your library face down and look at it. Create a 2/2 colorless Spirit creature token. When that token leaves the battlefield, put the exiled card into your hand. + this.addAbility(new LoyaltyAbility(new UginTheIneffableEffect(), 1)); + + // -3: Destroy target permanent that's one or more colors. + Ability ability = new LoyaltyAbility(new DestroyTargetEffect(), -3); + ability.addTarget(new TargetPermanent()); + this.addAbility(ability); + } + + private UginTheIneffable(final UginTheIneffable card) { + super(card); + } + + @Override + public UginTheIneffable copy() { + return new UginTheIneffable(this); + } +} + +class UginTheIneffableEffect extends OneShotEffect { + + UginTheIneffableEffect() { + super(Benefit); + staticText = "Exile the top card of your library face down and look at it. " + + "Create a 2/2 colorless Spirit creature token. When that token leaves the battlefield, " + + "put the exiled card into your hand."; + } + + private UginTheIneffableEffect(final UginTheIneffableEffect effect) { + super(effect); + } + + @Override + public UginTheIneffableEffect copy() { + return new UginTheIneffableEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId()); + Player player = game.getPlayer(source.getControllerId()); + if (player == null) { + return false; + } + Card card = player.getLibrary().getFromTop(game); + player.lookAtCards(sourcePermanent.getIdName(), card, game); + player.moveCards(card, Zone.EXILED, source, game); + card.turnFaceDown(game, source.getControllerId()); + Token token = new UginTheIneffableToken(); + token.putOntoBattlefield(1, game, source.getSourceId(), source.getControllerId()); + game.addDelayedTriggeredAbility(new UginTheIneffableDelayedTriggeredAbility( + new MageObjectReference(token.getLastAddedToken(), game), new MageObjectReference(card, game) + ), source); + return true; + } +} + +class UginTheIneffableDelayedTriggeredAbility extends DelayedTriggeredAbility { + + private final MageObjectReference tokenRef; + private final MageObjectReference cardRef; + + UginTheIneffableDelayedTriggeredAbility(MageObjectReference token, MageObjectReference card) { + super(null, Duration.Custom, true); + this.tokenRef = token; + this.cardRef = card; + } + + private UginTheIneffableDelayedTriggeredAbility(final UginTheIneffableDelayedTriggeredAbility ability) { + super(ability); + this.tokenRef = ability.tokenRef; + this.cardRef = ability.cardRef; + } + + @Override + public boolean checkEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.ZONE_CHANGE; + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (tokenRef.refersTo(((ZoneChangeEvent) event).getTarget(), game)) { + this.getEffects().clear(); + Effect effect = new ReturnToHandTargetEffect(); + effect.setTargetPointer(new FixedTarget(cardRef)); + this.addEffect(effect); + return true; + } + return false; + } + + @Override + public UginTheIneffableDelayedTriggeredAbility copy() { + return new UginTheIneffableDelayedTriggeredAbility(this); + } + + @Override + public String getRule() { + return "When this token leaves the battlefield, put the exiled card into your hand."; + } +} diff --git a/Mage.Sets/src/mage/sets/WarOfTheSpark.java b/Mage.Sets/src/mage/sets/WarOfTheSpark.java index ab9a9e634c..54159ef59a 100644 --- a/Mage.Sets/src/mage/sets/WarOfTheSpark.java +++ b/Mage.Sets/src/mage/sets/WarOfTheSpark.java @@ -272,6 +272,7 @@ public final class WarOfTheSpark extends ExpansionSet { cards.add(new SetCardInfo("Trusted Pegasus", 36, Rarity.COMMON, mage.cards.t.TrustedPegasus.class)); cards.add(new SetCardInfo("Turret Ogre", 148, Rarity.COMMON, mage.cards.t.TurretOgre.class)); cards.add(new SetCardInfo("Tyrant's Scorn", 225, Rarity.UNCOMMON, mage.cards.t.TyrantsScorn.class)); + cards.add(new SetCardInfo("Ugin, the Ineffable", 2, Rarity.RARE, mage.cards.u.UginTheIneffable.class)); cards.add(new SetCardInfo("Unlikely Aid", 109, Rarity.COMMON, mage.cards.u.UnlikelyAid.class)); cards.add(new SetCardInfo("Vampire Opportunist", 110, Rarity.COMMON, mage.cards.v.VampireOpportunist.class)); cards.add(new SetCardInfo("Vivien's Arkbow", 181, Rarity.RARE, mage.cards.v.ViviensArkbow.class)); diff --git a/Mage/src/main/java/mage/game/permanent/token/UginTheIneffableToken.java b/Mage/src/main/java/mage/game/permanent/token/UginTheIneffableToken.java new file mode 100644 index 0000000000..8bbb0002e2 --- /dev/null +++ b/Mage/src/main/java/mage/game/permanent/token/UginTheIneffableToken.java @@ -0,0 +1,29 @@ +package mage.game.permanent.token; + +import mage.MageInt; +import mage.constants.CardType; +import mage.constants.SubType; + +/** + * @author TheElk801 + */ +public final class UginTheIneffableToken extends TokenImpl { + + public UginTheIneffableToken() { + super("Spirit", "2/2 colorless Spirit creature token"); + setExpansionSetCodeForImage("WAR"); // default + cardType.add(CardType.CREATURE); + subtype.add(SubType.SPIRIT); + power = new MageInt(2); + toughness = new MageInt(2); + } + + private UginTheIneffableToken(final UginTheIneffableToken token) { + super(token); + } + + @Override + public UginTheIneffableToken copy() { + return new UginTheIneffableToken(this); + } +} diff --git a/Mage/src/main/java/mage/target/targetpointer/FixedTarget.java b/Mage/src/main/java/mage/target/targetpointer/FixedTarget.java index c8a14e5c27..06a2eaf0e4 100644 --- a/Mage/src/main/java/mage/target/targetpointer/FixedTarget.java +++ b/Mage/src/main/java/mage/target/targetpointer/FixedTarget.java @@ -1,15 +1,17 @@ package mage.target.targetpointer; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.UUID; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.cards.Card; import mage.constants.Zone; import mage.game.Game; import mage.game.permanent.Permanent; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.UUID; + public class FixedTarget implements TargetPointer { private final UUID targetId; @@ -21,6 +23,10 @@ public class FixedTarget implements TargetPointer { this.initialized = false; } + public FixedTarget(MageObjectReference mor) { + this(mor.getSourceId(), mor.getZoneChangeCounter()); + } + public FixedTarget(Card card, Game game) { this.targetId = card.getId(); this.zoneChangeCounter = card.getZoneChangeCounter(game);