This commit is contained in:
WBHarry 2026-04-28 20:30:32 +02:00
parent 1cece731ee
commit dbb08fec8c
7 changed files with 113 additions and 12 deletions

View file

@ -4,6 +4,15 @@ import IterableTypedObjectField from '../iterableTypedObjectField.mjs';
const fields = foundry.data.fields;
const getDamageBaseFields = () => ({
parts: new IterableTypedObjectField(DHDamageData),
includeBase: new fields.BooleanField({
initial: false,
label: 'DAGGERHEART.ACTIONS.Settings.includeBase.label'
}),
direct: new fields.BooleanField({ initial: false, label: 'DAGGERHEART.CONFIG.DamageType.direct.name' }),
});
export default class DamageField extends fields.SchemaField {
/**
* Action Workflow order
@ -13,12 +22,13 @@ export default class DamageField extends fields.SchemaField {
/** @inheritDoc */
constructor(options, context = {}) {
const damageFields = {
parts: new IterableTypedObjectField(DHDamageData),
includeBase: new fields.BooleanField({
initial: false,
label: 'DAGGERHEART.ACTIONS.Settings.includeBase.label'
...getDamageBaseFields(),
altOutcomes: new fields.SchemaField({
successFear: new fields.EmbeddedDataField(AltDamageOutcome, { nullable: true, initial: null }),
failureHope: new fields.EmbeddedDataField(AltDamageOutcome, { nullable: true, initial: null }),
failureFear: new fields.EmbeddedDataField(AltDamageOutcome, { nullable: true, initial: null }),
critical: new fields.EmbeddedDataField(AltDamageOutcome, { nullable: true, initial: null })
}),
direct: new fields.BooleanField({ initial: false, label: 'DAGGERHEART.CONFIG.DamageType.direct.name' }),
groupAttack: new fields.StringField({
choices: CONFIG.DH.GENERAL.groupAttackRange,
blank: true,
@ -28,6 +38,12 @@ export default class DamageField extends fields.SchemaField {
super(damageFields, options, context);
}
getDamageData(outcome) {
if (outcome === 'successHope') return this;
return this.altOutcomes[outcome].data;
}
/**
* Roll Damage/Healing Action Workflow part.
* Must be called within Action context or similar.
@ -326,3 +342,17 @@ export class DHDamageData extends DHResourceData {
};
}
}
class AltDamageOutcome extends foundry.abstract.DataModel {
static defineSchema() {
return {
copyStandard: new fields.BooleanField({ required: true, initial: true }),
...getDamageBaseFields(),
/* Stuff */
}
}
get data() {
return this.copyStandard ? this.parent : {}; // If not copying, return data from the this alternate outcome
}
}