small optimization to DoIfCostPaid text generation

This commit is contained in:
Evan Kranzler 2021-02-04 10:18:39 -05:00
parent f38639e1db
commit 3727e2ea42
4 changed files with 12 additions and 30 deletions

View file

@ -13,8 +13,6 @@ import mage.game.Game;
import mage.players.Player;
import mage.util.CardUtil;
import java.util.Locale;
public class DoIfCostPaid extends OneShotEffect {
protected Effects executingEffects = new Effects();
@ -164,16 +162,7 @@ public class DoIfCostPaid extends OneShotEffect {
protected String getCostText() {
StringBuilder sb = new StringBuilder();
String costText = cost.getText();
if (costText != null
&& !costText.toLowerCase(Locale.ENGLISH).startsWith("put")
&& !costText.toLowerCase(Locale.ENGLISH).startsWith("return")
&& !costText.toLowerCase(Locale.ENGLISH).startsWith("exile")
&& !costText.toLowerCase(Locale.ENGLISH).startsWith("discard")
&& !costText.toLowerCase(Locale.ENGLISH).startsWith("sacrifice")
&& !costText.toLowerCase(Locale.ENGLISH).startsWith("remove")
&& !costText.toLowerCase(Locale.ENGLISH).startsWith("tap")
&& !costText.toLowerCase(Locale.ENGLISH).startsWith("reveal")
&& !costText.toLowerCase(Locale.ENGLISH).startsWith("pay")) {
if (!CardUtil.checkCostWords(costText)) {
sb.append("pay ");
}
return sb.append(costText).toString();

View file

@ -11,8 +11,6 @@ import mage.game.Game;
import mage.players.Player;
import mage.util.CardUtil;
import java.util.Locale;
public class DoWhenCostPaid extends OneShotEffect {
private final ReflexiveTriggeredAbility ability;
@ -80,16 +78,7 @@ public class DoWhenCostPaid extends OneShotEffect {
private String getCostText() {
StringBuilder sb = new StringBuilder();
String costText = cost.getText();
if (costText != null
&& !costText.toLowerCase(Locale.ENGLISH).startsWith("put")
&& !costText.toLowerCase(Locale.ENGLISH).startsWith("return")
&& !costText.toLowerCase(Locale.ENGLISH).startsWith("exile")
&& !costText.toLowerCase(Locale.ENGLISH).startsWith("discard")
&& !costText.toLowerCase(Locale.ENGLISH).startsWith("sacrifice")
&& !costText.toLowerCase(Locale.ENGLISH).startsWith("remove")
&& !costText.toLowerCase(Locale.ENGLISH).startsWith("tap")
&& !costText.toLowerCase(Locale.ENGLISH).startsWith("reveal")
&& !costText.toLowerCase(Locale.ENGLISH).startsWith("pay")) {
if (!CardUtil.checkCostWords(costText)) {
sb.append("pay ");
}
return sb.append(costText).toString();

View file

@ -11,6 +11,7 @@ import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.util.CardUtil;
import mage.util.ManaUtil;
import java.util.Locale;
@ -96,12 +97,7 @@ public class SacrificeSourceUnlessPaysEffect extends OneShotEffect {
StringBuilder sb = new StringBuilder("sacrifice {this} unless you ");
String costText = cost != null ? cost.getText() : "{X}";
if (costText.toLowerCase(Locale.ENGLISH).startsWith("discard")
|| costText.toLowerCase(Locale.ENGLISH).startsWith("remove")
|| costText.toLowerCase(Locale.ENGLISH).startsWith("return")
|| costText.toLowerCase(Locale.ENGLISH).startsWith("put")
|| costText.toLowerCase(Locale.ENGLISH).startsWith("exile")
|| costText.toLowerCase(Locale.ENGLISH).startsWith("sacrifice")) {
if (CardUtil.checkCostWords(costText)) {
sb.append(costText.substring(0, 1).toLowerCase(Locale.ENGLISH));
sb.append(costText.substring(1));
} else {

View file

@ -60,6 +60,10 @@ public final class CardUtil {
public static final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
private static final List<String> costWords = Arrays.asList(
"put", "return", "exile", "discard", "sacrifice", "remove", "tap", "reveal", "pay"
);
/**
* Increase spell or ability cost to be paid.
*
@ -1169,4 +1173,8 @@ public final class CardUtil {
}
return zcc;
}
public static boolean checkCostWords(String text) {
return text != null && costWords.stream().anyMatch(text.toLowerCase(Locale.ENGLISH)::startsWith);
}
}