From e223aab42cafacbcf2d1fdfc5d8a1cfdfbae40ea Mon Sep 17 00:00:00 2001 From: WBHarry Date: Sun, 27 Jul 2025 19:26:01 +0200 Subject: [PATCH] Added fixes to make beastforms work --- lang/en.json | 6 +++++- .../applications/dialogs/beastformDialog.mjs | 4 +++- .../sheets/api/application-mixin.mjs | 9 +++++++- module/data/action/beastformAction.mjs | 6 ++---- module/data/actor/character.mjs | 21 +++++++++++++++---- module/data/fields/action/rollField.mjs | 4 ++-- module/data/item/beastform.mjs | 11 ++++++---- 7 files changed, 44 insertions(+), 17 deletions(-) diff --git a/lang/en.json b/lang/en.json index a5c9132a..9274a33b 100755 --- a/lang/en.json +++ b/lang/en.json @@ -1272,7 +1272,11 @@ }, "attack": { "damage": { - "value": { "label": "Base Attack: Damage" } + "dice": { + "label": "Base Attack: Damage Dice Index", + "hint": "Index for the damage dice used on the basic attack. 0=d4, 1=d6, 2=d8, 3=d10, 4=d12, 5=d20" + }, + "bonus": { "label": "Base Attack: Damage Bonus" } }, "roll": { "trait": { "label": "Base Attack: Trait" } diff --git a/module/applications/dialogs/beastformDialog.mjs b/module/applications/dialogs/beastformDialog.mjs index 3c35b542..35bac11c 100644 --- a/module/applications/dialogs/beastformDialog.mjs +++ b/module/applications/dialogs/beastformDialog.mjs @@ -123,13 +123,15 @@ export default class BeastformDialog extends HandlebarsApplicationMixin(Applicat ); const compendiumBeastforms = await game.packs.get(`daggerheart.beastforms`)?.getDocuments(); - const beastformTiers = [...(compendiumBeastforms ? compendiumBeastforms : []), ...game.items].reduce( + const beastformTiers = [...game.items, ...(compendiumBeastforms ? compendiumBeastforms : [])].reduce( (acc, x) => { const tier = CONFIG.DH.GENERAL.tiers[x.system.tier]; if (x.type !== 'beastform' || tier.id > this.configData.tierLimit) return acc; if (!acc[tier.id]) acc[tier.id] = { label: game.i18n.localize(tier.label), values: {} }; + if (Object.values(acc[tier.id].values).find(existing => existing.value.name === x.name)) return acc; + acc[tier.id].values[x.uuid] = { selected: this.selected?.uuid == x.uuid, value: x, diff --git a/module/applications/sheets/api/application-mixin.mjs b/module/applications/sheets/api/application-mixin.mjs index b1b335fc..50c93617 100644 --- a/module/applications/sheets/api/application-mixin.mjs +++ b/module/applications/sheets/api/application-mixin.mjs @@ -123,7 +123,14 @@ export default function DHApplicationMixin(Base) { /**@inheritdoc */ async _onFirstRender(context, options) { await super._onFirstRender(context, options); - this.relatedDocs.filter(doc => doc).map(doc => (doc.apps[this.id] = this)); + + const docs = []; + for (var docData of this.relatedDocs) { + const doc = await foundry.utils.fromUuid(docData.uuid); + docs.push(doc); + } + + docs.filter(doc => doc).map(doc => (doc.apps[this.id] = this)); if (!!this.options.contextMenus.length) this._createContextMenus(); } diff --git a/module/data/action/beastformAction.mjs b/module/data/action/beastformAction.mjs index ad09e2fb..ee5f3c6a 100644 --- a/module/data/action/beastformAction.mjs +++ b/module/data/action/beastformAction.mjs @@ -4,15 +4,13 @@ import DHBaseAction from './baseAction.mjs'; export default class DhBeastformAction extends DHBaseAction { static extraSchemas = [...super.extraSchemas, 'beastform']; - async use(event, ...args) { + async use(_event, ...args) { const beastformConfig = this.prepareBeastformConfig(); const abort = await this.handleActiveTransformations(); if (abort) return; - const item = args[0]; - - const { selected, evolved, hybrid } = await BeastformDialog.configure(beastformConfig, item); + const { selected, evolved, hybrid } = await BeastformDialog.configure(beastformConfig, this.item); if (!selected) return; await this.transform(selected, evolved, hybrid); diff --git a/module/data/actor/character.mjs b/module/data/actor/character.mjs index 61511241..2a585e95 100644 --- a/module/data/actor/character.mjs +++ b/module/data/actor/character.mjs @@ -112,7 +112,7 @@ export default class DhCharacter extends BaseDataActor { value: { custom: { enabled: true, - formula: '@system.rules.attack.damage.value' + formula: '@profd4' } } } @@ -244,10 +244,19 @@ export default class DhCharacter extends BaseDataActor { }), attack: new fields.SchemaField({ damage: new fields.SchemaField({ - value: new fields.StringField({ + diceIndex: new fields.NumberField({ + integer: true, + min: 0, + max: 5, + initial: 0, + label: 'DAGGERHEART.GENERAL.Rules.attack.damage.dice.label', + hint: 'DAGGERHEART.GENERAL.Rules.attack.damage.dice.hint' + }), + bonus: new fields.NumberField({ required: true, - initial: '@profd4', - label: 'DAGGERHEART.GENERAL.Rules.attack.damage.value.label' + initial: 0, + min: 0, + label: 'DAGGERHEART.GENERAL.Rules.attack.damage.bonus.label' }) }), roll: new fields.SchemaField({ @@ -547,6 +556,10 @@ export default class DhCharacter extends BaseDataActor { const baseHope = this.resources.hope.value + (this.companion?.system?.resources?.hope ?? 0); this.resources.hope.value = Math.min(baseHope, this.resources.hope.max); this.attack.roll.trait = this.rules.attack.roll.trait ?? this.attack.roll.trait; + + const diceTypes = Object.keys(CONFIG.DH.GENERAL.diceTypes); + const attackDiceIndex = Math.max(Math.min(this.rules.attack.damage.diceIndex, 5), 0); + this.attack.damage.parts[0].value.custom.formula = `@prof${diceTypes[attackDiceIndex]}${this.rules.attack.damage.bonus ? ` + ${this.rules.attack.damage.bonus}` : ''}`; } getRollData() { diff --git a/module/data/fields/action/rollField.mjs b/module/data/fields/action/rollField.mjs index b01db06b..511e0660 100644 --- a/module/data/fields/action/rollField.mjs +++ b/module/data/fields/action/rollField.mjs @@ -10,12 +10,12 @@ export class DHActionRollData extends foundry.abstract.DataModel { bonus: new fields.NumberField({ nullable: true, initial: null, integer: true }), advState: new fields.StringField({ choices: CONFIG.DH.ACTIONS.advantageState, - initial: CONFIG.DH.ACTIONS.advantageState.neutral.label + initial: 'neutral' }), diceRolling: new fields.SchemaField({ multiplier: new fields.StringField({ choices: CONFIG.DH.GENERAL.diceSetNumbers, - initial: CONFIG.DH.GENERAL.diceSetNumbers.prof, + initial: 'prof', label: 'DAGGERHEART.ACTIONS.RollField.diceRolling.multiplier' }), flatMultiplier: new fields.NumberField({ diff --git a/module/data/item/beastform.mjs b/module/data/item/beastform.mjs index 478beac6..d17fbf82 100644 --- a/module/data/item/beastform.mjs +++ b/module/data/item/beastform.mjs @@ -94,10 +94,13 @@ export default class DHBeastform extends BaseDataItem { return false; } - const features = await this.parent.parent.createEmbeddedDocuments( - 'Item', - this.features.map(x => x.toObject()) - ); + const beastformFeatures = []; + for (let featureData of this.features) { + const feature = await foundry.utils.fromUuid(featureData.uuid); + beastformFeatures.push(feature.toObject()); + } + + const features = await this.parent.parent.createEmbeddedDocuments('Item', beastformFeatures); const extraEffects = await this.parent.parent.createEmbeddedDocuments( 'ActiveEffect',