Json function fixes

- Fixed time evaluations not being case sensitive
- Set up ForEachFPCulture and ForEachShadowCulture functions that wrap the proper GameUtils functions.  Future reworks will need to point all culture-counting cards to use these functions so that count-altering modifiers (such as on the new Horn of Helm errata) will be respected.
This commit is contained in:
Christian 'ketura' McCarty
2022-12-23 01:41:02 -06:00
parent f4d9daaddc
commit 321e711d20
4 changed files with 23 additions and 12 deletions

View File

@@ -922,8 +922,8 @@
{
type: addThreats
amount: {
type: forEachFPCultureLessThan
amount: 4
type: forEachFPCulture
limit: 4
}
}
]

View File

@@ -33,7 +33,7 @@ public class PlayerResolver {
return actionContext.getPerformingPlayer();
};
}
else if (type.toLowerCase(Locale.ROOT).startsWith("frommemory(") && type.endsWith(")")) {
else if (type.toLowerCase().startsWith("frommemory(") && type.endsWith(")")) {
String memory = type.substring(type.indexOf("(") + 1, type.lastIndexOf(")"));
return (actionContext) -> actionContext.getValueFromMemory(memory);
}

View File

@@ -1,7 +1,6 @@
package com.gempukku.lotro.cards.build.field.effect.appender.resolver;
import com.gempukku.lotro.cards.build.InvalidCardDefinitionException;
import com.gempukku.lotro.common.Culture;
import com.gempukku.lotro.common.Phase;
public class TimeResolver {
@@ -15,17 +14,17 @@ public class TimeResolver {
}
private static Time parseTime(String value) throws InvalidCardDefinitionException {
if (value.startsWith("start(") && value.endsWith(")")) {
if (value.toLowerCase().startsWith("start(") && value.endsWith(")")) {
final String phaseName = value.substring(value.indexOf("(") + 1, value.lastIndexOf(")"));
return new Time(Phase.findPhase(phaseName), true, false);
}
else if (value.startsWith("end(") && value.endsWith(")")) {
else if (value.toLowerCase().startsWith("end(") && value.endsWith(")")) {
final String phaseName = value.substring(value.indexOf("(") + 1, value.lastIndexOf(")"));
if (phaseName.equals("current"))
if (phaseName.equalsIgnoreCase("current"))
return new Time(null, false, false);
return new Time(Phase.findPhase(phaseName), false, false);
}
else if (value.equals("endofturn"))
else if (value.equalsIgnoreCase("endofturn"))
return new Time(null, false, true);
else {
Phase phase = Phase.findPhase(value);

View File

@@ -250,12 +250,24 @@ public class ValueResolver {
int result = Math.max(0, spottable - over);
return new ConstantEvaluator(result);
};
} else if (type.equalsIgnoreCase("forEachFPCultureLessThan")) {
FieldUtils.validateAllowedFields(object, "amount");
final int lessThan = FieldUtils.getInteger(object.get("amount"), "amount");
} else if (type.equalsIgnoreCase("forEachFPCulture")) {
FieldUtils.validateAllowedFields(object, "limit", "over");
final int limit = FieldUtils.getInteger(object.get("limit"), "limit", Integer.MAX_VALUE);
final int over = FieldUtils.getInteger(object.get("over"), "over", 0);
return actionContext -> {
int spottable = GameUtils.getSpottableFPCulturesCount(actionContext.getGame(), actionContext.getPerformingPlayer());
int result = Math.max(0, lessThan - spottable);
int result = Math.max(0, spottable - over);
result = Math.min(limit, result);
return new ConstantEvaluator(result);
};
} else if (type.equalsIgnoreCase("forEachShadowCulture")) {
FieldUtils.validateAllowedFields(object, "limit", "over");
final int limit = FieldUtils.getInteger(object.get("limit"), "limit", Integer.MAX_VALUE);
final int over = FieldUtils.getInteger(object.get("over"), "over", 0);
return actionContext -> {
int spottable = GameUtils.getSpottableShadowCulturesCount(actionContext.getGame(), actionContext.getPerformingPlayer());
int result = Math.max(0, spottable - over);
result = Math.min(limit, result);
return new ConstantEvaluator(result);
};
} else if (type.equalsIgnoreCase("forEachInHand")) {