add textThatCard to SearchLibraryPutInPlayEffect, fix string builder

This commit is contained in:
xenohedron 2023-05-14 00:01:15 -04:00
parent b05e6d5cb1
commit bb8c59aafd
3 changed files with 33 additions and 15 deletions

View file

@ -54,7 +54,7 @@ public final class DemolitionField extends CardImpl {
)); ));
ability.addEffect(new SearchLibraryPutInPlayEffect( ability.addEffect(new SearchLibraryPutInPlayEffect(
new TargetCardInLibrary(StaticFilters.FILTER_CARD_BASIC_LAND_A), new TargetCardInLibrary(StaticFilters.FILTER_CARD_BASIC_LAND_A),
false, true false, false, true
)); ));
ability.addTarget(new TargetLandPermanent(filter)); ability.addTarget(new TargetLandPermanent(filter));
this.addAbility(ability); this.addAbility(ability);

View file

@ -11,7 +11,6 @@ import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.target.common.TargetCardInLibrary; import mage.target.common.TargetCardInLibrary;
import mage.util.CardUtil;
import java.util.UUID; import java.util.UUID;
@ -81,9 +80,8 @@ public class SearchLibraryPutInHandEffect extends SearchEffect {
private void setText() { private void setText() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("search your library for "); sb.append("search your library for ");
if (target.getNumberOfTargets() == 0 && target.getMaxNumberOfTargets() > 0) { sb.append(target.getDescription());
sb.append("up to ").append(CardUtil.numberToText(target.getMaxNumberOfTargets())).append(' '); if (target.getMaxNumberOfTargets() > 1) {
sb.append(target.getTargetName());
if (revealCards) { if (revealCards) {
sb.append(", reveal "); sb.append(", reveal ");
sb.append(textThatCard ? "those cards" : "them"); sb.append(textThatCard ? "those cards" : "them");
@ -93,7 +91,6 @@ public class SearchLibraryPutInHandEffect extends SearchEffect {
sb.append(textThatCard ? "those cards" : "them"); sb.append(textThatCard ? "those cards" : "them");
} }
} else { } else {
sb.append(CardUtil.addArticle(target.getTargetName()));
if (revealCards) { if (revealCards) {
sb.append(", reveal "); sb.append(", reveal ");
sb.append(textThatCard ? "that card" : "it"); sb.append(textThatCard ? "that card" : "it");
@ -102,7 +99,6 @@ public class SearchLibraryPutInHandEffect extends SearchEffect {
sb.append(", put "); sb.append(", put ");
sb.append(textThatCard ? "that card" : "it"); sb.append(textThatCard ? "that card" : "it");
} }
} }
sb.append(" into your hand, then shuffle"); sb.append(" into your hand, then shuffle");
staticText = sb.toString(); staticText = sb.toString();

View file

@ -18,6 +18,7 @@ import java.util.UUID;
public class SearchLibraryPutInPlayEffect extends SearchEffect { public class SearchLibraryPutInPlayEffect extends SearchEffect {
protected boolean tapped; protected boolean tapped;
protected boolean textThatCard;
protected boolean optional; protected boolean optional;
public SearchLibraryPutInPlayEffect(TargetCardInLibrary target) { public SearchLibraryPutInPlayEffect(TargetCardInLibrary target) {
@ -28,27 +29,27 @@ public class SearchLibraryPutInPlayEffect extends SearchEffect {
this(target, tapped, false); this(target, tapped, false);
} }
public SearchLibraryPutInPlayEffect(TargetCardInLibrary target, boolean tapped, boolean optional) { public SearchLibraryPutInPlayEffect(TargetCardInLibrary target, boolean tapped, boolean textThatCard) {
this(target, tapped, textThatCard, false);
}
public SearchLibraryPutInPlayEffect(TargetCardInLibrary target, boolean tapped, boolean textThatCard, boolean optional) {
super(target, Outcome.PutCardInPlay); super(target, Outcome.PutCardInPlay);
this.tapped = tapped; this.tapped = tapped;
this.textThatCard = textThatCard;
this.optional = optional; this.optional = optional;
if (target.getDescription().contains("land")) { if (target.getDescription().contains("land")) {
this.outcome = Outcome.PutLandInPlay; this.outcome = Outcome.PutLandInPlay;
} else if (target.getDescription().contains("creature")) { } else if (target.getDescription().contains("creature")) {
this.outcome = Outcome.PutCreatureInPlay; this.outcome = Outcome.PutCreatureInPlay;
} }
staticText = (optional ? "you may " : "") setText();
+ "search your library for "
+ target.getDescription()
+ ", "
+ (target.getMaxNumberOfTargets() > 1 ? "put them onto the battlefield" : "put it onto the battlefield")
+ (tapped ? " tapped" : "")
+ ", then shuffle";
} }
public SearchLibraryPutInPlayEffect(final SearchLibraryPutInPlayEffect effect) { public SearchLibraryPutInPlayEffect(final SearchLibraryPutInPlayEffect effect) {
super(effect); super(effect);
this.tapped = effect.tapped; this.tapped = effect.tapped;
this.textThatCard = effect.textThatCard;
this.optional = effect.optional; this.optional = effect.optional;
} }
@ -78,6 +79,27 @@ public class SearchLibraryPutInPlayEffect extends SearchEffect {
return false; return false;
} }
private void setText() {
StringBuilder sb = new StringBuilder();
if (optional) {
sb.append("you may ");
}
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() { public List<UUID> getTargets() {
return target.getTargets(); return target.getTargets();
} }