From 4cfc6ebc37adba8cb195934a8c6bbbf25ea6e66c Mon Sep 17 00:00:00 2001 From: Susucre <34709007+Susucre@users.noreply.github.com> Date: Fri, 18 Aug 2023 21:06:37 +0200 Subject: [PATCH] [WOE] Implement Beseech the Mirror (#10842) Co-authored-by: Evan Kranzler --- .../src/mage/cards/b/BeseechTheMirror.java | 111 ++++++++++++++++++ Mage.Sets/src/mage/sets/WildsOfEldraine.java | 1 + Mage/src/main/java/mage/util/CardUtil.java | 6 +- 3 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 Mage.Sets/src/mage/cards/b/BeseechTheMirror.java diff --git a/Mage.Sets/src/mage/cards/b/BeseechTheMirror.java b/Mage.Sets/src/mage/cards/b/BeseechTheMirror.java new file mode 100644 index 00000000000..532eb491969 --- /dev/null +++ b/Mage.Sets/src/mage/cards/b/BeseechTheMirror.java @@ -0,0 +1,111 @@ +package mage.cards.b; + +import mage.abilities.Ability; +import mage.abilities.condition.common.BargainedCondition; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.keyword.BargainAbility; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.ComparisonType; +import mage.constants.Outcome; +import mage.constants.Zone; +import mage.filter.FilterCard; +import mage.filter.predicate.mageobject.ManaValuePredicate; +import mage.game.Game; +import mage.players.Player; +import mage.target.common.TargetCardInLibrary; +import mage.util.CardUtil; + +import java.util.UUID; + +/** + * @author Susucr + */ +public final class BeseechTheMirror extends CardImpl { + + public BeseechTheMirror(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{1}{B}{B}{B}"); + + // Bargain + this.addAbility(new BargainAbility()); + + // Search your library for a card, exile it face down, then shuffle. If this spell was bargained, you may cast the exiled card without paying its mana cost if that spell's mana value is 4 or less. Put the exiled card into your hand if it wasn't cast this way. + this.getSpellAbility().addEffect(new BeseechTheMirrorEffect()); + } + + private BeseechTheMirror(final BeseechTheMirror card) { + super(card); + } + + @Override + public BeseechTheMirror copy() { + return new BeseechTheMirror(this); + } +} + +class BeseechTheMirrorEffect extends OneShotEffect { + + private static final FilterCard filter = new FilterCard(); + + static { + filter.add(new ManaValuePredicate(ComparisonType.OR_LESS, 4)); + } + + BeseechTheMirrorEffect() { + super(Outcome.Benefit); + staticText = "Search your library for a card, exile it face down, then shuffle. " + + "If this spell was bargained, you may cast the exiled card without paying " + + "its mana cost if that spell's mana value is 4 or less. Put the exiled card " + + "into your hand if it wasn't cast this way."; + } + + private BeseechTheMirrorEffect(final BeseechTheMirrorEffect effect) { + super(effect); + } + + @Override + public BeseechTheMirrorEffect copy() { + return new BeseechTheMirrorEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller == null) { + return false; + } + + // Search your library for a card + TargetCardInLibrary target = new TargetCardInLibrary(); + if (controller.searchLibrary(target, source, game)) { + Card card = controller.getLibrary().getCard(target.getFirstTarget(), game); + if (card != null) { + // exile it face down + card.setFaceDown(true, game); + controller.moveCards(card, Zone.EXILED, source, game, false, true, false, null); + card.setFaceDown(true, game); + + // then shuffle + controller.shuffleLibrary(source, game); + + // If this spell was bargained, + if (BargainedCondition.instance.apply(game, source)) { + // you may cast the exiled card without paying its mana cost if that spell's mana value is 4 or less. + CardUtil.castSpellWithAttributesForFree(controller, source, game, card, filter); + } + game.getState().processAction(game); + + if (game.getState().getZone(card.getId()).equals(Zone.EXILED)) { + // Put the exiled card into your hand if it wasn't cast this way. + controller.moveCards(card, Zone.HAND, source, game, false, true, false, null); + card.setFaceDown(false, game); + } + + return true; + } + } + return false; + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/WildsOfEldraine.java b/Mage.Sets/src/mage/sets/WildsOfEldraine.java index 85b7834d49d..b02e784220b 100644 --- a/Mage.Sets/src/mage/sets/WildsOfEldraine.java +++ b/Mage.Sets/src/mage/sets/WildsOfEldraine.java @@ -24,6 +24,7 @@ public final class WildsOfEldraine extends ExpansionSet { cards.add(new SetCardInfo("Ash, Party Crasher", 201, Rarity.UNCOMMON, mage.cards.a.AshPartyCrasher.class)); cards.add(new SetCardInfo("Ashiok's Reaper", 79, Rarity.UNCOMMON, mage.cards.a.AshioksReaper.class)); cards.add(new SetCardInfo("Beanstalk Wurm", 161, Rarity.COMMON, mage.cards.b.BeanstalkWurm.class)); + cards.add(new SetCardInfo("Beseech the Mirror", 82, Rarity.MYTHIC, mage.cards.b.BeseechTheMirror.class)); cards.add(new SetCardInfo("Besotted Knight", 4, Rarity.COMMON, mage.cards.b.BesottedKnight.class)); cards.add(new SetCardInfo("Bitter Chill", 44, Rarity.UNCOMMON, mage.cards.b.BitterChill.class)); cards.add(new SetCardInfo("Break the Spell", 5, Rarity.COMMON, mage.cards.b.BreakTheSpell.class)); diff --git a/Mage/src/main/java/mage/util/CardUtil.java b/Mage/src/main/java/mage/util/CardUtil.java index a2f58887cc1..6467d931c7e 100644 --- a/Mage/src/main/java/mage/util/CardUtil.java +++ b/Mage/src/main/java/mage/util/CardUtil.java @@ -1255,7 +1255,11 @@ public final class CardUtil { private static final FilterCard defaultFilter = new FilterCard("card to cast"); public static boolean castSpellWithAttributesForFree(Player player, Ability source, Game game, Card card) { - return castSpellWithAttributesForFree(player, source, game, new CardsImpl(card), StaticFilters.FILTER_CARD); + return castSpellWithAttributesForFree(player, source, game, card, StaticFilters.FILTER_CARD); + } + + public static boolean castSpellWithAttributesForFree(Player player, Ability source, Game game, Card card, FilterCard filter) { + return castSpellWithAttributesForFree(player, source, game, new CardsImpl(card), filter); } public static boolean castSpellWithAttributesForFree(Player player, Ability source, Game game, Cards cards, FilterCard filter) {