Enforce maximum values for PF2e numbered conditions

Cap dying (4), doomed (3), wounded (3), and slowed (3) at their
rule-defined maximums. The domain clamps values in setConditionValue
and the condition picker disables the [+] button at the cap.

Closes #31

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lukas
2026-04-09 00:04:47 +02:00
parent 1c107a500b
commit 553e09f280
5 changed files with 120 additions and 20 deletions

View File

@@ -92,7 +92,11 @@ export function setConditionValue(
const { combatant: target } = found;
const current = target.conditions ?? [];
if (value <= 0) {
const def = CONDITION_DEFINITIONS.find((d) => d.id === conditionId);
const clampedValue =
def?.maxValue === undefined ? value : Math.min(value, def.maxValue);
if (clampedValue <= 0) {
const filtered = current.filter((c) => c.id !== conditionId);
const newConditions = filtered.length > 0 ? filtered : undefined;
return {
@@ -106,7 +110,7 @@ export function setConditionValue(
const existing = current.find((c) => c.id === conditionId);
if (existing) {
const updated = current.map((c) =>
c.id === conditionId ? { ...c, value } : c,
c.id === conditionId ? { ...c, value: clampedValue } : c,
);
return {
encounter: applyConditions(encounter, combatantId, updated),
@@ -115,17 +119,25 @@ export function setConditionValue(
type: "ConditionAdded",
combatantId,
condition: conditionId,
value,
value: clampedValue,
},
],
};
}
const added = sortByDefinitionOrder([...current, { id: conditionId, value }]);
const added = sortByDefinitionOrder([
...current,
{ id: conditionId, value: clampedValue },
]);
return {
encounter: applyConditions(encounter, combatantId, added),
events: [
{ type: "ConditionAdded", combatantId, condition: conditionId, value },
{
type: "ConditionAdded",
combatantId,
condition: conditionId,
value: clampedValue,
},
],
};
}