Merge pull request #10369 from xenohedron/refactor-search

Refactor search library effect classes to clean up text generation
This commit is contained in:
xenohedron 2023-06-04 22:18:18 +03:00 committed by GitHub
commit 807a6c95f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
286 changed files with 377 additions and 469 deletions

View file

@ -7,7 +7,6 @@ import mage.abilities.costs.common.PayLifeCost;
import mage.abilities.costs.common.SacrificeSourceCost;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.filter.FilterCard;
@ -33,7 +32,7 @@ public class FetchLandActivatedAbility extends ActivatedAbilityImpl {
FilterCard filter = new FilterCard(subType1.getDescription() + " or " + subType2.getDescription() + " card");
filter.add(Predicates.or(subType1.getPredicate(), subType2.getPredicate()));
TargetCardInLibrary target = new TargetCardInLibrary(filter);
addEffect(new SearchLibraryPutInPlayEffect(target, false, true, Outcome.PutLandInPlay));
addEffect(new SearchLibraryPutInPlayEffect(target, false));
}
private FetchLandActivatedAbility(FetchLandActivatedAbility ability) {

View file

@ -11,7 +11,6 @@ import mage.constants.Zone;
import mage.game.Game;
import mage.players.Player;
import mage.target.common.TargetCardInLibrary;
import mage.util.CardUtil;
import java.util.UUID;
@ -20,35 +19,24 @@ import java.util.UUID;
*/
public class SearchLibraryPutInHandEffect extends SearchEffect {
private boolean revealCards = false;
private boolean forceShuffle;
private String rulePrefix;
private boolean reveal;
private boolean textThatCard;
public SearchLibraryPutInHandEffect(TargetCardInLibrary target) {
this(target, false, true);
public SearchLibraryPutInHandEffect(TargetCardInLibrary target, boolean reveal) {
this(target, reveal, false);
}
public SearchLibraryPutInHandEffect(TargetCardInLibrary target, boolean revealCards) {
this(target, revealCards, true);
}
public SearchLibraryPutInHandEffect(TargetCardInLibrary target, boolean revealCards, boolean forceShuffle) {
this(target, revealCards, forceShuffle, "search your library for ");
}
public SearchLibraryPutInHandEffect(TargetCardInLibrary target, boolean revealCards, boolean forceShuffle, String rulePrefix) {
public SearchLibraryPutInHandEffect(TargetCardInLibrary target, boolean reveal, boolean textThatCard) {
super(target, Outcome.DrawCard);
this.revealCards = revealCards;
this.forceShuffle = forceShuffle;
this.rulePrefix = rulePrefix;
this.reveal = reveal;
this.textThatCard = textThatCard;
setText();
}
public SearchLibraryPutInHandEffect(final SearchLibraryPutInHandEffect effect) {
super(effect);
this.revealCards = effect.revealCards;
this.forceShuffle = effect.forceShuffle;
this.rulePrefix = effect.rulePrefix;
this.reveal = effect.reveal;
this.textThatCard = effect.textThatCard;
}
@Override
@ -73,7 +61,7 @@ public class SearchLibraryPutInHandEffect extends SearchEffect {
}
}
controller.moveCards(cards, Zone.HAND, source, game);
if (revealCards) {
if (reveal) {
String name = "Reveal";
Card sourceCard = game.getCard(source.getSourceId());
if (sourceCard != null) {
@ -85,35 +73,34 @@ public class SearchLibraryPutInHandEffect extends SearchEffect {
controller.shuffleLibrary(source, game);
return true;
}
if (forceShuffle) {
controller.shuffleLibrary(source, game);
}
controller.shuffleLibrary(source, game);
return false;
}
private void setText() {
StringBuilder sb = new StringBuilder();
sb.append(rulePrefix);
if (target.getNumberOfTargets() == 0 && target.getMaxNumberOfTargets() > 0) {
sb.append("up to ").append(CardUtil.numberToText(target.getMaxNumberOfTargets())).append(' ');
sb.append(target.getTargetName());
if (forceShuffle) {
sb.append(revealCards ? ", reveal them" : "");
sb.append(", put them into your hand, then shuffle");
sb.append("search your library for ");
sb.append(target.getDescription());
if (target.getMaxNumberOfTargets() > 1) {
if (reveal) {
sb.append(", reveal ");
sb.append(textThatCard ? "those cards" : "them");
sb.append(", put them");
} else {
sb.append(revealCards ? ", reveal them," : "");
sb.append(" and put them into your hand. If you do, shuffle");
sb.append(", put ");
sb.append(textThatCard ? "those cards" : "them");
}
} else {
sb.append(CardUtil.addArticle(target.getTargetName()));
if (forceShuffle) {
sb.append(revealCards ? ", reveal it, put it" : ", put that card");
sb.append(" into your hand, then shuffle");
if (reveal) {
sb.append(", reveal ");
sb.append(textThatCard ? "that card" : "it");
sb.append(", put it");
} else {
sb.append(revealCards ? ", reveal it," : "");
sb.append(" and put that card into your hand. If you do, shuffle");
sb.append(", put ");
sb.append(textThatCard ? "that card" : "it");
}
}
sb.append(" into your hand, then shuffle");
staticText = sb.toString();
}

View file

@ -20,28 +20,12 @@ import mage.util.CardUtil;
*/
public class SearchLibraryPutInHandOrOnBattlefieldEffect extends SearchEffect {
private boolean revealCards = false;
private boolean forceShuffle;
private String rulePrefix;
private String nameToPutOnBattlefield = null;
public SearchLibraryPutInHandOrOnBattlefieldEffect(TargetCardInLibrary target, String nameToPutOnBattlefield) {
this(target, false, true, nameToPutOnBattlefield);
}
private boolean revealCards;
private String nameToPutOnBattlefield;
public SearchLibraryPutInHandOrOnBattlefieldEffect(TargetCardInLibrary target, boolean revealCards, String nameToPutOnBattlefield) {
this(target, revealCards, true, nameToPutOnBattlefield);
}
public SearchLibraryPutInHandOrOnBattlefieldEffect(TargetCardInLibrary target, boolean revealCards, boolean forceShuffle, String nameToPutOnBattlefield) {
this(target, revealCards, forceShuffle, "search your library for ", nameToPutOnBattlefield);
}
public SearchLibraryPutInHandOrOnBattlefieldEffect(TargetCardInLibrary target, boolean revealCards, boolean forceShuffle, String rulePrefix, String nameToPutOnBattlefield) {
super(target, Outcome.DrawCard);
this.revealCards = revealCards;
this.forceShuffle = forceShuffle;
this.rulePrefix = rulePrefix;
this.nameToPutOnBattlefield = nameToPutOnBattlefield;
setText();
}
@ -49,8 +33,6 @@ public class SearchLibraryPutInHandOrOnBattlefieldEffect extends SearchEffect {
public SearchLibraryPutInHandOrOnBattlefieldEffect(final SearchLibraryPutInHandOrOnBattlefieldEffect effect) {
super(effect);
this.revealCards = effect.revealCards;
this.forceShuffle = effect.forceShuffle;
this.rulePrefix = effect.rulePrefix;
this.nameToPutOnBattlefield = effect.nameToPutOnBattlefield;
}
@ -98,15 +80,13 @@ public class SearchLibraryPutInHandOrOnBattlefieldEffect extends SearchEffect {
controller.shuffleLibrary(source, game);
return true;
}
if (forceShuffle) {
controller.shuffleLibrary(source, game);
}
controller.shuffleLibrary(source, game);
return false;
}
private void setText() {
StringBuilder sb = new StringBuilder();
sb.append(rulePrefix);
sb.append("search your library for ");
if (target.getNumberOfTargets() == 0 && target.getMaxNumberOfTargets() > 0) {
sb.append("up to ").append(CardUtil.numberToText(target.getMaxNumberOfTargets())).append(' ');
sb.append(target.getTargetName()).append(revealCards ? ", reveal them," : "").append(" and put them into your hand");
@ -118,11 +98,7 @@ public class SearchLibraryPutInHandOrOnBattlefieldEffect extends SearchEffect {
sb.append(nameToPutOnBattlefield);
sb.append("this way, you may put it onto the battlefield instead");
}
if (forceShuffle) {
sb.append(". Then shuffle");
} else {
sb.append(". If you do, shuffle");
}
sb.append(". Then shuffle");
staticText = sb.toString();
}

View file

@ -18,47 +18,38 @@ import java.util.UUID;
public class SearchLibraryPutInPlayEffect extends SearchEffect {
protected boolean tapped;
protected boolean forceShuffle;
protected boolean textThatCard;
protected boolean optional;
public SearchLibraryPutInPlayEffect(TargetCardInLibrary target) {
this(target, false, true, Outcome.PutCardInPlay);
this(target, false);
}
public SearchLibraryPutInPlayEffect(TargetCardInLibrary target, boolean tapped) {
this(target, tapped, true, Outcome.PutCardInPlay);
this(target, tapped, false);
}
public SearchLibraryPutInPlayEffect(TargetCardInLibrary target, boolean tapped, boolean forceShuffle) {
this(target, tapped, forceShuffle, Outcome.PutCardInPlay);
public SearchLibraryPutInPlayEffect(TargetCardInLibrary target, boolean tapped, boolean textThatCard) {
this(target, tapped, textThatCard, false);
}
public SearchLibraryPutInPlayEffect(TargetCardInLibrary target, boolean tapped, Outcome outcome) {
this(target, tapped, true, outcome);
}
public SearchLibraryPutInPlayEffect(TargetCardInLibrary target, boolean tapped, boolean forceShuffle, Outcome outcome) {
this(target, tapped, forceShuffle, false, outcome);
}
public SearchLibraryPutInPlayEffect(TargetCardInLibrary target, boolean tapped, boolean forceShuffle, boolean optional, Outcome outcome) {
super(target, outcome);
public SearchLibraryPutInPlayEffect(TargetCardInLibrary target, boolean tapped, boolean textThatCard, boolean optional) {
super(target, Outcome.PutCardInPlay);
this.tapped = tapped;
this.forceShuffle = forceShuffle;
this.textThatCard = textThatCard;
this.optional = optional;
staticText = (optional ? "you may " : "")
+ "search your library for "
+ target.getDescription()
+ (forceShuffle ? ", " : " and ")
+ (target.getMaxNumberOfTargets() > 1 ? "put them onto the battlefield" : "put it onto the battlefield")
+ (tapped ? " tapped" : "")
+ (forceShuffle ? ", then shuffle" : ". If you do, shuffle");
if (target.getDescription().contains("land")) {
this.outcome = Outcome.PutLandInPlay;
} else if (target.getDescription().contains("creature")) {
this.outcome = Outcome.PutCreatureInPlay;
}
setText();
}
public SearchLibraryPutInPlayEffect(final SearchLibraryPutInPlayEffect effect) {
super(effect);
this.tapped = effect.tapped;
this.forceShuffle = effect.forceShuffle;
this.textThatCard = effect.textThatCard;
this.optional = effect.optional;
}
@ -84,10 +75,29 @@ public class SearchLibraryPutInPlayEffect extends SearchEffect {
player.shuffleLibrary(source, game);
return true;
}
if (forceShuffle) {
player.shuffleLibrary(source, game);
player.shuffleLibrary(source, game);
return false;
}
private void setText() {
StringBuilder sb = new StringBuilder();
if (optional) {
sb.append("you may ");
}
return true;
sb.append("search your library for ");
sb.append(target.getDescription());
sb.append(", put ");
if (target.getMaxNumberOfTargets() > 1) {
sb.append(textThatCard ? "those cards" : "them");
} else {
sb.append(textThatCard ? "that card" : "it");
}
sb.append(" onto the battlefield");
if (tapped) {
sb.append(" tapped");
}
sb.append( ", then shuffle");
staticText = sb.toString();
}
public List<UUID> getTargets() {

View file

@ -16,40 +16,26 @@ import mage.target.common.TargetCardInLibrary;
public class SearchLibraryPutInPlayTargetPlayerEffect extends SearchEffect {
protected boolean tapped;
protected boolean forceShuffle;
protected boolean ownerIsController;
public SearchLibraryPutInPlayTargetPlayerEffect(TargetCardInLibrary target) {
this(target, false, true, Outcome.PutCardInPlay);
}
public SearchLibraryPutInPlayTargetPlayerEffect(TargetCardInLibrary target, boolean tapped) {
this(target, tapped, true, Outcome.PutCardInPlay);
this(target, tapped, false);
}
public SearchLibraryPutInPlayTargetPlayerEffect(TargetCardInLibrary target, boolean tapped, boolean forceShuffle) {
this(target, tapped, forceShuffle, Outcome.PutCardInPlay);
}
public SearchLibraryPutInPlayTargetPlayerEffect(TargetCardInLibrary target, boolean tapped, Outcome outcome) {
this(target, tapped, true, outcome);
}
public SearchLibraryPutInPlayTargetPlayerEffect(TargetCardInLibrary target, boolean tapped, boolean forceShuffle, Outcome outcome) {
this(target, tapped, forceShuffle, outcome, false);
}
public SearchLibraryPutInPlayTargetPlayerEffect(TargetCardInLibrary target, boolean tapped, boolean forceShuffle, Outcome outcome, boolean ownerIsController) {
super(target, outcome);
public SearchLibraryPutInPlayTargetPlayerEffect(TargetCardInLibrary target, boolean tapped, boolean ownerIsController) {
super(target, Outcome.PutCardInPlay);
this.tapped = tapped;
this.forceShuffle = forceShuffle;
this.ownerIsController = ownerIsController;
if (target.getDescription().contains("land")) {
this.outcome = Outcome.PutLandInPlay;
} else if (target.getDescription().contains("creature")) {
this.outcome = Outcome.PutCreatureInPlay;
}
}
public SearchLibraryPutInPlayTargetPlayerEffect(final SearchLibraryPutInPlayTargetPlayerEffect effect) {
super(effect);
this.tapped = effect.tapped;
this.forceShuffle = effect.forceShuffle;
this.ownerIsController = effect.ownerIsController;
}
@ -70,12 +56,8 @@ public class SearchLibraryPutInPlayTargetPlayerEffect extends SearchEffect {
player.shuffleLibrary(source, game);
return true;
}
if (forceShuffle) {
player.shuffleLibrary(source, game);
}
player.shuffleLibrary(source, game);
}
return false;
}
@ -87,9 +69,9 @@ public class SearchLibraryPutInPlayTargetPlayerEffect extends SearchEffect {
return getTargetPointer().describeTargets(mode.getTargets(), "that player")
+ " searches their library for "
+ target.getDescription()
+ (forceShuffle ? ", " : " and ")
+ ", "
+ (target.getMaxNumberOfTargets() > 1 ? "puts them onto the battlefield" : "puts it onto the battlefield")
+ (tapped ? " tapped" : "")
+ (forceShuffle ? ", then shuffles" : ". If that player does, they shuffle");
+ ", then shuffles";
}
}

View file

@ -18,24 +18,16 @@ import mage.util.CardUtil;
public class SearchLibraryPutOnLibraryEffect extends SearchEffect {
private boolean reveal;
private boolean forceShuffle;
public SearchLibraryPutOnLibraryEffect(TargetCardInLibrary target) {
this(target, false, true);
setText();
}
public SearchLibraryPutOnLibraryEffect(TargetCardInLibrary target, boolean reveal, boolean forceShuffle) {
public SearchLibraryPutOnLibraryEffect(TargetCardInLibrary target, boolean reveal) {
super(target, Outcome.DrawCard);
this.reveal = reveal;
this.forceShuffle = forceShuffle;
setText();
}
public SearchLibraryPutOnLibraryEffect(final SearchLibraryPutOnLibraryEffect effect) {
super(effect);
this.reveal = effect.reveal;
this.forceShuffle = effect.forceShuffle;
}
@Override
@ -55,16 +47,11 @@ public class SearchLibraryPutOnLibraryEffect extends SearchEffect {
if (reveal && !foundCards.isEmpty()) {
controller.revealCards(sourceObject.getIdName(), foundCards, game);
}
if (forceShuffle) {
controller.shuffleLibrary(source, game);
}
controller.shuffleLibrary(source, game);
controller.putCardsOnTopOfLibrary(foundCards, game, source, reveal);
return true;
}
// shuffle
if (forceShuffle) {
controller.shuffleLibrary(source, game);
}
controller.shuffleLibrary(source, game);
return false;
}

View file

@ -27,7 +27,7 @@ public class CyclingAbility extends ActivatedAbilityImpl {
}
public CyclingAbility(Cost cost, FilterCard filter, String text) {
super(Zone.HAND, new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true, true), cost);
super(Zone.HAND, new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true), cost);
this.addCost(new CyclingDiscardCost());
this.cost = cost;
this.text = text;

View file

@ -4,7 +4,6 @@ import mage.abilities.Ability;
import mage.abilities.common.SpellCastControllerTriggeredAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.StaticFilters;
import mage.filter.common.FilterCreatureCard;
@ -23,7 +22,7 @@ public final class GarrukCallerOfBeastsEmblem extends Emblem {
*/
public GarrukCallerOfBeastsEmblem() {
super("Emblem Garruk");
Effect effect = new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(new FilterCreatureCard("creature card")), false, true, Outcome.PutCreatureInPlay);
Effect effect = new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(new FilterCreatureCard("creature card")), false);
Ability ability = new SpellCastControllerTriggeredAbility(Zone.COMMAND, effect, StaticFilters.FILTER_SPELL_A_CREATURE, true, false);
this.getAbilities().add(ability);
}

View file

@ -3,7 +3,6 @@ package mage.game.command.emblems;
import mage.abilities.common.BeginningOfYourEndStepTriggeredAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.StaticFilters;
import mage.game.command.Emblem;
@ -14,7 +13,7 @@ public class GarrukUnleashedEmblem extends Emblem {
// At the beginning of your end step, you may search your library for a creature card, put it onto the battlefield, then shuffle your library.
public GarrukUnleashedEmblem() {
super("Emblem Garruk");
Effect effect = new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(StaticFilters.FILTER_CARD_CREATURE), false, true, Outcome.PutCreatureInPlay)
Effect effect = new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(StaticFilters.FILTER_CARD_CREATURE), false)
.setText("search your library for a creature card, put it onto the battlefield, then shuffle");
this.getAbilities().add(new BeginningOfYourEndStepTriggeredAbility(Zone.COMMAND, effect, true));
}

View file

@ -49,7 +49,7 @@ public class TrailOfTheMageRingsPlane extends Plane {
this.getAbilities().add(ability);
// Active player can roll the planar die: Whenever you roll {CHAOS}, you may search your library for an instant or sorcery card, reveal it, put it into your hand, then shuffle your library
Effect chaosEffect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, new FilterInstantOrSorceryCard()), true, true);
Effect chaosEffect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, new FilterInstantOrSorceryCard()), true);
Target chaosTarget = null;
List<Effect> chaosEffects = new ArrayList<Effect>();