add reloading feature

Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com>
This commit is contained in:
Gergely Brautigam 2026-07-14 20:24:19 +02:00
parent e9e8d2bd59
commit 9e4d8d637a
No known key found for this signature in database
GPG key ID: 3763870D61A6E2CA
8 changed files with 91 additions and 16 deletions

View file

@ -197,11 +197,29 @@ export default class CostField extends fields.ArrayField {
static getItemIdCostUpdate(r) {
switch (r.key) {
case CONFIG.DH.GENERAL.itemAbilityCosts.resource.id:
case CONFIG.DH.GENERAL.itemAbilityCosts.resource.id: {
const resource = r.target.system.resource;
let max = Number(resource.max);
if (!Number.isFinite(max) && resource.max) {
try {
max = Roll.safeEval(Roll.replaceFormulaData(resource.max, r.target.getRollData()));
} catch {
max = null;
}
}
const hasMax = Number.isFinite(max) && max > 0;
if (r.clear) {
return {
path: 'system.resource.value',
value: hasMax ? max : resource.value
};
}
const newValue = resource.value + r.value;
return {
path: 'system.resource.value',
value: r.target.system.resource.value + r.value
value: Math.max(hasMax ? Math.min(newValue, max) : newValue, 0)
};
}
case CONFIG.DH.GENERAL.itemAbilityCosts.quantity.id:
return {
path: 'system.quantity',