Corrected resource logic

This commit is contained in:
WBHarry 2025-07-09 12:56:25 +02:00
parent b08a7be88a
commit b3c630b977

View file

@ -337,7 +337,8 @@ export default class DHBaseAction extends foundry.abstract.DataModel {
const resources = config.costs const resources = config.costs
.filter(c => c.enabled !== false) .filter(c => c.enabled !== false)
.map(c => { .map(c => {
return { type: c.type, value: c.total ?? c.value }; const resource = this.actor.system.resources[c.type];
return { type: c.type, value: (c.total ?? c.value) * (resource.hasOwnProperty('maxTotal') ? 1 : -1) };
}); });
await this.actor.modifyResource(resources); await this.actor.modifyResource(resources);
@ -382,22 +383,21 @@ export default class DHBaseAction extends foundry.abstract.DataModel {
const realCosts = this.getRealCosts(costs), const realCosts = this.getRealCosts(costs),
hasFearCost = realCosts.findIndex(c => c.type === 'fear'); hasFearCost = realCosts.findIndex(c => c.type === 'fear');
if (hasFearCost > -1) { if (hasFearCost > -1) {
const fearCost = realCosts.splice(hasFearCost, 1); const fearCost = realCosts.splice(hasFearCost, 1)[0];
if ( if (
!game.user.isGM || !game.user.isGM ||
fearCost[0].total > game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Resources.Fear) fearCost.total > game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Resources.Fear)
) )
return false; return false;
} }
/* maxTotal is a sign that the resource is inverted, IE it counts upwards instead of down */
const resources = this.actor.system.resources; const resources = this.actor.system.resources;
return realCosts.reduce( return realCosts.reduce(
(a, c) => (a, c) =>
a && a && resources[c.type].hasOwnProperty('maxTotal')
!( ? resources[c.type].value + (c.total ?? c.value) <= resources[c.type].maxTotal
resources[c.type]?.value + (c.total ?? c.value) > : resources[c.type]?.value >= (c.total ?? c.value),
(resources[c.type]?.maxTotal ?? resources[c.type]?.total)
),
true true
); );
} }