Merge branch 'sd' into 'master'

more Effect getStackDescription improvements

See merge request core-developers/forge!6275
This commit is contained in:
Michael Kamensky
2022-02-21 05:13:41 +00:00
3 changed files with 43 additions and 10 deletions

View File

@@ -25,6 +25,7 @@ import forge.game.spellability.SpellAbility;
import forge.util.Aggregates;
import forge.util.CardTranslation;
import forge.util.Localizer;
import forge.util.Lang;
public class CopySpellAbilityEffect extends SpellAbilityEffect {
@@ -48,7 +49,7 @@ public class CopySpellAbilityEffect extends SpellAbilityEffect {
amount = AbilityUtils.calculateAmount(sa.getHostCard(), sa.getParam("Amount"), sa);
}
if (amount > 1) {
sb.append(amount).append(" times");
sb.append(" ").append(Lang.getNumeral(amount)).append(" times");
}
sb.append(".");
// TODO probably add an optional "You may choose new targets..."

View File

@@ -6,6 +6,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import forge.util.Lang;
import org.apache.commons.lang3.StringUtils;
import com.google.common.collect.Maps;
@@ -217,20 +218,19 @@ public class SacrificeEffect extends SpellAbilityEffect {
sb.append("Sacrifices ").append(sa.getHostCard().toString());
} else if (valid.equals("Card.AttachedBy")) {
final Card toSac = sa.getHostCard().getEnchantingCard();
sb.append(toSac.getController()).append(" Sacrifices ").append(toSac).append(".");
sb.append(toSac.getController()).append(" sacrifices ").append(toSac).append(".");
} else {
for (final Player p : tgts) {
sb.append(p.getName()).append(" ");
}
sb.append(Lang.joinHomogenous(tgts)).append(" ");
boolean oneTgtP = tgts.size() == 1;
String msg = sa.getParamOrDefault("SacMessage", valid);
if (sa.hasParam("Destroy")) {
sb.append("Destroys ");
sb.append(oneTgtP ? "destroys " : " destroys ");
} else {
sb.append("Sacrifices ");
sb.append(oneTgtP ? "sacrifices " : "sacrifices ");
}
sb.append(amount).append(" ").append(msg).append(".");
sb.append(Lang.nounWithNumeralExceptOne(amount, msg)).append(".");
}
return sb.toString();

View File

@@ -17,6 +17,7 @@
*/
package forge.game.ability.effects;
import java.util.Arrays;
import java.util.List;
import forge.util.Lang;
@@ -42,9 +43,40 @@ public class TokenEffect extends TokenEffectBase {
final Card host = sa.getHostCard();
final List<Player> creators = AbilityUtils.getDefinedPlayers(host, sa.getParamOrDefault("TokenOwner",
"You"), sa);
String start = Lang.joinHomogenous(creators) + (creators.size() == 1 ? " creates" : " create");
String verb = creators.size() == 1 ? "creates" : "create";
String start = Lang.joinHomogenous(creators) + " " + verb;
String create = desc.contains("Create") ? "Create" : "create";
desc = desc.replace(create, start);
desc = desc.replaceFirst(".*" + create, "");
desc = start + desc;
//try to put the right amount of tokens for X calculations and the like
if (sa.hasParam("TokenAmount") && !StringUtils.isNumeric(sa.getParam("TokenAmount"))) {
final int numTokens = AbilityUtils.calculateAmount(host, sa.getParam("TokenAmount"), sa);
if (numTokens != 0) { //0 probably means calculation isn't ready in time for stack
if (numTokens != 1) { //if we are making more than one, substitute the numeral for a/an
String numeral = " " + Lang.getNumeral(numTokens) + " ";
List<String> words = Arrays.asList(desc.split(" "));
String target = " " + words.get(words.indexOf(verb) + 1) + " ";
desc = desc.replaceFirst(target, numeral);
}
//try to cut out unneeded description, which would now be confusing
String truncate = null;
if (desc.contains(", where")) {
truncate = ", where";
} else if (desc.contains(" for each")) {
truncate = " for each";
}
if (truncate != null) { //if we do truncate, make sure the string ends properly
desc = desc.split(truncate)[0];
if (desc.endsWith("token") && numTokens > 1) {
desc = desc + "s.";
} else {
desc = desc + ".";
}
}
}
}
//pronoun replacement for things that create an amount based on what you control
desc = desc.replace("you control","they control");
}
return desc;
}