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:
Dapoulp 2025-07-29 22:34:09 +02:00 committed by GitHub
parent 2608c4a5ae
commit 8e516df7cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 172 additions and 86 deletions

View file

@ -1,10 +1,12 @@
import FormulaField from "../formulaField.mjs";
const fields = foundry.data.fields;
export default class UsesField extends fields.SchemaField {
constructor(options = {}, context = {}) {
const usesFields = {
value: new fields.NumberField({ nullable: true, initial: null }),
max: new fields.NumberField({ nullable: true, initial: null }),
max: new FormulaField({ nullable: true, initial: null, deterministic: true }),
recovery: new fields.StringField({
choices: CONFIG.DH.GENERAL.refreshTypes,
initial: null,
@ -33,6 +35,11 @@ export default class UsesField extends fields.SchemaField {
static hasUses(uses) {
if (!uses) return true;
return (uses.hasOwnProperty('enabled') && !uses.enabled) || uses.value + 1 <= uses.max;
let max = uses.max ?? 0;
if(isNaN(max)) {
const roll = new Roll(Roll.replaceFormulaData(uses.max, this.getRollData())).evaluateSync();
max = roll.total;
}
return (uses.hasOwnProperty('enabled') && !uses.enabled) || uses.value + 1 <= max;
}
}