mirror of
https://github.com/magefree/mage.git
synced 2025-12-30 07:22:03 -08:00
refactor text gen for ExileTopXMayPlayUntilEffect
This commit is contained in:
parent
038cf01aa8
commit
cac779cbec
62 changed files with 276 additions and 303 deletions
|
|
@ -0,0 +1,88 @@
|
|||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.dynamicvalue.common.StaticValue;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.asthought.PlayFromNotOwnHandZoneTargetEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.target.targetpointer.FixedTargets;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class ExileTopXMayPlayUntilEffect extends OneShotEffect {
|
||||
|
||||
private final DynamicValue amount;
|
||||
private final Duration duration;
|
||||
|
||||
public ExileTopXMayPlayUntilEffect(int amount, Duration duration) {
|
||||
this(StaticValue.get(amount), duration);
|
||||
}
|
||||
|
||||
public ExileTopXMayPlayUntilEffect(DynamicValue amount, Duration duration) {
|
||||
super(Outcome.Benefit);
|
||||
this.amount = amount.copy();
|
||||
this.duration = duration;
|
||||
makeText(amount.toString().equals("1") ? "that card" : "those cards", duration == Duration.EndOfTurn);
|
||||
}
|
||||
|
||||
private ExileTopXMayPlayUntilEffect(final ExileTopXMayPlayUntilEffect effect) {
|
||||
super(effect);
|
||||
this.amount = effect.amount.copy();
|
||||
this.duration = effect.duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExileTopXMayPlayUntilEffect copy() {
|
||||
return new ExileTopXMayPlayUntilEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller == null) {
|
||||
return false;
|
||||
}
|
||||
int resolvedAmount = amount.calculate(game, source, this);
|
||||
Set<Card> cards = controller.getLibrary().getTopCards(game, resolvedAmount);
|
||||
if (cards.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
controller.moveCardsToExile(cards, source, game, true, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source));
|
||||
// remove cards that could not be moved to exile
|
||||
cards.removeIf(card -> !Zone.EXILED.equals(game.getState().getZone(card.getId())));
|
||||
if (!cards.isEmpty()) {
|
||||
game.addEffect(new PlayFromNotOwnHandZoneTargetEffect(Zone.EXILED, duration)
|
||||
.setTargetPointer(new FixedTargets(cards, game)), source);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Until end of turn, ] you may play [refCardText] [this turn]
|
||||
*/
|
||||
public ExileTopXMayPlayUntilEffect withTextOptions(String refCardText, boolean durationRuleAtEnd) {
|
||||
makeText(refCardText, durationRuleAtEnd);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void makeText(String refCardText, boolean durationRuleAtEnd) {
|
||||
String text = "exile the top ";
|
||||
boolean singular = amount.toString().equals("1");
|
||||
text += singular ? "card" : CardUtil.numberToText(amount.toString()) + " cards";
|
||||
text += " of your library. ";
|
||||
if (durationRuleAtEnd) {
|
||||
text += "You may play " + refCardText + ' ' + (duration == Duration.EndOfTurn ? "this turn" : duration.toString());
|
||||
} else {
|
||||
text += CardUtil.getTextWithFirstCharUpperCase(duration.toString()) + ", you may play " + refCardText;
|
||||
}
|
||||
this.staticText = text;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,109 +0,0 @@
|
|||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.dynamicvalue.common.StaticValue;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.asthought.PlayFromNotOwnHandZoneTargetEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.target.targetpointer.FixedTargets;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class ExileTopXMayPlayUntilEndOfTurnEffect extends OneShotEffect {
|
||||
|
||||
private final DynamicValue amount;
|
||||
private final boolean showHint;
|
||||
private final Duration duration;
|
||||
|
||||
public ExileTopXMayPlayUntilEndOfTurnEffect(int amount) {
|
||||
this(amount, false);
|
||||
}
|
||||
|
||||
public ExileTopXMayPlayUntilEndOfTurnEffect(int amount, boolean showHint) {
|
||||
this(amount, showHint, Duration.EndOfTurn);
|
||||
}
|
||||
|
||||
public ExileTopXMayPlayUntilEndOfTurnEffect(int amount, boolean showHint, Duration duration) {
|
||||
this(StaticValue.get(amount), showHint, duration);
|
||||
}
|
||||
|
||||
public ExileTopXMayPlayUntilEndOfTurnEffect(DynamicValue amount) {
|
||||
this(amount, false);
|
||||
}
|
||||
|
||||
public ExileTopXMayPlayUntilEndOfTurnEffect(DynamicValue amount, boolean showHint) {
|
||||
this(amount, showHint, Duration.EndOfTurn);
|
||||
}
|
||||
|
||||
public ExileTopXMayPlayUntilEndOfTurnEffect(DynamicValue amount, boolean showHint, Duration duration) {
|
||||
super(Outcome.Benefit);
|
||||
this.amount = amount.copy();
|
||||
this.showHint = showHint;
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
private ExileTopXMayPlayUntilEndOfTurnEffect(final ExileTopXMayPlayUntilEndOfTurnEffect effect) {
|
||||
super(effect);
|
||||
this.amount = effect.amount.copy();
|
||||
this.showHint = effect.showHint;
|
||||
this.duration = effect.duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExileTopXMayPlayUntilEndOfTurnEffect copy() {
|
||||
return new ExileTopXMayPlayUntilEndOfTurnEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller == null) {
|
||||
return false;
|
||||
}
|
||||
int resolvedAmount = amount.calculate(game, source, this);
|
||||
Set<Card> cards = controller.getLibrary().getTopCards(game, resolvedAmount);
|
||||
if (cards.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
controller.moveCardsToExile(cards, source, game, true, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source));
|
||||
// remove cards that could not be moved to exile
|
||||
cards.removeIf(card -> !Zone.EXILED.equals(game.getState().getZone(card.getId())));
|
||||
if (!cards.isEmpty()) {
|
||||
game.addEffect(new PlayFromNotOwnHandZoneTargetEffect(Zone.EXILED, duration)
|
||||
.setTargetPointer(new FixedTargets(cards, game)), source);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
if (staticText != null && !staticText.isEmpty()) {
|
||||
return staticText;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder("exile the top ");
|
||||
if (amount.toString().equals("1")) {
|
||||
sb.append("card of your library. ");
|
||||
} else {
|
||||
sb.append(CardUtil.numberToText(amount.toString()));
|
||||
sb.append(" cards of your library. ");
|
||||
}
|
||||
sb.append(CardUtil.getTextWithFirstCharUpperCase(duration.toString()));
|
||||
sb.append(", you may play ");
|
||||
sb.append(amount.toString().equals("1") ? "that card"
|
||||
: amount.toString().equals("2") ? "those cards" // That is weird.
|
||||
: "cards exiled this way");
|
||||
|
||||
if (showHint) {
|
||||
sb.append(". <i>(You still pay its costs. You can play a land this way only if you have an available land play remaining.)</i>");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue