diff --git a/Mage.Sets/src/mage/cards/b/BanishIntoFable.java b/Mage.Sets/src/mage/cards/b/BanishIntoFable.java new file mode 100644 index 00000000000..285f88d1ce4 --- /dev/null +++ b/Mage.Sets/src/mage/cards/b/BanishIntoFable.java @@ -0,0 +1,127 @@ +package mage.cards.b; + +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.CastSourceTriggeredAbility; +import mage.abilities.effects.common.CreateTokenEffect; +import mage.abilities.effects.common.ReturnToHandTargetEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.game.permanent.token.KnightToken; +import mage.game.stack.Spell; +import mage.target.common.TargetNonlandPermanent; +import mage.watchers.common.CastFromHandWatcher; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class BanishIntoFable extends CardImpl { + + public BanishIntoFable(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{4}{W}{U}"); + + // When you cast this spell from your hand, copy it if you control an artifact, then copy it if you control an enchantment. You may choose new targets for the copies. + this.addAbility(new BanishIntoFableTriggeredAbility()); + + // Return target nonland permanent to its owner's hand. You create a 2/2 white Knight creature token with vigilance. + this.getSpellAbility().addEffect(new ReturnToHandTargetEffect()); + this.getSpellAbility().addTarget(new TargetNonlandPermanent()); + this.getSpellAbility().addEffect(new CreateTokenEffect(new KnightToken()) + .setText("You create a 2/2 white Knight creature token with vigilance")); + } + + private BanishIntoFable(final BanishIntoFable card) { + super(card); + } + + @Override + public BanishIntoFable copy() { + return new BanishIntoFable(this); + } +} + +class BanishIntoFableTriggeredAbility extends CastSourceTriggeredAbility { + + BanishIntoFableTriggeredAbility() { + super(null, false); + this.addWatcher(new CastFromHandWatcher()); + this.setRuleAtTheTop(true); + } + + private BanishIntoFableTriggeredAbility(BanishIntoFableTriggeredAbility ability) { + super(ability); + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (!super.checkTrigger(event, game)) { + return false; + } + CastFromHandWatcher watcher = game.getState().getWatcher(CastFromHandWatcher.class); + if (watcher == null || !watcher.spellWasCastFromHand(event.getSourceId())) { + return false; + } + Spell spell = game.getState().getStack().getSpell(event.getSourceId()); + if (spell == null) { + return false; + } + this.getEffects().clear(); + this.addEffect(new BanishIntoFableEffect(spell.getId())); + return true; + } + + @Override + public BanishIntoFableTriggeredAbility copy() { + return new BanishIntoFableTriggeredAbility(this); + } +} + +class BanishIntoFableEffect extends OneShotEffect { + + private final UUID spellId; + + BanishIntoFableEffect(UUID spellId) { + super(Outcome.Benefit); + this.spellId = spellId; + } + + private BanishIntoFableEffect(final BanishIntoFableEffect effect) { + super(effect); + this.spellId = effect.spellId; + } + + @Override + public BanishIntoFableEffect copy() { + return new BanishIntoFableEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Spell spell = game.getSpellOrLKIStack(spellId); + if (spell == null) { + return false; + } + if (game.getBattlefield() + .getAllActivePermanents(source.getControllerId()) + .stream() + .filter(Permanent::isArtifact) + .count() > 0) { + spell.createCopyOnStack(game, source, source.getControllerId(), true); + } + if (game.getBattlefield() + .getAllActivePermanents(source.getControllerId()) + .stream() + .filter(Permanent::isEnchantment) + .count() > 0) { + spell.createCopyOnStack(game, source, source.getControllerId(), true); + } + return true; + } +} diff --git a/Mage.Sets/src/mage/sets/ThroneOfEldraine.java b/Mage.Sets/src/mage/sets/ThroneOfEldraine.java index bfbf479d266..5945f8dfb38 100644 --- a/Mage.Sets/src/mage/sets/ThroneOfEldraine.java +++ b/Mage.Sets/src/mage/sets/ThroneOfEldraine.java @@ -33,6 +33,7 @@ public final class ThroneOfEldraine extends ExpansionSet { cards.add(new SetCardInfo("Arcane Signet", 331, Rarity.COMMON, mage.cards.a.ArcaneSignet.class)); cards.add(new SetCardInfo("Arcanist's Owl", 206, Rarity.UNCOMMON, mage.cards.a.ArcanistsOwl.class)); cards.add(new SetCardInfo("Bake into a Pie", 76, Rarity.COMMON, mage.cards.b.BakeIntoAPie.class)); + cards.add(new SetCardInfo("Banish into Fable", 325, Rarity.RARE, mage.cards.b.BanishIntoFable.class)); cards.add(new SetCardInfo("Beanstalk Giant", 149, Rarity.UNCOMMON, mage.cards.b.BeanstalkGiant.class)); cards.add(new SetCardInfo("Belle of the Brawl", 78, Rarity.UNCOMMON, mage.cards.b.BelleOfTheBrawl.class)); cards.add(new SetCardInfo("Chittering Witch", 319, Rarity.RARE, mage.cards.c.ChitteringWitch.class));