From 56ee36c7a38539408df0038799c8c9c3d45c641f Mon Sep 17 00:00:00 2001 From: Hanmac Date: Mon, 11 Jul 2016 13:41:30 +0000 Subject: [PATCH] AbilityUtils: applyTextChangeEffects: some fixes about textChange now replacement does not try to replace what was already replaced. (in description with a strike) exclude the ChosenColor from Any (replace Blue to Blue doesn't make any sense) for Types does use PluralType, that does help to replace "Forests" with "Plains", but also fixed the Problem with replaceing Creature Types in Keywords which are written as Plural and should stay as such. --- .../java/forge/game/ability/AbilityUtils.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/forge-game/src/main/java/forge/game/ability/AbilityUtils.java b/forge-game/src/main/java/forge/game/ability/AbilityUtils.java index 9c6e84c1dce..c8832952854 100644 --- a/forge-game/src/main/java/forge/game/ability/AbilityUtils.java +++ b/forge-game/src/main/java/forge/game/ability/AbilityUtils.java @@ -1618,20 +1618,27 @@ public class AbilityUtils { for (final byte c : MagicColor.WUBRG) { final String colorLowerCase = MagicColor.toLongString(c).toLowerCase(), colorCaptCase = StringUtils.capitalize(MagicColor.toLongString(c)); + // Color should not replace itself. + if (e.getValue().equalsIgnoreCase(colorLowerCase)) { + continue; + } value = getReplacedText(colorLowerCase, e.getValue(), isDescriptive); - replaced = replaced.replace(colorLowerCase, value.toLowerCase()); + replaced = replaced.replaceAll("(?)" + colorLowerCase, value.toLowerCase()); value = getReplacedText(colorCaptCase, e.getValue(), isDescriptive); - replaced = replaced.replace(colorCaptCase, StringUtils.capitalize(value)); + replaced = replaced.replaceAll("(?)" + colorCaptCase, StringUtils.capitalize(value)); } } else { value = getReplacedText(key, e.getValue(), isDescriptive); - replaced = replaced.replace(key, value); + replaced = replaced.replaceAll("(?)" + key, value); } } for (final Entry e : card.getChangedTextTypeWords().entrySet()) { final String key = e.getKey(); + final String pkey = CardUtil.getPluralType(key); + final String pvalue = getReplacedText(pkey, CardUtil.getPluralType(e.getValue()), isDescriptive); + replaced = replaced.replaceAll("(?)" + pkey, pvalue); final String value = getReplacedText(key, e.getValue(), isDescriptive); - replaced = replaced.replace(key, value); + replaced = replaced.replaceAll("(?)" + key, value); } return replaced; }