fixed issues with alternate cost text generation (fixes #8943)

This commit is contained in:
Evan Kranzler 2022-05-11 18:38:00 -04:00
parent bd38a1d851
commit 5316da040d
2 changed files with 12 additions and 24 deletions

View file

@ -12,7 +12,7 @@ import mage.game.Game;
public class AlternativeCostImpl<T extends AlternativeCostImpl<T>> extends CostsImpl<Cost> implements AlternativeCost {
protected String name;
protected String reminderText;
protected final String reminderText;
protected boolean isMana;
protected boolean activated;
@ -21,9 +21,7 @@ public class AlternativeCostImpl<T extends AlternativeCostImpl<T>> extends Costs
this.activated = false;
this.name = name;
this.isMana = cost instanceof ManaCost;
if (reminderText != null) {
this.reminderText = "<i>(" + reminderText + ")</i>";
}
this.reminderText = reminderText;
this.add(cost);
}
@ -63,11 +61,10 @@ public class AlternativeCostImpl<T extends AlternativeCostImpl<T>> extends Costs
*/
@Override
public String getReminderText() {
String replace = "";
if (reminderText != null && !reminderText.isEmpty()) {
replace = reminderText.replace("{cost}", this.getText(true));
return "<i>(" + reminderText.replace("{cost}", this.getText(true)) + ")</i>";
}
return replace;
return "";
}
/**

View file

@ -16,6 +16,7 @@ import mage.util.CardUtil;
import java.util.Iterator;
import java.util.UUID;
import java.util.stream.Collectors;
/**
* @author LevelX2
@ -250,23 +251,13 @@ public class AlternativeCostSourceAbility extends StaticAbility implements Alter
}
int numberCosts = 0;
String remarkText = "";
for (AlternativeCost alternativeCost : alternateCosts) {
if (numberCosts == 0) {
if (alternativeCost.getCost() instanceof ManaCost) {
sb.append("pay ");
}
sb.append(alternativeCost.getText(false));
remarkText = alternativeCost.getReminderText();
} else {
sb.append(" and ");
if (alternativeCost.getCost() instanceof ManaCost) {
sb.append("pay ");
}
String text = alternativeCost.getText(true);
sb.append(Character.toLowerCase(text.charAt(0))).append(text.substring(1));
}
++numberCosts;
}
sb.append(CardUtil.concatWithAnd(alternateCosts
.stream()
.map(cost -> cost.getCost() instanceof ManaCost
? "pay " + cost.getText(true)
: cost.getText(true))
.map(CardUtil::getTextWithFirstCharLowerCase)
.collect(Collectors.toList())));
if (condition == null || alternateCosts.size() == 1) {
sb.append(" rather than pay this spell's mana cost");
} else if (alternateCosts.isEmpty()) {