Tweak TextChange transformation

This commit is contained in:
TRT
2023-05-12 22:14:26 +02:00
parent 2df79520e2
commit eed1220c31
7 changed files with 19 additions and 41 deletions

View File

@@ -45,7 +45,6 @@ public class ForgeScript {
int desiredColor = MagicColor.fromName(colorName); int desiredColor = MagicColor.fromName(colorName);
boolean hasColor = colors.hasAnyColor(desiredColor); boolean hasColor = colors.hasAnyColor(desiredColor);
return mustHave == hasColor; return mustHave == hasColor;
} else if (property.contains("Colorless")) { // ... Card is colorless } else if (property.contains("Colorless")) { // ... Card is colorless
boolean non = property.startsWith("non"); boolean non = property.startsWith("non");
boolean withSource = property.endsWith("Source"); boolean withSource = property.endsWith("Source");
@@ -53,34 +52,28 @@ public class ForgeScript {
return false; return false;
} }
return non != colors.isColorless(); return non != colors.isColorless();
} else if (property.contains("MultiColor")) { } else if (property.contains("MultiColor")) {
// ... Card is multicolored // ... Card is multicolored
if (property.endsWith("Source") && isColorlessSource) if (property.endsWith("Source") && isColorlessSource)
return false; return false;
return property.startsWith("non") != colors.isMulticolor(); return property.startsWith("non") != colors.isMulticolor();
} else if (property.contains("AllColors")) { } else if (property.contains("AllColors")) {
if (property.endsWith("Source") && isColorlessSource) if (property.endsWith("Source") && isColorlessSource)
return false; return false;
return property.startsWith("non") != colors.isAllColors(); return property.startsWith("non") != colors.isAllColors();
} else if (property.contains("MonoColor")) { // ... Card is monocolored } else if (property.contains("MonoColor")) { // ... Card is monocolored
if (property.endsWith("Source") && isColorlessSource) if (property.endsWith("Source") && isColorlessSource)
return false; return false;
return property.startsWith("non") != colors.isMonoColor(); return property.startsWith("non") != colors.isMonoColor();
} else if (property.startsWith("ChosenColor")) { } else if (property.startsWith("ChosenColor")) {
if (property.endsWith("Source") && isColorlessSource) if (property.endsWith("Source") && isColorlessSource)
return false; return false;
return source.hasChosenColor() && colors.hasAnyColor(MagicColor.fromName(source.getChosenColor())); return source.hasChosenColor() && colors.hasAnyColor(MagicColor.fromName(source.getChosenColor()));
} else if (property.startsWith("AnyChosenColor")) { } else if (property.startsWith("AnyChosenColor")) {
if (property.endsWith("Source") && isColorlessSource) if (property.endsWith("Source") && isColorlessSource)
return false; return false;
return source.hasChosenColor() return source.hasChosenColor()
&& colors.hasAnyColor(ColorSet.fromNames(source.getChosenColors()).getColor()); && colors.hasAnyColor(ColorSet.fromNames(source.getChosenColors()).getColor());
} else if (property.equals("AssociatedWithChosenColor")) { } else if (property.equals("AssociatedWithChosenColor")) {
final String color = source.getChosenColor(); final String color = source.getChosenColor();
switch (color) { switch (color) {

View File

@@ -79,8 +79,6 @@ import io.sentry.Sentry;
public class AbilityUtils { public class AbilityUtils {
private final static ImmutableList<String> cmpList = ImmutableList.of("LT", "LE", "EQ", "GE", "GT", "NE"); private final static ImmutableList<String> cmpList = ImmutableList.of("LT", "LE", "EQ", "GE", "GT", "NE");
static public final String WITH_DELIMITER = "((?<=%1$s)|(?=%1$s))";
// should the three getDefined functions be merged into one? Or better to // should the three getDefined functions be merged into one? Or better to
// have separate? // have separate?
// If we only have one, each function needs to Cast the Object to the // If we only have one, each function needs to Cast the Object to the
@@ -3012,10 +3010,8 @@ public class AbilityUtils {
public static final String applyDescriptionTextChangeEffects(final String def, final Card card) { public static final String applyDescriptionTextChangeEffects(final String def, final Card card) {
return applyTextChangeEffects(def, card, true); return applyTextChangeEffects(def, card, true);
} }
private static final String applyTextChangeEffects(final String def, final Card card, final boolean isDescriptive) { private static final String applyTextChangeEffects(final String def, final Card card, final boolean isDescriptive) {
return applyTextChangeEffects(def, isDescriptive, return applyTextChangeEffects(def, isDescriptive, card.getChangedTextColorWords(), card.getChangedTextTypeWords());
card.getChangedTextColorWords(), card.getChangedTextTypeWords());
} }
public static final String applyTextChangeEffects(final String def, final boolean isDescriptive, public static final String applyTextChangeEffects(final String def, final boolean isDescriptive,
@@ -3027,7 +3023,6 @@ public class AbilityUtils {
String replaced = def; String replaced = def;
for (final Entry<String, String> e : colorMap.entrySet()) { for (final Entry<String, String> e : colorMap.entrySet()) {
final String key = e.getKey(); final String key = e.getKey();
String value;
if (key.equals("Any")) { if (key.equals("Any")) {
for (final byte c : MagicColor.WUBRG) { for (final byte c : MagicColor.WUBRG) {
final String colorLowerCase = MagicColor.toLongString(c).toLowerCase(), final String colorLowerCase = MagicColor.toLongString(c).toLowerCase(),
@@ -3036,38 +3031,28 @@ public class AbilityUtils {
if (e.getValue().equalsIgnoreCase(colorLowerCase)) { if (e.getValue().equalsIgnoreCase(colorLowerCase)) {
continue; continue;
} }
value = getReplacedText(colorLowerCase, e.getValue(), isDescriptive); replaced = getReplacedText(replaced, colorLowerCase, e.getValue().toLowerCase(), isDescriptive);
replaced = replaced.replaceAll("(?<!>)" + colorLowerCase, value.toLowerCase()); replaced = getReplacedText(replaced, colorCaptCase, e.getValue(), isDescriptive);
value = getReplacedText(colorCaptCase, e.getValue(), isDescriptive);
replaced = replaced.replaceAll("(?<!>)" + colorCaptCase, StringUtils.capitalize(value));
} }
} else { } else {
value = getReplacedText(key, e.getValue(), isDescriptive); replaced = getReplacedText(replaced, key, e.getValue(), isDescriptive);
replaced = replaced.replaceAll("(?<!>)" + key, value);
} }
} }
StringBuilder sb = new StringBuilder();
for (String replacedPart : replaced.split(String.format(WITH_DELIMITER, "\\."))) {
if (!replacedPart.equals("Self") && !replacedPart.equals(".")) {
for (final Entry<String, String> e : typeMap.entrySet()) { for (final Entry<String, String> e : typeMap.entrySet()) {
final String key = e.getKey(); final String key = e.getKey();
final String pkey = CardType.getPluralType(key); replaced = getReplacedText(replaced, CardType.getPluralType(key), CardType.getPluralType(e.getValue()), isDescriptive);
final String pvalue = getReplacedText(pkey, CardType.getPluralType(e.getValue()), isDescriptive); replaced = getReplacedText(replaced, key, e.getValue(), isDescriptive);
replacedPart = replacedPart.replaceAll("(?<!>)" + pkey, pvalue);
final String value = getReplacedText(key, e.getValue(), isDescriptive);
replacedPart = replacedPart.replaceAll("(?<!>)" + key, value);
}
}
sb.append(replacedPart);
}
return sb.toString();
} }
private static final String getReplacedText(final String originalWord, final String newWord, final boolean isDescriptive) { return replaced;
if (isDescriptive) {
return "<strike>" + originalWord + "</strike> " + newWord;
} }
return newWord;
private static final String getReplacedText(final String text, final String originalWord, String newWord, final boolean isDescriptive) {
if (isDescriptive) {
newWord = "<strike>" + originalWord + "</strike> " + newWord;
}
// use word boundaries and keep negations
return text.replaceAll((isDescriptive ? "(?<!>)" : "") + "\\b(non)?" + originalWord, "$1" + newWord);
} }
public static final String getSVar(final CardTraitBase ability, final String sVarName) { public static final String getSVar(final CardTraitBase ability, final String sVarName) {

View File

@@ -1602,7 +1602,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
} }
runParams.put(AbilityKey.CounterAmount, delta); runParams.put(AbilityKey.CounterAmount, delta);
runParams.put(AbilityKey.NewCounterAmount, newValue); runParams.put(AbilityKey.NewCounterAmount, newValue);
getGame().getTriggerHandler().runTrigger(TriggerType.CounterRemovedOnce, AbilityKey.newMap(runParams), false); getGame().getTriggerHandler().runTrigger(TriggerType.CounterRemovedOnce, runParams, false);
} }
@Override @Override

View File

@@ -97,7 +97,6 @@ public class CostReveal extends CostPartWithList {
} else { } else {
return amount <= getMaxAmountX(ability, payer, effect); return amount <= getMaxAmountX(ability, payer, effect);
} }
} }
@Override @Override

View File

@@ -5,7 +5,7 @@ PT:3/2
K:Flying K:Flying
T:Mode$ Phase | Phase$ Upkeep | ValidPlayer$ You | TriggerZones$ Battlefield | Execute$ TrigMill | TriggerDescription$ At the beginning of your upkeep, mill a card. If an instant or sorcery card was milled this way, transform CARDNAME. T:Mode$ Phase | Phase$ Upkeep | ValidPlayer$ You | TriggerZones$ Battlefield | Execute$ TrigMill | TriggerDescription$ At the beginning of your upkeep, mill a card. If an instant or sorcery card was milled this way, transform CARDNAME.
SVar:TrigMill:DB$ Mill | Defined$ You | RememberMilled$ True | SubAbility$ DBTransform SVar:TrigMill:DB$ Mill | Defined$ You | RememberMilled$ True | SubAbility$ DBTransform
SVar:DBTransform:DB$ SetState | Defined$ Self | ConditionDefined$ Remembered | ConditionPresent$ Card.Instant,Card.Sorcery | ConditionCompare$ EQ1 | SubAbility$ Cleanup | Mode$ Transform SVar:DBTransform:DB$ SetState | Defined$ Self | ConditionDefined$ Remembered | ConditionPresent$ Card.Instant,Card.Sorcery | SubAbility$ Cleanup | Mode$ Transform
SVar:Cleanup:DB$ Cleanup | ClearRemembered$ True SVar:Cleanup:DB$ Cleanup | ClearRemembered$ True
DeckHints:Ability$Delirium & Type$Instant|Sorcery DeckHints:Ability$Delirium & Type$Instant|Sorcery
AlternateMode:DoubleFaced AlternateMode:DoubleFaced

View File

@@ -1,7 +1,7 @@
Name:Devout Invocation Name:Devout Invocation
ManaCost:6 W ManaCost:6 W
Types:Sorcery Types:Sorcery
A:SP$ Tap | CardChoices$ Creature.YouCtrl+untapped | AnyNumber$ True | ChoiceAmount$ Count$Valid Creature.YouCtrl+untapped | RememberTapped$ True | SpellDescription$ Tap any number of untapped creatures you control. Create a 4/4 white Angel creature token with flying for each creature tapped this way. | StackDescription$ SpellDescription A:SP$ Tap | CardChoices$ Creature.YouCtrl+untapped | AnyNumber$ True | ChoiceAmount$ Count$Valid Creature.YouCtrl+untapped | RememberTapped$ True | SubAbility$ DBToken | SpellDescription$ Tap any number of untapped creatures you control. Create a 4/4 white Angel creature token with flying for each creature tapped this way. | StackDescription$ SpellDescription
SVar:DBToken:DB$ Token | TokenAmount$ Y | TokenScript$ w_4_4_angel_flying | TokenOwner$ You | SubAbility$ DBCleanup SVar:DBToken:DB$ Token | TokenAmount$ Y | TokenScript$ w_4_4_angel_flying | TokenOwner$ You | SubAbility$ DBCleanup
SVar:DBCleanup:DB$ Cleanup | ClearRemembered$ True SVar:DBCleanup:DB$ Cleanup | ClearRemembered$ True
SVar:Y:Remembered$Amount SVar:Y:Remembered$Amount

View File

@@ -7,9 +7,10 @@ T:Mode$ Phase | Phase$ Upkeep | ValidPlayer$ You | Execute$ TrigToken | TriggerZ
SVar:TrigToken:DB$ Token | TokenScript$ boo SVar:TrigToken:DB$ Token | TokenScript$ boo
A:AB$ PutCounter | Cost$ AddCounter<1/LOYALTY> | Planeswalker$ True | ValidTgts$ Creature.withTrample,Creature.withHaste | TgtPrompt$ Select target creature with trample or haste | TargetMin$ 0 | TargetMax$ 1 | CounterType$ P1P1 | CounterNum$ 3 | SpellDescription$ Put three +1/+1 counters on up to one target creature with trample or haste. A:AB$ PutCounter | Cost$ AddCounter<1/LOYALTY> | Planeswalker$ True | ValidTgts$ Creature.withTrample,Creature.withHaste | TgtPrompt$ Select target creature with trample or haste | TargetMin$ 0 | TargetMax$ 1 | CounterType$ P1P1 | CounterNum$ 3 | SpellDescription$ Put three +1/+1 counters on up to one target creature with trample or haste.
A:AB$ Sacrifice | Cost$ SubCounter<2/LOYALTY> | Planeswalker$ True | SacValid$ Creature | RememberSacrificed$ True | SubAbility$ DBImmediateTrigger | SpellDescription$ Sacrifice a creature. A:AB$ Sacrifice | Cost$ SubCounter<2/LOYALTY> | Planeswalker$ True | SacValid$ Creature | RememberSacrificed$ True | SubAbility$ DBImmediateTrigger | SpellDescription$ Sacrifice a creature.
SVar:DBImmediateTrigger:DB$ ImmediateTrigger | Execute$ TrigDamage | ConditionDefined$ RememberedLKI | ConditionPresent$ Creature | RememberObjects$ RememberedLKI | SpellDescription$ When you do, CARDNAME deals X damage to any target, where X is that creature's power. If the sacrificed creature was a Hamster, draw X cards. SVar:DBImmediateTrigger:DB$ ImmediateTrigger | Execute$ TrigDamage | ConditionDefined$ RememberedLKI | ConditionPresent$ Creature | RememberObjects$ RememberedLKI | SubAbility$ DBCleanup | SpellDescription$ When you do, CARDNAME deals X damage to any target, where X is that creature's power. If the sacrificed creature was a Hamster, draw X cards.
SVar:TrigDamage:DB$ DealDamage | ValidTgts$ Any | NumDmg$ X | SubAbility$ DBDraw SVar:TrigDamage:DB$ DealDamage | ValidTgts$ Any | NumDmg$ X | SubAbility$ DBDraw
SVar:DBDraw:DB$ Draw | ConditionDefined$ DelayTriggerRememberedLKI | ConditionPresent$ Hamster | NumCards$ X SVar:DBDraw:DB$ Draw | ConditionDefined$ DelayTriggerRememberedLKI | ConditionPresent$ Hamster | NumCards$ X
SVar:DBCleanup:DB$ Cleanup | ClearRemembered$ True
SVar:X:TriggerRemembered$CardPower SVar:X:TriggerRemembered$CardPower
K:CARDNAME can be your commander. K:CARDNAME can be your commander.
DeckHas:Ability$Sacrifice|Counters|Token DeckHas:Ability$Sacrifice|Counters|Token