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(
new TargetCardInLibrary(StaticFilters.FILTER_CARD_BASIC_LAND_A),
false, true
false, false, true
));
ability.addTarget(new TargetLandPermanent(filter));
this.addAbility(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;
@ -81,9 +80,8 @@ public class SearchLibraryPutInHandEffect extends SearchEffect {
private void setText() {
StringBuilder sb = new StringBuilder();
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());
sb.append(target.getDescription());
if (target.getMaxNumberOfTargets() > 1) {
if (revealCards) {
sb.append(", reveal ");
sb.append(textThatCard ? "those cards" : "them");
@ -93,7 +91,6 @@ public class SearchLibraryPutInHandEffect extends SearchEffect {
sb.append(textThatCard ? "those cards" : "them");
}
} else {
sb.append(CardUtil.addArticle(target.getTargetName()));
if (revealCards) {
sb.append(", reveal ");
sb.append(textThatCard ? "that card" : "it");
@ -102,7 +99,6 @@ public class SearchLibraryPutInHandEffect extends SearchEffect {
sb.append(", put ");
sb.append(textThatCard ? "that card" : "it");
}
}
sb.append(" into your hand, then shuffle");
staticText = sb.toString();

View file

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