mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
Feature/443 adversary action roll type (#456)
* Some tests * Filter types choices * Resource/Uses max as FormulaField * Removed isReversed on item resources * Stuffs --------- Co-authored-by: WBHarry <williambjrklund@gmail.com>
This commit is contained in:
parent
2608c4a5ae
commit
8e516df7cb
19 changed files with 172 additions and 86 deletions
|
|
@ -26,11 +26,19 @@ export default class CostField extends fields.ArrayField {
|
|||
}
|
||||
|
||||
static calcCosts(costs) {
|
||||
console.log(costs, CostField.getResources.call(this, costs))
|
||||
const resources = CostField.getResources.call(this, costs);
|
||||
return costs.map(c => {
|
||||
c.scale = c.scale ?? 1;
|
||||
c.step = c.step ?? 1;
|
||||
c.total = c.value * c.scale * c.step;
|
||||
c.total = c.value + ((c.scale - 1) * c.step);
|
||||
c.enabled = c.hasOwnProperty('enabled') ? c.enabled : true;
|
||||
c.max = c.key === 'fear'
|
||||
? game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Resources.Fear)
|
||||
: resources[c.key].isReversed
|
||||
? resources[c.key].max
|
||||
: resources[c.key].value
|
||||
if(c.scalable) c.maxStep = Math.floor(c.max / c.step);
|
||||
return c;
|
||||
});
|
||||
}
|
||||
|
|
@ -51,9 +59,11 @@ export default class CostField extends fields.ArrayField {
|
|||
const resources = CostField.getResources.call(this, realCosts);
|
||||
return realCosts.reduce(
|
||||
(a, c) =>
|
||||
a && resources[c.key].isReversed
|
||||
? resources[c.key].value + (c.total ?? c.value) <= resources[c.key].max
|
||||
: resources[c.key]?.value >= (c.total ?? c.value),
|
||||
!resources[c.key]
|
||||
? a
|
||||
: a && resources[c.key].isReversed
|
||||
? resources[c.key].value + (c.total ?? c.value) <= resources[c.key].max
|
||||
: resources[c.key]?.value >= (c.total ?? c.value),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
|
@ -61,10 +71,11 @@ export default class CostField extends fields.ArrayField {
|
|||
static getResources(costs) {
|
||||
const actorResources = this.actor.system.resources;
|
||||
const itemResources = {};
|
||||
for (var itemResource of costs) {
|
||||
for (let itemResource of costs) {
|
||||
if (itemResource.keyIsID) {
|
||||
itemResources[itemResource.key] = {
|
||||
value: this.parent.resource.value ?? 0
|
||||
value: this.parent.resource.value ?? 0,
|
||||
max: CostField.formatMax.call(this, this.parent?.resource?.max)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -79,4 +90,13 @@ export default class CostField extends fields.ArrayField {
|
|||
const realCosts = costs?.length ? costs.filter(c => c.enabled) : [];
|
||||
return realCosts;
|
||||
}
|
||||
|
||||
static formatMax(max) {
|
||||
max ??= 0;
|
||||
if (isNaN(max)) {
|
||||
const roll = Roll.replaceFormulaData(max, this.getRollData());
|
||||
max = roll.total;
|
||||
}
|
||||
return Number(max);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue