diff --git a/Mage.Sets/src/mage/cards/i/IvyGleefulSpellthief.java b/Mage.Sets/src/mage/cards/i/IvyGleefulSpellthief.java new file mode 100644 index 0000000000..25a8fd3fee --- /dev/null +++ b/Mage.Sets/src/mage/cards/i/IvyGleefulSpellthief.java @@ -0,0 +1,143 @@ +package mage.cards.i; + +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.SpellCastAllTriggeredAbility; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.keyword.FlyingAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.SubType; +import mage.constants.SuperType; +import mage.filter.FilterSpell; +import mage.filter.predicate.ObjectSourcePlayer; +import mage.filter.predicate.ObjectSourcePlayerPredicate; +import mage.filter.predicate.mageobject.MageObjectReferencePredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.game.stack.Spell; +import mage.game.stack.StackObject; +import mage.target.Target; +import mage.util.TargetAddress; +import mage.util.functions.StackObjectCopyApplier; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class IvyGleefulSpellthief extends CardImpl { + + private static final FilterSpell filter + = new FilterSpell("a spell that targets only a single creature other than {this}"); + + static { + filter.add(IvyGleefulSpellthiefPredicate.instance); + } + + public IvyGleefulSpellthief(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{G}{U}"); + + this.addSuperType(SuperType.LEGENDARY); + this.subtype.add(SubType.FAERIE); + this.subtype.add(SubType.ROGUE); + this.power = new MageInt(2); + this.toughness = new MageInt(1); + + // Flying + this.addAbility(FlyingAbility.getInstance()); + + // Whenever a player casts a spell that targets only a single creature other than Ivy, Gleeful Spellthief, you may copy that spell. The copy targets Ivy. + this.addAbility(new SpellCastAllTriggeredAbility(new IvyGleefulSpellthiefEffect(), filter, true)); + } + + private IvyGleefulSpellthief(final IvyGleefulSpellthief card) { + super(card); + } + + @Override + public IvyGleefulSpellthief copy() { + return new IvyGleefulSpellthief(this); + } +} + +enum IvyGleefulSpellthiefPredicate implements ObjectSourcePlayerPredicate { + instance; + + @Override + public boolean apply(ObjectSourcePlayer input, Game game) { + Spell spell = input.getObject(); + if (spell == null) { + return false; + } + UUID singleTarget = null; + for (TargetAddress addr : TargetAddress.walk(spell)) { + Target targetInstance = addr.getTarget(spell); + for (UUID targetId : targetInstance.getTargets()) { + if (singleTarget == null) { + singleTarget = targetId; + } else if (!singleTarget.equals(targetId)) { + return false; + } + } + } + if (singleTarget == null) { + return false; + } + Permanent permanent = game.getPermanent(singleTarget); + return permanent != null + && permanent.isCreature(game) + && !permanent.getId().equals(input.getSourceId()); + } +} + +class IvyGleefulSpellthiefEffect extends OneShotEffect { + + private static final class IvyGleefulSpellthiefApplier implements StackObjectCopyApplier { + + private final MageObjectReferencePredicate morPredicate; + + IvyGleefulSpellthiefApplier(Permanent permanent, Game game) { + this.morPredicate = new MageObjectReferencePredicate(permanent, game); + } + + @Override + public void modifySpell(StackObject stackObject, Game game) { + } + + @Override + public MageObjectReferencePredicate getNextNewTargetType(int copyNumber) { + return copyNumber == 0 ? morPredicate : null; + } + } + + IvyGleefulSpellthiefEffect() { + super(Outcome.Benefit); + staticText = "copy that spell. The copy targets {this}"; + } + + private IvyGleefulSpellthiefEffect(final IvyGleefulSpellthiefEffect effect) { + super(effect); + } + + @Override + public IvyGleefulSpellthiefEffect copy() { + return new IvyGleefulSpellthiefEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Spell spell = (Spell) getValue("spellCast"); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); + if (spell == null || permanent == null) { + return false; + } + spell.createCopyOnStack( + game, source, source.getControllerId(), false, + 1, new IvyGleefulSpellthiefApplier(permanent, game) + ); + return true; + } +} diff --git a/Mage.Sets/src/mage/sets/DominariaUnited.java b/Mage.Sets/src/mage/sets/DominariaUnited.java index 9e2caa0f53..0654bdb294 100644 --- a/Mage.Sets/src/mage/sets/DominariaUnited.java +++ b/Mage.Sets/src/mage/sets/DominariaUnited.java @@ -132,6 +132,7 @@ public final class DominariaUnited extends ExpansionSet { cards.add(new SetCardInfo("In Thrall to the Pit", 132, Rarity.COMMON, mage.cards.i.InThrallToThePit.class)); cards.add(new SetCardInfo("Inscribed Tablet", 232, Rarity.UNCOMMON, mage.cards.i.InscribedTablet.class)); cards.add(new SetCardInfo("Island", 265, Rarity.LAND, mage.cards.basiclands.Island.class, NON_FULL_USE_VARIOUS)); + cards.add(new SetCardInfo("Ivy, Gleeful Spellthief", 201, Rarity.RARE, mage.cards.i.IvyGleefulSpellthief.class)); cards.add(new SetCardInfo("Jaya's Firenado", 134, Rarity.COMMON, mage.cards.j.JayasFirenado.class)); cards.add(new SetCardInfo("Jaya, Fiery Negotiator", 133, Rarity.MYTHIC, mage.cards.j.JayaFieryNegotiator.class)); cards.add(new SetCardInfo("Jhoira, Ageless Innovator", 202, Rarity.RARE, mage.cards.j.JhoiraAgelessInnovator.class));