[LCI] Implement the Mother Lode (#11351)

refactor DiscoverEffect to call a static doDiscover that returns the discovered card.
This commit is contained in:
Susucre 2023-10-28 16:49:57 +02:00 committed by GitHub
parent 9e037f63d8
commit cd9f9c9f05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 99 additions and 15 deletions

View file

@ -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);
}
}

View file

@ -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));

View file

@ -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 + " <i>(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;
}
}