Added limit option to ForEachInMemory. Fixed Would Have Gone crashing the game :)

This commit is contained in:
Christian 'ketura' McCarty
2021-12-19 01:46:44 -06:00
parent 56bd66461a
commit dce7137b49
2 changed files with 19 additions and 19 deletions

View File

@@ -185,31 +185,30 @@
{
"type": "canSpot",
"filter": "name(Aragorn)"
}
],
"cost": [
{
"type": "chooseANumber",
"from": 0,
"to": 3,
"memorize": "chosenNumber"
},
{
"type": "discardStackedCards",
"count": {
"type": "fromMemory",
"memory": "chosenNumber"
},
"on": "self",
"memorize": "discardedFromStack"
"type": "canSpot",
"filter": "self,hasStacked(any)"
}
],
"cost": {
"type": "discardStackedCards",
"count": {
"type": "range",
"from": 1,
"to": {
"type": "countStacked",
"on": "self"
}
},
"memorize": "discardedCards"
},
"effect": {
"type": "modifyStrength",
"filter": "choose(companion,signet(aragorn))",
"amount": {
"type": "fromMemory",
"memory": "chosenNumber",
"type": "forEachInMemory",
"memory": "discardedCards",
"limit": 3
}
}

View File

@@ -106,11 +106,12 @@ public class ValueResolver {
FieldUtils.validateAllowedFields(object);
return (actionContext) -> (game, cardAffected) -> GameUtils.getRegion(actionContext.getGame());
} else if (type.equalsIgnoreCase("forEachInMemory")) {
FieldUtils.validateAllowedFields(object, "memory");
FieldUtils.validateAllowedFields(object, "memory", "limit");
final String memory = FieldUtils.getString(object.get("memory"), "memory");
final int limit = FieldUtils.getInteger(object.get("limit"), "limit", Integer.MAX_VALUE);
return (actionContext) -> {
final int count = actionContext.getCardsFromMemory(memory).size();
return new ConstantEvaluator(count);
return new ConstantEvaluator(Math.min(limit, count));
};
} else if (type.equalsIgnoreCase("forEachMatchingInMemory")) {
FieldUtils.validateAllowedFields(object, "memory", "filter", "limit");