From 80e7593bb1404621857461a902f82643462a795d Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Sat, 6 Apr 2019 10:06:18 -0400 Subject: [PATCH] Implemented Kaya's Ghostform --- .../src/mage/cards/k/KayasGhostform.java | 112 ++++++++++++++++++ Mage.Sets/src/mage/sets/WarOfTheSpark.java | 1 + 2 files changed, 113 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/k/KayasGhostform.java diff --git a/Mage.Sets/src/mage/cards/k/KayasGhostform.java b/Mage.Sets/src/mage/cards/k/KayasGhostform.java new file mode 100644 index 0000000000..277d139bc4 --- /dev/null +++ b/Mage.Sets/src/mage/cards/k/KayasGhostform.java @@ -0,0 +1,112 @@ +package mage.cards.k; + +import mage.abilities.Ability; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.common.AttachEffect; +import mage.abilities.effects.common.ReturnToBattlefieldUnderYourControlAttachedEffect; +import mage.abilities.keyword.EnchantAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.filter.FilterPermanent; +import mage.filter.common.FilterCreatureOrPlaneswalkerPermanent; +import mage.filter.predicate.permanent.ControllerPredicate; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.ZoneChangeEvent; +import mage.game.permanent.Permanent; +import mage.target.TargetPermanent; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class KayasGhostform extends CardImpl { + + private static final FilterPermanent filter + = new FilterCreatureOrPlaneswalkerPermanent("creature or planeswalker you control"); + + static { + filter.add(new ControllerPredicate(TargetController.YOU)); + } + + public KayasGhostform(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{B}"); + + this.subtype.add(SubType.AURA); + + // Enchant creature or planeswalker you control + TargetPermanent auraTarget = new TargetPermanent(filter); + this.getSpellAbility().addTarget(auraTarget); + this.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature)); + Ability ability = new EnchantAbility(auraTarget.getTargetName()); + this.addAbility(ability); + + // When enchanted permanent dies or is put into exile, return that card to the battlefield under your control. + this.addAbility(new KayasGhostformTriggeredAbility()); + } + + private KayasGhostform(final KayasGhostform card) { + super(card); + } + + @Override + public KayasGhostform copy() { + return new KayasGhostform(this); + } +} + +class KayasGhostformTriggeredAbility extends TriggeredAbilityImpl { + + KayasGhostformTriggeredAbility() { + super(Zone.ALL, new ReturnToBattlefieldUnderYourControlAttachedEffect(), false); + } + + private KayasGhostformTriggeredAbility(final KayasGhostformTriggeredAbility ability) { + super(ability); + } + + @Override + public KayasGhostformTriggeredAbility copy() { + return new KayasGhostformTriggeredAbility(this); + } + + @Override + public boolean checkEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.ZONE_CHANGE; + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + ZoneChangeEvent zEvent = (ZoneChangeEvent) event; + if (zEvent.getFromZone() != Zone.BATTLEFIELD + || !(zEvent.getToZone() == Zone.GRAVEYARD || zEvent.getToZone() == Zone.EXILED)) { + return false; + } + if (zEvent.getTarget() != null && zEvent.getTarget().getAttachments() != null + && zEvent.getTarget().getAttachments().contains(this.getSourceId())) { + return true; + } else { + // If both (attachment and attached went to graveyard at the same time, the attachemnets can be already removed from the attached object.) + // So check here with the LKI of the enchantment + Permanent attachment = game.getPermanentOrLKIBattlefield(getSourceId()); + if (attachment != null + && zEvent.getTargetId() != null && attachment.getAttachedTo() != null + && zEvent.getTargetId().equals(attachment.getAttachedTo())) { + Permanent attachedTo = game.getPermanentOrLKIBattlefield(attachment.getAttachedTo()); + if (attachedTo != null + && attachment.getAttachedToZoneChangeCounter() == attachedTo.getZoneChangeCounter(game)) { // zoneChangeCounter is stored in Permanent + return true; + } + } + } + return false; + } + + @Override + public String getRule() { + return "When enchanted permanent dies or is put into exile, " + + "return that card to the battlefield under your control."; + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/WarOfTheSpark.java b/Mage.Sets/src/mage/sets/WarOfTheSpark.java index ba27720d2d..390c5890de 100644 --- a/Mage.Sets/src/mage/sets/WarOfTheSpark.java +++ b/Mage.Sets/src/mage/sets/WarOfTheSpark.java @@ -78,6 +78,7 @@ public final class WarOfTheSpark extends ExpansionSet { cards.add(new SetCardInfo("Jace, Wielder of Mysteries", 54, Rarity.RARE, mage.cards.j.JaceWielderOfMysteries.class)); cards.add(new SetCardInfo("Jiang Yanggu, Wildcrafter", 164, Rarity.UNCOMMON, mage.cards.j.JiangYangguWildcrafter.class)); cards.add(new SetCardInfo("Karn's Bastion", 248, Rarity.RARE, mage.cards.k.KarnsBastion.class)); + cards.add(new SetCardInfo("Kaya's Ghostform", 94, Rarity.COMMON, mage.cards.k.KayasGhostform.class)); cards.add(new SetCardInfo("Kaya, Bane of the Dead", 231, Rarity.UNCOMMON, mage.cards.k.KayaBaneOfTheDead.class)); cards.add(new SetCardInfo("Kiora's Dambreaker", 58, Rarity.COMMON, mage.cards.k.KiorasDambreaker.class)); cards.add(new SetCardInfo("Kiora, Behemoth Beckoner", 232, Rarity.UNCOMMON, mage.cards.k.KioraBehemothBeckoner.class));