mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 05:22:02 -08:00
Refactor LookLibraryAndPickControllerEffect (#8841)
This commit is contained in:
parent
7db8dd11b4
commit
dc7dcec39a
195 changed files with 1463 additions and 3526 deletions
|
|
@ -19,7 +19,7 @@ public enum DeliriumCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "if there are four or more card types among cards in your graveyard";
|
||||
return "there are four or more card types among cards in your graveyard";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,253 +35,134 @@ import mage.abilities.dynamicvalue.DynamicValue;
|
|||
import mage.abilities.dynamicvalue.common.StaticValue;
|
||||
import mage.cards.Cards;
|
||||
import mage.cards.CardsImpl;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterCard;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.target.TargetCard;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import static java.lang.Integer.min;
|
||||
|
||||
/**
|
||||
* @author LevelX
|
||||
* @author LevelX, awjackson
|
||||
*/
|
||||
public class LookLibraryAndPickControllerEffect extends LookLibraryControllerEffect {
|
||||
|
||||
protected FilterCard filter; // which kind of cards to reveal
|
||||
protected DynamicValue numberToPick;
|
||||
protected boolean revealPickedCards = true;
|
||||
protected Zone targetPickedCards = Zone.HAND; // HAND
|
||||
protected int foundCardsToPick = 0;
|
||||
protected int numberToPick;
|
||||
protected PutCards putPickedCards;
|
||||
protected FilterCard filter;
|
||||
protected boolean revealPickedCards;
|
||||
protected boolean optional;
|
||||
private boolean upTo;
|
||||
private boolean putOnTopSelected;
|
||||
private boolean anyOrder;
|
||||
protected boolean upTo;
|
||||
|
||||
//TODO: These constructors are a mess
|
||||
public LookLibraryAndPickControllerEffect(DynamicValue numberOfCards,
|
||||
boolean mayShuffleAfter, DynamicValue numberToPick,
|
||||
FilterCard pickFilter, boolean putOnTop) {
|
||||
this(numberOfCards, mayShuffleAfter, numberToPick, pickFilter,
|
||||
putOnTop, true);
|
||||
public LookLibraryAndPickControllerEffect(int numberOfCards, int numberToPick,
|
||||
PutCards putPickedCards, PutCards putLookedCards) {
|
||||
this(numberOfCards, numberToPick, putPickedCards, putLookedCards, false);
|
||||
}
|
||||
|
||||
public LookLibraryAndPickControllerEffect(DynamicValue numberOfCards,
|
||||
boolean mayShuffleAfter, DynamicValue numberToPick,
|
||||
FilterCard pickFilter, boolean putOnTop, boolean reveal) {
|
||||
this(numberOfCards, mayShuffleAfter, numberToPick, pickFilter,
|
||||
Zone.LIBRARY, putOnTop, reveal);
|
||||
public LookLibraryAndPickControllerEffect(DynamicValue numberOfCards, int numberToPick,
|
||||
PutCards putPickedCards, PutCards putLookedCards) {
|
||||
this(numberOfCards, numberToPick, putPickedCards, putLookedCards, false);
|
||||
}
|
||||
|
||||
public LookLibraryAndPickControllerEffect(DynamicValue numberOfCards,
|
||||
boolean mayShuffleAfter, DynamicValue numberToPick,
|
||||
FilterCard pickFilter, Zone targetZoneLookedCards,
|
||||
boolean putOnTop, boolean reveal) {
|
||||
this(numberOfCards, mayShuffleAfter, numberToPick, pickFilter,
|
||||
targetZoneLookedCards, putOnTop, reveal, reveal);
|
||||
public LookLibraryAndPickControllerEffect(int numberOfCards, int numberToPick,
|
||||
PutCards putPickedCards, PutCards putLookedCards, boolean upTo) {
|
||||
this(StaticValue.get(numberOfCards), numberToPick, putPickedCards, putLookedCards, upTo);
|
||||
}
|
||||
|
||||
public LookLibraryAndPickControllerEffect(int numberOfCards,
|
||||
int numberToPick, FilterCard pickFilter, boolean upTo) {
|
||||
this(StaticValue.get(numberOfCards), false,
|
||||
StaticValue.get(numberToPick), pickFilter, Zone.LIBRARY, false,
|
||||
true, upTo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param numberOfCards
|
||||
* @param numberToPick
|
||||
* @param pickFilter
|
||||
* @param reveal
|
||||
* @param upTo
|
||||
* @param targetZonePickedCards
|
||||
* @param optional
|
||||
*/
|
||||
public LookLibraryAndPickControllerEffect(int numberOfCards,
|
||||
int numberToPick, FilterCard pickFilter, boolean reveal,
|
||||
boolean upTo, Zone targetZonePickedCards, boolean optional) {
|
||||
this(StaticValue.get(numberOfCards), false,
|
||||
StaticValue.get(numberToPick), pickFilter, Zone.LIBRARY, false,
|
||||
reveal, upTo, targetZonePickedCards, optional, true, true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param numberOfCards
|
||||
* @param mayShuffleAfter
|
||||
* @param numberToPick
|
||||
* @param pickFilter
|
||||
* @param targetZoneLookedCards
|
||||
* @param putOnTop if zone for the rest is library decide if cards go to top
|
||||
* or bottom
|
||||
* @param reveal
|
||||
* @param upTo
|
||||
*/
|
||||
public LookLibraryAndPickControllerEffect(DynamicValue numberOfCards,
|
||||
boolean mayShuffleAfter, DynamicValue numberToPick,
|
||||
FilterCard pickFilter, Zone targetZoneLookedCards,
|
||||
boolean putOnTop, boolean reveal, boolean upTo) {
|
||||
this(numberOfCards, mayShuffleAfter, numberToPick, pickFilter,
|
||||
targetZoneLookedCards, putOnTop, reveal, upTo, Zone.HAND,
|
||||
false, true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param numberOfCards
|
||||
* @param mayShuffleAfter
|
||||
* @param numberToPick
|
||||
* @param pickFilter
|
||||
* @param targetZoneLookedCards
|
||||
* @param putOnTop if zone for the rest is library decide if cards go to top
|
||||
* or bottom
|
||||
* @param reveal
|
||||
* @param upTo
|
||||
* @param targetZonePickedCards
|
||||
* @param optional
|
||||
*/
|
||||
public LookLibraryAndPickControllerEffect(DynamicValue numberOfCards,
|
||||
boolean mayShuffleAfter, DynamicValue numberToPick,
|
||||
FilterCard pickFilter, Zone targetZoneLookedCards, boolean putOnTop,
|
||||
boolean reveal, boolean upTo, Zone targetZonePickedCards,
|
||||
boolean optional) {
|
||||
|
||||
this(numberOfCards, mayShuffleAfter, numberToPick, pickFilter,
|
||||
targetZoneLookedCards, putOnTop, reveal, upTo,
|
||||
targetZonePickedCards, optional, true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param numberOfCards
|
||||
* @param mayShuffleAfter
|
||||
* @param numberToPick
|
||||
* @param pickFilter
|
||||
* @param targetZoneLookedCards
|
||||
* @param putOnTop if zone for the rest is library decide if cards go to top
|
||||
* or bottom
|
||||
* @param reveal
|
||||
* @param upTo
|
||||
* @param targetZonePickedCards
|
||||
* @param optional
|
||||
* @param putOnTopSelected
|
||||
* @param anyOrder
|
||||
*/
|
||||
public LookLibraryAndPickControllerEffect(DynamicValue numberOfCards,
|
||||
boolean mayShuffleAfter, DynamicValue numberToPick,
|
||||
FilterCard pickFilter, Zone targetZoneLookedCards, boolean putOnTop,
|
||||
boolean reveal, boolean upTo, Zone targetZonePickedCards,
|
||||
boolean optional, boolean putOnTopSelected, boolean anyOrder) {
|
||||
super(Outcome.DrawCard, numberOfCards, mayShuffleAfter,
|
||||
targetZoneLookedCards, putOnTop);
|
||||
public LookLibraryAndPickControllerEffect(DynamicValue numberOfCards, int numberToPick,
|
||||
PutCards putPickedCards, PutCards putLookedCards, boolean upTo) {
|
||||
super(putPickedCards.getOutcome(), numberOfCards, putLookedCards);
|
||||
this.numberToPick = numberToPick;
|
||||
this.filter = pickFilter;
|
||||
this.revealPickedCards = reveal;
|
||||
this.targetPickedCards = targetZonePickedCards;
|
||||
this.upTo = upTo;
|
||||
this.putPickedCards = putPickedCards;
|
||||
this.filter = (numberToPick > 1) ? StaticFilters.FILTER_CARD_CARDS : StaticFilters.FILTER_CARD_A;
|
||||
this.revealPickedCards = false;
|
||||
this.optional = false;
|
||||
this.upTo = upTo || numberToPick == Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
public LookLibraryAndPickControllerEffect(int numberOfCards, int numberToPick, FilterCard filter,
|
||||
PutCards putPickedCards, PutCards putLookedCards) {
|
||||
this(numberOfCards, numberToPick, filter, putPickedCards, putLookedCards, true);
|
||||
}
|
||||
|
||||
public LookLibraryAndPickControllerEffect(DynamicValue numberOfCards, int numberToPick, FilterCard filter,
|
||||
PutCards putPickedCards, PutCards putLookedCards) {
|
||||
this(numberOfCards, numberToPick, filter, putPickedCards, putLookedCards, true);
|
||||
}
|
||||
|
||||
public LookLibraryAndPickControllerEffect(int numberOfCards, int numberToPick, FilterCard filter,
|
||||
PutCards putPickedCards, PutCards putLookedCards, boolean optional) {
|
||||
this(StaticValue.get(numberOfCards), numberToPick, filter, putPickedCards, putLookedCards, optional);
|
||||
}
|
||||
|
||||
public LookLibraryAndPickControllerEffect(DynamicValue numberOfCards, int numberToPick, FilterCard filter,
|
||||
PutCards putPickedCards, PutCards putLookedCards, boolean optional) {
|
||||
super(putPickedCards.getOutcome(), numberOfCards, putLookedCards);
|
||||
this.numberToPick = numberToPick;
|
||||
this.putPickedCards = putPickedCards;
|
||||
this.filter = filter;
|
||||
this.revealPickedCards = !putPickedCards.getZone().isPublicZone();
|
||||
this.optional = optional;
|
||||
this.putOnTopSelected = putOnTopSelected;
|
||||
this.anyOrder = anyOrder;
|
||||
this.upTo = (numberToPick > 1);
|
||||
}
|
||||
|
||||
public LookLibraryAndPickControllerEffect(final LookLibraryAndPickControllerEffect effect) {
|
||||
super(effect);
|
||||
this.numberToPick = effect.numberToPick.copy();
|
||||
this.numberToPick = effect.numberToPick;
|
||||
this.putPickedCards = effect.putPickedCards;
|
||||
this.filter = effect.filter.copy();
|
||||
this.revealPickedCards = effect.revealPickedCards;
|
||||
this.targetPickedCards = effect.targetPickedCards;
|
||||
this.upTo = effect.upTo;
|
||||
this.optional = effect.optional;
|
||||
this.putOnTopSelected = effect.putOnTopSelected;
|
||||
this.anyOrder = effect.anyOrder;
|
||||
this.upTo = effect.upTo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LookLibraryAndPickControllerEffect copy() {
|
||||
return new LookLibraryAndPickControllerEffect(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionWithSelectedCards(Cards cards, Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player != null && numberToPick.calculate(game, source, this) > 0
|
||||
&& cards.count(filter, source.getControllerId(), source, game) > 0) {
|
||||
if (!optional || player.chooseUse(Outcome.DrawCard, getMayText(), source, game)) {
|
||||
FilterCard pickFilter = filter.copy();
|
||||
pickFilter.setMessage(getPickText());
|
||||
int number = min(cards.size(), numberToPick.calculate(game, source, this));
|
||||
TargetCard target = new TargetCard((upTo ? 0 : number), number, Zone.LIBRARY, pickFilter);
|
||||
if (player.choose(Outcome.DrawCard, cards, target, game)) {
|
||||
Cards pickedCards = new CardsImpl(target.getTargets());
|
||||
cards.removeAll(pickedCards);
|
||||
if (targetPickedCards == Zone.LIBRARY && !putOnTopSelected) {
|
||||
player.putCardsOnBottomOfLibrary(pickedCards, game, source, anyOrder);
|
||||
} else {
|
||||
player.moveCards(pickedCards.getCards(game), targetPickedCards, source, game);
|
||||
}
|
||||
if (revealPickedCards) {
|
||||
player.revealCards(source, pickedCards, game);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
protected boolean actionWithLookedCards(Game game, Ability source, Player player, Cards cards) {
|
||||
int number = Math.min(numberToPick, cards.count(filter, source.getControllerId(), source, game));
|
||||
if (number < 1
|
||||
|| optional && !player.chooseUse(putPickedCards.getOutcome(), getMayText(), source, game)) {
|
||||
return actionWithPickedCards(game, source, player, new CardsImpl(), cards);
|
||||
}
|
||||
|
||||
TargetCard target = new TargetCard((upTo ? 0 : number), number, Zone.LIBRARY, filter);
|
||||
target.withChooseHint(getChooseHint());
|
||||
if (!player.chooseTarget(putPickedCards.getOutcome(), cards, target, source, game)) {
|
||||
return actionWithPickedCards(game, source, player, new CardsImpl(), cards);
|
||||
}
|
||||
Cards pickedCards = new CardsImpl(target.getTargets());
|
||||
if (revealPickedCards) {
|
||||
player.revealCards(source, pickedCards, game);
|
||||
}
|
||||
cards.removeAll(pickedCards);
|
||||
return actionWithPickedCards(game, source, player, pickedCards, cards);
|
||||
}
|
||||
|
||||
private String getMayText() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
switch (targetPickedCards) {
|
||||
case HAND:
|
||||
if (revealPickedCards) {
|
||||
sb.append("Reveal ").append(filter.getMessage()).append(" and put into your hand");
|
||||
} else {
|
||||
sb.append("Put ").append(filter.getMessage()).append(" into your hand");
|
||||
}
|
||||
break;
|
||||
case BATTLEFIELD:
|
||||
sb.append("Put ").append(filter.getMessage()).append(" onto the battlefield");
|
||||
break;
|
||||
case GRAVEYARD:
|
||||
sb.append("Put ").append(filter.getMessage()).append(" into your graveyard");
|
||||
break;
|
||||
}
|
||||
return sb.append('?').toString();
|
||||
protected boolean actionWithPickedCards(Game game, Ability source, Player player, Cards pickedCards, Cards otherCards) {
|
||||
boolean result = moveCards(game, source, player, pickedCards, putPickedCards);
|
||||
result |= moveCards(game, source, player, otherCards, putLookedCards);
|
||||
return result;
|
||||
}
|
||||
|
||||
private String getPickText() {
|
||||
StringBuilder sb = new StringBuilder(filter.getMessage()).append(" to ");
|
||||
switch (targetPickedCards) {
|
||||
case LIBRARY:
|
||||
if (putOnTopSelected) {
|
||||
sb.append("put on the top of your library");
|
||||
} else {
|
||||
sb.append("put on the bottom of your library");
|
||||
}
|
||||
if (anyOrder) {
|
||||
sb.append(" in any order");
|
||||
} else {
|
||||
sb.append(" in a random order");
|
||||
}
|
||||
break;
|
||||
case HAND:
|
||||
if (revealPickedCards) {
|
||||
sb.append("reveal and put into your hand");
|
||||
} else {
|
||||
sb.append("put into your hand");
|
||||
}
|
||||
break;
|
||||
case BATTLEFIELD:
|
||||
sb.append("put onto the battlefield");
|
||||
break;
|
||||
case GRAVEYARD:
|
||||
sb.append("put into the graveyard");
|
||||
break;
|
||||
protected String getMayText() {
|
||||
boolean plural = numberToPick > 1;
|
||||
StringBuilder sb = new StringBuilder(revealPickedCards ? "Reveal " : "Put ");
|
||||
sb.append(plural ? filter.getMessage() : CardUtil.addArticle(filter.getMessage()));
|
||||
if (revealPickedCards) {
|
||||
sb.append(" and put ");
|
||||
sb.append(plural ? "them" : "it");
|
||||
}
|
||||
return sb.toString();
|
||||
sb.append(" ");
|
||||
sb.append(putPickedCards.getMessage(plural));
|
||||
return sb.append("?").toString();
|
||||
}
|
||||
|
||||
protected String getChooseHint() {
|
||||
return "to put " + putPickedCards.getMessage(numberToPick > 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -289,75 +170,57 @@ public class LookLibraryAndPickControllerEffect extends LookLibraryControllerEff
|
|||
if (staticText != null && !staticText.isEmpty()) {
|
||||
return staticText;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int pickCount=numberToPick.calculate(null, null, this);
|
||||
int cardCount=numberOfCards.calculate(null, null, this);
|
||||
if (pickCount > 0) {
|
||||
if (revealPickedCards) {
|
||||
sb.append(". You may reveal ");
|
||||
sb.append(filter.getMessage());
|
||||
sb.append(" from among them and put ");
|
||||
sb.append(pickCount>1?"the revealed cards":"it");
|
||||
sb.append(" into your ");
|
||||
} else if (targetPickedCards == Zone.BATTLEFIELD) {
|
||||
sb.append(". ");
|
||||
if (optional) {
|
||||
sb.append("You may p");
|
||||
} else {
|
||||
sb.append('P');
|
||||
}
|
||||
sb.append("ut ").append(filter.getMessage()).append(" from among them onto the ");
|
||||
} else {
|
||||
sb.append(". Put ");
|
||||
if (pickCount > 1) {
|
||||
if (upTo) {
|
||||
if (pickCount == (cardCount)) {
|
||||
sb.append("any number");
|
||||
} else {
|
||||
sb.append("up to ").append(CardUtil.numberToText(pickCount));
|
||||
}
|
||||
} else {
|
||||
sb.append(CardUtil.numberToText(pickCount));
|
||||
}
|
||||
} else {
|
||||
sb.append("one");
|
||||
}
|
||||
|
||||
sb.append(" of them into your ");
|
||||
}
|
||||
sb.append(targetPickedCards.toString().toLowerCase(Locale.ENGLISH));
|
||||
|
||||
if (targetZoneLookedCards == Zone.LIBRARY) {
|
||||
sb.append(revealPickedCards?". Put ":" and ");
|
||||
sb.append(cardCount-pickCount==1?"the other ":"the rest ");
|
||||
if (putOnTop) {
|
||||
sb.append("back on top");
|
||||
} else {
|
||||
sb.append("on the bottom");
|
||||
}
|
||||
sb.append(" of your library");
|
||||
if (cardCount-pickCount>1) {
|
||||
sb.append(" in ");
|
||||
if (anyOrder && !backInRandomOrder) {
|
||||
sb.append("any");
|
||||
} else {
|
||||
sb.append("a random");
|
||||
}
|
||||
sb.append(" order");
|
||||
}
|
||||
} else if (targetZoneLookedCards == Zone.GRAVEYARD) {
|
||||
sb.append(" and the");
|
||||
if (numberOfCards instanceof StaticValue && numberToPick instanceof StaticValue
|
||||
&& ((StaticValue) numberToPick).getValue() + 1 == ((StaticValue) numberOfCards).getValue()) {
|
||||
sb.append(" other");
|
||||
} else {
|
||||
sb.append(" rest");
|
||||
}
|
||||
sb.append(" into your graveyard");
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(". ");
|
||||
if (optional) {
|
||||
sb.append(revealPickedCards ? "You may reveal " : "You may put ");
|
||||
} else {
|
||||
sb.append(revealPickedCards ? "Reveal " : "Put ");
|
||||
}
|
||||
boolean havePredicates = filter.hasPredicates();
|
||||
boolean plural = numberToPick > 1;
|
||||
if (havePredicates && !plural && !upTo) {
|
||||
sb.append(CardUtil.addArticle(filter.getMessage()));
|
||||
} else if (numberToPick == Integer.MAX_VALUE) {
|
||||
sb.append("any number of ");
|
||||
if (havePredicates) {
|
||||
sb.append(filter.getMessage());
|
||||
}
|
||||
} else {
|
||||
if (upTo) {
|
||||
sb.append("up to ");
|
||||
}
|
||||
sb.append(CardUtil.numberToText(numberToPick));
|
||||
sb.append(" ");
|
||||
sb.append(havePredicates ? filter.getMessage() : "of ");
|
||||
}
|
||||
if (havePredicates) {
|
||||
sb.append(" from among ");
|
||||
}
|
||||
sb.append("them ");
|
||||
if (revealPickedCards) {
|
||||
sb.append("and put ");
|
||||
sb.append(plural ? "them " : "it ");
|
||||
}
|
||||
sb.append(putPickedCards.getMessage(plural));
|
||||
|
||||
plural = optional
|
||||
|| upTo
|
||||
|| !(numberOfCards instanceof StaticValue)
|
||||
|| numberOfCards.calculate(null, null, this) - numberToPick != 1;
|
||||
|
||||
// if remaining text would be "put the other on top of your library", omit it
|
||||
if (!plural && putLookedCards == PutCards.TOP_ANY) {
|
||||
return setText(mode, sb.toString());
|
||||
}
|
||||
sb.append(havePredicates && (optional || upTo) ? ". Put" : " and");
|
||||
sb.append(" the ");
|
||||
sb.append(plural ? "rest " : "other ");
|
||||
if (putPickedCards == PutCards.GRAVEYARD && putLookedCards == PutCards.TOP_ANY) {
|
||||
sb.append("back ");
|
||||
}
|
||||
sb.append(putLookedCards.getMessage(plural));
|
||||
|
||||
// get text frame from super class and inject action text
|
||||
return setText(mode, sb.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
|
|
@ -17,61 +16,81 @@ import mage.util.CardUtil;
|
|||
|
||||
/**
|
||||
*
|
||||
* @author LevelX
|
||||
* @author LevelX, awjackson
|
||||
*/
|
||||
public class LookLibraryControllerEffect extends OneShotEffect {
|
||||
|
||||
public enum PutCards {
|
||||
HAND(Outcome.DrawCard, Zone.HAND, "into your hand"),
|
||||
GRAVEYARD(Outcome.Discard, Zone.GRAVEYARD, "into your graveyard"),
|
||||
BATTLEFIELD(Outcome.PutCardInPlay, Zone.BATTLEFIELD, "onto the battlefield"),
|
||||
BATTLEFIELD_TAPPED(Outcome.PutCardInPlay, Zone.BATTLEFIELD, "onto the battlefield tapped"),
|
||||
TOP_ANY(Outcome.Benefit, Zone.LIBRARY, "on top of your library", " in any order"),
|
||||
BOTTOM_ANY(Outcome.Benefit, Zone.LIBRARY, "on the bottom of your library", " in any order"),
|
||||
BOTTOM_RANDOM(Outcome.Benefit, Zone.LIBRARY, "on the bottom of your library", " in a random order");
|
||||
|
||||
private final Outcome outcome;
|
||||
private final Zone zone;
|
||||
private final String message;
|
||||
private final String order;
|
||||
|
||||
PutCards(Outcome outcome, Zone zone, String message) {
|
||||
this(outcome, zone, message, "");
|
||||
}
|
||||
|
||||
PutCards(Outcome outcome, Zone zone, String message, String order) {
|
||||
this.outcome = outcome;
|
||||
this.zone = zone;
|
||||
this.message = message;
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public Outcome getOutcome() {
|
||||
return outcome;
|
||||
}
|
||||
|
||||
public Zone getZone() {
|
||||
return zone;
|
||||
}
|
||||
|
||||
public String getMessage(boolean withOrder) {
|
||||
return withOrder ? message + order : message;
|
||||
}
|
||||
}
|
||||
|
||||
protected DynamicValue numberOfCards;
|
||||
protected boolean mayShuffleAfter = false;
|
||||
protected boolean putOnTop = true; // if false on put rest back on bottom of library
|
||||
protected Zone targetZoneLookedCards; // GRAVEYARD, LIBRARY
|
||||
protected boolean backInRandomOrder = false;
|
||||
protected PutCards putLookedCards;
|
||||
protected boolean revealCards;
|
||||
|
||||
public LookLibraryControllerEffect() {
|
||||
this(1);
|
||||
}
|
||||
|
||||
public LookLibraryControllerEffect(int numberOfCards) {
|
||||
this(numberOfCards, false, true);
|
||||
this(StaticValue.get(numberOfCards));
|
||||
}
|
||||
|
||||
public LookLibraryControllerEffect(DynamicValue numberOfCards) {
|
||||
this(numberOfCards, false, true);
|
||||
this(Outcome.Benefit, numberOfCards, PutCards.TOP_ANY);
|
||||
}
|
||||
|
||||
public LookLibraryControllerEffect(int numberOfCards, boolean mayShuffleAfter) {
|
||||
this(numberOfCards, mayShuffleAfter, true);
|
||||
}
|
||||
|
||||
public LookLibraryControllerEffect(int numberOfCards, boolean mayShuffleAfter, boolean putOnTop) {
|
||||
this(StaticValue.get(numberOfCards), mayShuffleAfter, putOnTop);
|
||||
}
|
||||
|
||||
public LookLibraryControllerEffect(DynamicValue numberOfCards, boolean mayShuffleAfter, boolean putOnTop) {
|
||||
this(Outcome.Benefit, numberOfCards, mayShuffleAfter, Zone.LIBRARY, putOnTop);
|
||||
}
|
||||
|
||||
public LookLibraryControllerEffect(Outcome outcome, DynamicValue numberOfCards, boolean mayShuffleAfter, Zone targetZoneLookedCards, boolean putOnTop) {
|
||||
public LookLibraryControllerEffect(Outcome outcome, DynamicValue numberOfCards, PutCards putLookedCards) {
|
||||
super(outcome);
|
||||
this.numberOfCards = numberOfCards;
|
||||
this.mayShuffleAfter = mayShuffleAfter;
|
||||
this.targetZoneLookedCards = targetZoneLookedCards;
|
||||
this.putOnTop = putOnTop;
|
||||
this.putLookedCards = putLookedCards;
|
||||
this.revealCards = false;
|
||||
}
|
||||
|
||||
public LookLibraryControllerEffect(final LookLibraryControllerEffect effect) {
|
||||
super(effect);
|
||||
this.numberOfCards = effect.numberOfCards.copy();
|
||||
this.mayShuffleAfter = effect.mayShuffleAfter;
|
||||
this.targetZoneLookedCards = effect.targetZoneLookedCards;
|
||||
this.putOnTop = effect.putOnTop;
|
||||
this.backInRandomOrder = effect.backInRandomOrder;
|
||||
this.putLookedCards = effect.putLookedCards;
|
||||
this.revealCards = effect.revealCards;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LookLibraryControllerEffect copy() {
|
||||
return new LookLibraryControllerEffect(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -84,68 +103,37 @@ public class LookLibraryControllerEffect extends OneShotEffect {
|
|||
// take cards from library and look at them
|
||||
boolean topCardRevealed = controller.isTopCardRevealed();
|
||||
controller.setTopCardRevealed(false);
|
||||
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, this.numberOfCards.calculate(game, source, this)));
|
||||
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, numberOfCards.calculate(game, source, this)));
|
||||
|
||||
controller.lookAtCards(source, null, cards, game);
|
||||
if (revealCards) {
|
||||
controller.revealCards(source, cards, game);
|
||||
} else {
|
||||
controller.lookAtCards(source, null, cards, game);
|
||||
}
|
||||
|
||||
this.actionWithSelectedCards(cards, game, source);
|
||||
|
||||
this.putCardsBack(source, controller, cards, game);
|
||||
boolean result = actionWithLookedCards(game, source, controller, cards);
|
||||
|
||||
controller.setTopCardRevealed(topCardRevealed);
|
||||
|
||||
this.mayShuffle(controller, source, game);
|
||||
|
||||
return true;
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isBackInRandomOrder() {
|
||||
return backInRandomOrder;
|
||||
protected boolean actionWithLookedCards(Game game, Ability source, Player player, Cards cards) {
|
||||
return moveCards(game, source, player, cards, putLookedCards);
|
||||
}
|
||||
|
||||
public Effect setBackInRandomOrder(boolean backInRandomOrder) {
|
||||
this.backInRandomOrder = backInRandomOrder;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected void actionWithSelectedCards(Cards cards, Game game, Ability source) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Put the rest of the cards back to defined zone
|
||||
*
|
||||
* @param source
|
||||
* @param player
|
||||
* @param cards
|
||||
* @param game
|
||||
*/
|
||||
protected void putCardsBack(Ability source, Player player, Cards cards, Game game) {
|
||||
switch (targetZoneLookedCards) {
|
||||
case LIBRARY:
|
||||
if (putOnTop) {
|
||||
player.putCardsOnTopOfLibrary(cards, game, source, !backInRandomOrder);
|
||||
} else {
|
||||
player.putCardsOnBottomOfLibrary(cards, game, source, !backInRandomOrder);
|
||||
}
|
||||
break;
|
||||
case GRAVEYARD:
|
||||
player.moveCards(cards, Zone.GRAVEYARD, source, game);
|
||||
break;
|
||||
protected static boolean moveCards(Game game, Ability source, Player player, Cards cards, PutCards putCards) {
|
||||
switch (putCards) {
|
||||
case TOP_ANY:
|
||||
return player.putCardsOnTopOfLibrary(cards, game, source, true);
|
||||
case BOTTOM_ANY:
|
||||
return player.putCardsOnBottomOfLibrary(cards, game, source, true);
|
||||
case BOTTOM_RANDOM:
|
||||
return player.putCardsOnBottomOfLibrary(cards, game, source, false);
|
||||
case BATTLEFIELD_TAPPED:
|
||||
return player.moveCards(cards.getCards(game), Zone.BATTLEFIELD, source, game, true, false, false, null);
|
||||
default:
|
||||
// not supported yet
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to shuffle library if allowed
|
||||
*
|
||||
* @param player
|
||||
* @param source
|
||||
* @param game
|
||||
*/
|
||||
protected void mayShuffle(Player player, Ability source, Game game) {
|
||||
if (this.mayShuffleAfter && player.chooseUse(Outcome.Benefit, "Shuffle your library?", source, game)) {
|
||||
player.shuffleLibrary(source, game);
|
||||
return player.moveCards(cards, putCards.getZone(), source, game);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -158,46 +146,29 @@ public class LookLibraryControllerEffect extends OneShotEffect {
|
|||
if (staticText != null && !staticText.isEmpty()) {
|
||||
return staticText;
|
||||
}
|
||||
int numberLook;
|
||||
try {
|
||||
numberLook = Integer.parseInt(numberOfCards.toString());
|
||||
} catch (NumberFormatException e) {
|
||||
numberLook = 0;
|
||||
String numberString = numberOfCards.toString();
|
||||
boolean dynamic = !numberOfCards.getMessage().isEmpty();
|
||||
boolean oneCard = !dynamic && numberString.equals("1");
|
||||
StringBuilder sb = new StringBuilder(revealCards ? "reveal " : "look at ");
|
||||
if (oneCard) {
|
||||
sb.append("the top card");
|
||||
} else if (dynamic) {
|
||||
sb.append("the top X cards");
|
||||
} else if (numberString.equals("that many")) {
|
||||
sb.append("that many cards from the top");
|
||||
} else {
|
||||
sb.append("the top ").append(CardUtil.numberToText(numberString)).append(" cards");
|
||||
}
|
||||
StringBuilder sb = new StringBuilder("look at the top ");
|
||||
switch (numberLook) {
|
||||
case 0:
|
||||
sb.append(" X ");
|
||||
break;
|
||||
case 1:
|
||||
sb.append("card ");
|
||||
break;
|
||||
default:
|
||||
sb.append(CardUtil.numberToText(numberLook));
|
||||
break;
|
||||
sb.append(" of your library");
|
||||
if (dynamic) {
|
||||
sb.append(", where X is ").append(numberOfCards.getMessage());
|
||||
}
|
||||
if (numberLook != 1) {
|
||||
sb.append(" cards ");
|
||||
}
|
||||
|
||||
sb.append("of your library");
|
||||
if (numberLook == 0) {
|
||||
sb.append(", where {X} is the number of cards ").append(numberOfCards.getMessage());
|
||||
}
|
||||
|
||||
if (!middleText.isEmpty()) {
|
||||
sb.append(middleText);
|
||||
} else if (numberLook > 1) {
|
||||
if (backInRandomOrder) {
|
||||
sb.append(". Put the rest on the bottom of your library in a random order");
|
||||
} else {
|
||||
sb.append(", then put them back in any order");
|
||||
}
|
||||
} else if (!oneCard) {
|
||||
sb.append(", then put them ");
|
||||
sb.append(putLookedCards == PutCards.TOP_ANY ? "back in any order" : putLookedCards.getMessage(true));
|
||||
}
|
||||
if (this.mayShuffleAfter) {
|
||||
sb.append(". You may shuffle");
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,53 +0,0 @@
|
|||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardsImpl;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
||||
public class LookLibraryMayPutToBottomEffect extends OneShotEffect {
|
||||
|
||||
public LookLibraryMayPutToBottomEffect() {
|
||||
super(Outcome.DrawCard);
|
||||
this.staticText = "Look at the top card of your library. You may put that card on the bottom of your library.";
|
||||
}
|
||||
|
||||
public LookLibraryMayPutToBottomEffect(final LookLibraryMayPutToBottomEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
MageObject sourceObject = game.getObject(source);
|
||||
if (sourceObject == null || controller == null) {
|
||||
return false;
|
||||
}
|
||||
if (controller.getLibrary().hasCards()) {
|
||||
Card card = controller.getLibrary().getFromTop(game);
|
||||
if (card == null) {
|
||||
return false;
|
||||
}
|
||||
controller.lookAtCards(sourceObject.getName(), new CardsImpl(card), game);
|
||||
boolean toBottom = controller.chooseUse(outcome, "Put card on the bottom of your library?", source, game);
|
||||
return controller.moveCardToLibraryWithInfo(card, source, game, Zone.LIBRARY, !toBottom, false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LookLibraryMayPutToBottomEffect copy() {
|
||||
return new LookLibraryMayPutToBottomEffect(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.filter.FilterCard;
|
||||
|
||||
/**
|
||||
* @author awjackson
|
||||
*/
|
||||
public class RevealLibraryPickControllerEffect extends LookLibraryAndPickControllerEffect {
|
||||
|
||||
public RevealLibraryPickControllerEffect(int numberOfCards, int numberToPick, FilterCard filter,
|
||||
PutCards putPickedCards, PutCards putLookedCards) {
|
||||
this(numberOfCards, numberToPick, filter, putPickedCards, putLookedCards, true);
|
||||
}
|
||||
|
||||
public RevealLibraryPickControllerEffect(int numberOfCards, int numberToPick, FilterCard filter,
|
||||
PutCards putPickedCards, PutCards putLookedCards, boolean optional) {
|
||||
super(numberOfCards, numberToPick, filter, putPickedCards, putLookedCards, optional);
|
||||
this.revealCards = true;
|
||||
this.revealPickedCards = false;
|
||||
}
|
||||
|
||||
public RevealLibraryPickControllerEffect(final LookLibraryAndPickControllerEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RevealLibraryPickControllerEffect copy() {
|
||||
return new RevealLibraryPickControllerEffect(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
|
|
@ -14,13 +12,21 @@ import mage.players.Player;
|
|||
*/
|
||||
public class ShuffleLibrarySourceEffect extends OneShotEffect {
|
||||
|
||||
private boolean optional;
|
||||
|
||||
public ShuffleLibrarySourceEffect() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
public ShuffleLibrarySourceEffect(boolean optional) {
|
||||
super(Outcome.Neutral);
|
||||
this.staticText = "Shuffle your library";
|
||||
this.optional = optional;
|
||||
this.staticText = optional ? "you may shuffle" : "shuffle your library";
|
||||
}
|
||||
|
||||
public ShuffleLibrarySourceEffect(final ShuffleLibrarySourceEffect effect) {
|
||||
super(effect);
|
||||
this.optional = effect.optional;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -32,7 +38,9 @@ public class ShuffleLibrarySourceEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player != null) {
|
||||
player.shuffleLibrary(source, game);
|
||||
if (!optional || player.chooseUse(Outcome.Benefit, "Shuffle your library?", source, game)) {
|
||||
player.shuffleLibrary(source, game);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -64,6 +64,12 @@ public final class StaticFilters {
|
|||
FILTER_CARD_ARTIFACT.setLockedFilter(true);
|
||||
}
|
||||
|
||||
public static final FilterArtifactCard FILTER_CARD_ARTIFACTS = new FilterArtifactCard("artifact cards");
|
||||
|
||||
static {
|
||||
FILTER_CARD_ARTIFACTS.setLockedFilter(true);
|
||||
}
|
||||
|
||||
public static final FilterArtifactCard FILTER_CARD_ARTIFACT_AN = new FilterArtifactCard("an artifact card");
|
||||
|
||||
static {
|
||||
|
|
@ -939,6 +945,16 @@ public final class StaticFilters {
|
|||
FILTER_CARD_ARTIFACT_OR_CREATURE.setLockedFilter(true);
|
||||
}
|
||||
|
||||
public static final FilterCard FILTER_CARD_CREATURE_OR_LAND = new FilterCard("creature or land card");
|
||||
|
||||
static {
|
||||
FILTER_CARD_CREATURE_OR_LAND.add(Predicates.or(
|
||||
CardType.CREATURE.getPredicate(),
|
||||
CardType.LAND.getPredicate()
|
||||
));
|
||||
FILTER_CARD_CREATURE_OR_LAND.setLockedFilter(true);
|
||||
}
|
||||
|
||||
public static final FilterPlayer FILTER_PLAYER_CONTROLLER = new FilterPlayer("you");
|
||||
|
||||
static {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue