forked from External/mage
[LCI] Implement the Mother Lode (#11351)
refactor DiscoverEffect to call a static doDiscover that returns the discovered card.
This commit is contained in:
parent
9e037f63d8
commit
cd9f9c9f05
3 changed files with 99 additions and 15 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue