mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 19:51:08 +01:00
75 lines
3.1 KiB
JavaScript
75 lines
3.1 KiB
JavaScript
const fields = foundry.data.fields;
|
|
|
|
export class DHActionRollData extends foundry.abstract.DataModel {
|
|
/** @override */
|
|
static defineSchema() {
|
|
return {
|
|
type: new fields.StringField({ nullable: true, initial: null, choices: CONFIG.DH.GENERAL.rollTypes }),
|
|
trait: new fields.StringField({ nullable: true, initial: null, choices: CONFIG.DH.ACTOR.abilities }),
|
|
difficulty: new fields.NumberField({ nullable: true, initial: null, integer: true, min: 0 }),
|
|
bonus: new fields.NumberField({ nullable: true, initial: null, integer: true }),
|
|
advState: new fields.StringField({
|
|
choices: CONFIG.DH.ACTIONS.advantageState,
|
|
initial: 'neutral'
|
|
}),
|
|
diceRolling: new fields.SchemaField({
|
|
multiplier: new fields.StringField({
|
|
choices: CONFIG.DH.GENERAL.diceSetNumbers,
|
|
initial: 'prof',
|
|
label: 'DAGGERHEART.ACTIONS.RollField.diceRolling.multiplier'
|
|
}),
|
|
flatMultiplier: new fields.NumberField({
|
|
nullable: true,
|
|
initial: 1,
|
|
label: 'DAGGERHEART.ACTIONS.RollField.diceRolling.flatMultiplier'
|
|
}),
|
|
dice: new fields.StringField({
|
|
choices: CONFIG.DH.GENERAL.diceTypes,
|
|
initial: CONFIG.DH.GENERAL.diceTypes.d6,
|
|
label: 'DAGGERHEART.ACTIONS.RollField.diceRolling.dice'
|
|
}),
|
|
compare: new fields.StringField({
|
|
choices: CONFIG.DH.ACTIONS.diceCompare,
|
|
nullable: true,
|
|
initial: null,
|
|
label: 'DAGGERHEART.ACTIONS.RollField.diceRolling.compare'
|
|
}),
|
|
treshold: new fields.NumberField({
|
|
integer: true,
|
|
nullable: true,
|
|
initial: null,
|
|
label: 'DAGGERHEART.ACTIONS.RollField.diceRolling.threshold'
|
|
})
|
|
}),
|
|
useDefault: new fields.BooleanField({ initial: false })
|
|
};
|
|
}
|
|
|
|
getFormula() {
|
|
if (!this.type) return;
|
|
let formula = '';
|
|
switch (this.type) {
|
|
case 'diceSet':
|
|
const multiplier =
|
|
this.diceRolling.multiplier === 'flat'
|
|
? this.diceRolling.flatMultiplier
|
|
: `@${this.diceRolling.multiplier}`;
|
|
if (this.diceRolling.compare && this.diceRolling.threshold) {
|
|
formula = `${multiplier}${this.diceRolling.dice}cs${CONFIG.DH.ACTIONS.diceCompare[this.diceRolling.compare].operator}${this.diceRolling.treshold}`;
|
|
} else {
|
|
formula = `${multiplier}${this.diceRolling.dice}`;
|
|
}
|
|
break;
|
|
default:
|
|
formula = '';
|
|
break;
|
|
}
|
|
return formula;
|
|
}
|
|
}
|
|
|
|
export default class RollField extends fields.EmbeddedDataField {
|
|
constructor(options, context = {}) {
|
|
super(DHActionRollData, options, context);
|
|
}
|
|
}
|