From cd9f9c9f0518625d176fa035d1a0f78f2af94006 Mon Sep 17 00:00:00 2001 From: Susucre <34709007+Susucre@users.noreply.github.com> Date: Sat, 28 Oct 2023 16:49:57 +0200 Subject: [PATCH] [LCI] Implement the Mother Lode (#11351) refactor DiscoverEffect to call a static doDiscover that returns the discovered card. --- .../src/mage/cards/h/HitTheMotherLode.java | 74 +++++++++++++++++++ .../src/mage/sets/TheLostCavernsOfIxalan.java | 1 + .../effects/keyword/DiscoverEffect.java | 39 ++++++---- 3 files changed, 99 insertions(+), 15 deletions(-) create mode 100644 Mage.Sets/src/mage/cards/h/HitTheMotherLode.java diff --git a/Mage.Sets/src/mage/cards/h/HitTheMotherLode.java b/Mage.Sets/src/mage/cards/h/HitTheMotherLode.java new file mode 100644 index 00000000000..feb37530c25 --- /dev/null +++ b/Mage.Sets/src/mage/cards/h/HitTheMotherLode.java @@ -0,0 +1,74 @@ +package mage.cards.h; + +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.CreateTokenEffect; +import mage.abilities.effects.keyword.DiscoverEffect; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.game.Game; +import mage.game.permanent.token.TreasureToken; +import mage.players.Player; + +import java.util.UUID; + +/** + * @author Susucr + */ +public final class HitTheMotherLode extends CardImpl { + + public HitTheMotherLode(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{4}{R}{R}{R}"); + + // Discover 10. If the discovered card's mana value is less than 10, create a number of tapped Treasure tokens equal to the difference. + this.getSpellAbility().addEffect(new HitTheMotherLodeEffect()); + } + + private HitTheMotherLode(final HitTheMotherLode card) { + super(card); + } + + @Override + public HitTheMotherLode copy() { + return new HitTheMotherLode(this); + } +} + +class HitTheMotherLodeEffect extends OneShotEffect { + + HitTheMotherLodeEffect() { + super(Outcome.Benefit); + staticText = "Discover 10. If the discovered card's mana value is less than 10, " + + "create a number of tapped Treasure tokens equal to the difference."; + } + + private HitTheMotherLodeEffect(final HitTheMotherLodeEffect effect) { + super(effect); + } + + @Override + public HitTheMotherLodeEffect copy() { + return new HitTheMotherLodeEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller == null) { + return false; + } + + Card card = DiscoverEffect.doDiscover(controller, 10, game, source); + int value = card == null ? 0 : card.getManaValue(); + if (value >= 10) { + return false; + } + + return new CreateTokenEffect(new TreasureToken(), 10 - value, true) + .apply(game, source); + } + +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/TheLostCavernsOfIxalan.java b/Mage.Sets/src/mage/sets/TheLostCavernsOfIxalan.java index 6e44e55ad9c..1035cf29327 100644 --- a/Mage.Sets/src/mage/sets/TheLostCavernsOfIxalan.java +++ b/Mage.Sets/src/mage/sets/TheLostCavernsOfIxalan.java @@ -58,6 +58,7 @@ public final class TheLostCavernsOfIxalan extends ExpansionSet { cards.add(new SetCardInfo("Hidden Necropolis", 275, Rarity.COMMON, mage.cards.h.HiddenNecropolis.class)); cards.add(new SetCardInfo("Hidden Nursery", 276, Rarity.COMMON, mage.cards.h.HiddenNursery.class)); cards.add(new SetCardInfo("Hidden Volcano", 277, Rarity.COMMON, mage.cards.h.HiddenVolcano.class)); + cards.add(new SetCardInfo("Hit the Mother Lode", 153, Rarity.RARE, mage.cards.h.HitTheMotherLode.class)); cards.add(new SetCardInfo("Huatli, Poet of Unity", 189, Rarity.MYTHIC, mage.cards.h.HuatliPoetOfUnity.class)); cards.add(new SetCardInfo("Idol of the Deep King", 155, Rarity.COMMON, mage.cards.i.IdolOfTheDeepKing.class)); cards.add(new SetCardInfo("Island", 395, Rarity.LAND, mage.cards.basiclands.Island.class, NON_FULL_USE_VARIOUS)); diff --git a/Mage/src/main/java/mage/abilities/effects/keyword/DiscoverEffect.java b/Mage/src/main/java/mage/abilities/effects/keyword/DiscoverEffect.java index 57fe408b2a1..5f39033b8f6 100644 --- a/Mage/src/main/java/mage/abilities/effects/keyword/DiscoverEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/keyword/DiscoverEffect.java @@ -21,13 +21,10 @@ import mage.util.CardUtil; public class DiscoverEffect extends OneShotEffect { private final int amount; - private final FilterCard filter; public DiscoverEffect(int amount) { super(Outcome.Benefit); this.amount = amount; - this.filter = new FilterNonlandCard(); - filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, amount + 1)); staticText = "Discover " + amount + " (Exile cards from the top of your library " + "until you exile a nonland card with mana value " + amount + " or less. " + "Cast it without paying its mana cost or put it into your hand. " + @@ -37,7 +34,6 @@ public class DiscoverEffect extends OneShotEffect { private DiscoverEffect(final DiscoverEffect effect) { super(effect); this.amount = effect.amount; - this.filter = effect.filter.copy(); } @Override @@ -51,20 +47,18 @@ public class DiscoverEffect extends OneShotEffect { if (player == null) { return false; } - Cards cards = new CardsImpl(); - Card card = getCard(player, cards, game, source); - if (card != null) { - CardUtil.castSpellWithAttributesForFree(player, source, game, card, filter); - if (game.getState().getZone(card.getId()) == Zone.EXILED) { - player.moveCards(card, Zone.HAND, source, game); - } - } - cards.retainZone(Zone.EXILED, game); - player.putCardsOnBottomOfLibrary(cards, game, source, false); + + doDiscover(player, amount, game, source); return true; } - private Card getCard(Player player, Cards cards, Game game, Ability source) { + private static FilterCard makeDiscoverFilter(int amount) { + FilterCard filter = new FilterNonlandCard(); + filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, amount + 1)); + return filter; + } + + private static Card getCard(Player player, FilterCard filter, Cards cards, Game game, Ability source) { for (Card card : player.getLibrary().getCards(game)) { cards.add(card); player.moveCards(card, Zone.EXILED, source, game); @@ -75,4 +69,19 @@ public class DiscoverEffect extends OneShotEffect { } return null; } + + public static Card doDiscover(Player player, int amount, Game game, Ability source) { + Cards cards = new CardsImpl(); + FilterCard filter = makeDiscoverFilter(amount); + Card card = getCard(player, filter, cards, game, source); + if (card != null) { + CardUtil.castSpellWithAttributesForFree(player, source, game, card, filter); + if (game.getState().getZone(card.getId()) == Zone.EXILED) { + player.moveCards(card, Zone.HAND, source, game); + } + } + cards.retainZone(Zone.EXILED, game); + player.putCardsOnBottomOfLibrary(cards, game, source, false); + return card; + } }