mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 11:41:08 +01:00
55 lines
2 KiB
JavaScript
55 lines
2 KiB
JavaScript
import FormulaField from '../fields/formulaField.mjs';
|
|
|
|
const fields = foundry.data.fields;
|
|
|
|
export class DHActionDiceData extends foundry.abstract.DataModel {
|
|
/** @override */
|
|
static defineSchema() {
|
|
return {
|
|
multiplier: new fields.StringField({
|
|
choices: SYSTEM.GENERAL.multiplierTypes,
|
|
initial: 'proficiency',
|
|
label: 'Multiplier'
|
|
}),
|
|
dice: new fields.StringField({ choices: SYSTEM.GENERAL.diceTypes, initial: 'd6', label: 'Formula' }),
|
|
bonus: new fields.NumberField({ nullable: true, initial: null, label: 'Bonus' }),
|
|
custom: new fields.SchemaField({
|
|
enabled: new fields.BooleanField({ label: 'Custom Formula' }),
|
|
formula: new FormulaField({ label: 'Formula' })
|
|
})
|
|
};
|
|
}
|
|
|
|
getFormula(actor) {
|
|
return this.custom.enabled
|
|
? this.custom.formula
|
|
: `${actor.system[this.multiplier]?.total ?? 1}${this.dice}${this.bonus ? (this.bonus < 0 ? ` - ${Math.abs(this.bonus)}` : ` + ${this.bonus}`) : ''}`;
|
|
}
|
|
}
|
|
|
|
export class DHDamageField extends fields.SchemaField {
|
|
constructor(hasBase, options, context = {}) {
|
|
const damageFields = {
|
|
parts: new fields.ArrayField(new fields.EmbeddedDataField(DHDamageData))
|
|
};
|
|
if (hasBase) damageFields.includeBase = new fields.BooleanField({ initial: true });
|
|
super(damageFields, options, context);
|
|
}
|
|
}
|
|
|
|
export class DHDamageData extends DHActionDiceData {
|
|
/** @override */
|
|
static defineSchema() {
|
|
return {
|
|
...super.defineSchema(),
|
|
base: new fields.BooleanField({ initial: false, readonly: true, label: 'Base' }),
|
|
type: new fields.StringField({
|
|
choices: SYSTEM.GENERAL.damageTypes,
|
|
initial: 'physical',
|
|
label: 'Type',
|
|
nullable: false,
|
|
required: true
|
|
})
|
|
};
|
|
}
|
|
}
|