Feature/666 experience hope cost (#728)

* h

* Character & Companion Experience Hope Cost
This commit is contained in:
Dapoulp 2025-08-08 23:31:01 +02:00 committed by GitHub
parent f9cb0954f9
commit 45b3569cba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 61 additions and 13 deletions

View file

@ -47,6 +47,7 @@ export default class CostField extends fields.ArrayField {
static hasCost(costs) {
const realCosts = CostField.getRealCosts.call(this, costs),
hasFearCost = realCosts.findIndex(c => c.key === 'fear');
if (hasFearCost > -1) {
const fearCost = realCosts.splice(hasFearCost, 1)[0];
if (
@ -70,7 +71,8 @@ export default class CostField extends fields.ArrayField {
}
static getResources(costs) {
const actorResources = this.actor.system.resources;
const actorResources = foundry.utils.deepClone(this.actor.system.resources);
if(this.actor.system.partner) actorResources.hope = foundry.utils.deepClone(this.actor.system.partner.system.resources.hope);
const itemResources = {};
for (let itemResource of costs) {
if (itemResource.keyIsID) {
@ -89,7 +91,13 @@ export default class CostField extends fields.ArrayField {
static getRealCosts(costs) {
const realCosts = costs?.length ? costs.filter(c => c.enabled) : [];
return realCosts;
let mergedCosts = [];
realCosts.forEach(c => {
const getCost = Object.values(mergedCosts).find(gc => gc.key === c.key);
if(getCost) getCost.total += c.total;
else mergedCosts.push(c);
});
return mergedCosts;
}
static formatMax(max) {