Added Quantity as a possible cost

This commit is contained in:
WBHarry 2025-08-28 01:08:03 +02:00
parent fa0fa1f9ee
commit 26ce421d9c
7 changed files with 89 additions and 53 deletions

View file

@ -46,16 +46,11 @@ export default class CostField extends fields.ArrayField {
if (this.parent?.parent) {
for (var cost of config.costs) {
if (cost.keyIsID) {
if (cost.itemId) {
usefulResources[cost.key] = {
value: cost.value,
target: this.parent.parent,
keyIsID: true
};
} else if (cost.key === 'quantity') {
usefulResources[cost.key] = {
value: cost.value,
target: this.parent.parent
itemId: cost.itemId
};
}
}
@ -74,7 +69,7 @@ export default class CostField extends fields.ArrayField {
key: c.key,
value: (c.total ?? c.value) * (resource.isReversed ? 1 : -1),
target: resource.target,
keyIsID: resource.keyIsID
itemId: resource.itemId
});
return a;
}
@ -107,7 +102,12 @@ export default class CostField extends fields.ArrayField {
*/
static calcCosts(costs) {
const resources = CostField.getResources.call(this, costs);
return costs.map(c => {
let filteredCosts = costs;
if (this.parent.metadata.isQuantifiable && this.parent.consumeOnUse === false) {
filteredCosts = filteredCosts.filter(c => c.key !== 'quantity');
}
return filteredCosts.map(c => {
c.scale = c.scale ?? 0;
c.step = c.step ?? 1;
c.total = c.value + c.scale * c.step;
@ -167,17 +167,8 @@ export default class CostField extends fields.ArrayField {
actorResources.hope = foundry.utils.deepClone(this.actor.system.partner.system.resources.hope);
const itemResources = {};
for (let itemResource of costs) {
if (itemResource.keyIsID) {
itemResources[itemResource.key] = {
value: this.parent.resource.value ?? 0,
max: CostField.formatMax.call(this, this.parent?.resource?.max)
};
}
if (itemResource.key === 'quantity') {
itemResources[itemResource.key] = {
value: this.parent.quantity ?? 0,
max: null
};
if (itemResource.itemId) {
itemResources[itemResource.key] = CostField.getItemIdCostResource.bind(this)(itemResource);
}
}
@ -187,6 +178,38 @@ export default class CostField extends fields.ArrayField {
};
}
static getItemIdCostResource(itemResource) {
switch (itemResource.key) {
case CONFIG.DH.GENERAL.itemAbilityCosts.resource.id:
return {
value: this.parent.resource.value ?? 0,
max: CostField.formatMax.call(this, this.parent?.resource?.max)
};
case CONFIG.DH.GENERAL.itemAbilityCosts.quantity.id:
return {
value: this.parent.quantity ?? 0,
max: this.parent.quantity ?? 0
};
default:
return { value: 0, max: 0 };
}
}
static getItemIdCostUpdate(r) {
switch (r.key) {
case CONFIG.DH.GENERAL.itemAbilityCosts.resource.id:
return {
'system.resource.value': r.target.system.resource.value + r.value
};
case CONFIG.DH.GENERAL.itemAbilityCosts.quantity.id:
return {
'system.quantity': r.target.system.quantity + r.value
};
default:
return {};
}
}
/**
*
* @param {*} costs