From c4448226e055b207576db54122d8abb8558278bb Mon Sep 17 00:00:00 2001 From: IrkTheImp <41175833+IrkTheImp@users.noreply.github.com> Date: Thu, 3 Jul 2025 18:02:44 -0500 Subject: [PATCH] 219-fix weapon action damage and display of calculation. (#250) * fix weapon action damage and display of calculation. * modify weapon data to split formula. * remove unused field --- lang/en.json | 3 ++- module/applications/config/Action.mjs | 7 +++--- module/applications/roll.mjs | 25 +++++++++++-------- .../applications/adversary-settings.mjs | 1 - module/data/action/action.mjs | 4 +-- module/data/item/weapon.mjs | 3 ++- module/dialogs/d20RollDialog.mjs | 8 +++--- templates/chat/duality-roll.hbs | 2 +- templates/chat/parts/damage-chat.hbs | 3 ++- templates/sheets/items/weapon/header.hbs | 3 ++- templates/sheets/items/weapon/settings.hbs | 6 +++-- 11 files changed, 36 insertions(+), 29 deletions(-) diff --git a/lang/en.json b/lang/en.json index d466b0fc..61498321 100755 --- a/lang/en.json +++ b/lang/en.json @@ -1546,7 +1546,8 @@ "Range": "Range", "Damage": { "Title": "Damage", - "Value": "Value", + "Die": "Die", + "Bonus": "Bonus", "Type": "Type" }, "Burden": "Burden", diff --git a/module/applications/config/Action.mjs b/module/applications/config/Action.mjs index 6b5f7b41..7e14bb33 100644 --- a/module/applications/config/Action.mjs +++ b/module/applications/config/Action.mjs @@ -38,7 +38,7 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) { } }; - static CLEAN_ARRAYS = ["damage.parts", "cost", "effects"]; + static CLEAN_ARRAYS = ['damage.parts', 'cost', 'effects']; _getTabs() { const tabs = { @@ -69,7 +69,6 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) { context.disableOption = this.disableOption.bind(this); context.isNPC = this.action.actor && this.action.actor.type !== 'character'; context.hasRoll = this.action.hasRoll; - console.log(context) return context; } @@ -97,9 +96,9 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) { _prepareSubmitData(event, formData) { const submitData = foundry.utils.expandObject(formData.object); - for ( const keyPath of this.constructor.CLEAN_ARRAYS ) { + for (const keyPath of this.constructor.CLEAN_ARRAYS) { const data = foundry.utils.getProperty(submitData, keyPath); - if ( data ) foundry.utils.setProperty(submitData, keyPath, Object.values(data)); + if (data) foundry.utils.setProperty(submitData, keyPath, Object.values(data)); } return submitData; } diff --git a/module/applications/roll.mjs b/module/applications/roll.mjs index 321ead6f..36188ad8 100644 --- a/module/applications/roll.mjs +++ b/module/applications/roll.mjs @@ -39,7 +39,6 @@ export class DHRoll extends Roll { if (config.dialog.configure !== false) { // Open Roll Dialog const DialogClass = config.dialog?.class ?? this.DefaultDialog; - console.log(roll, config); const configDialog = await DialogClass.configure(roll, config, message); if (!configDialog) return; } @@ -124,6 +123,18 @@ export class DHRoll extends Roll { } return (this._formula = this.constructor.getFormula(this.terms)); } + + static calculateTotalModifiers(roll, config) { + config.roll.modifierTotal = 0; + for (let i = 0; i < roll.terms.length; i++) { + if ( + roll.terms[i] instanceof foundry.dice.terms.NumericTerm && + !!roll.terms[i - 1] && + roll.terms[i - 1] instanceof foundry.dice.terms.OperatorTerm + ) + config.roll.modifierTotal += Number(`${roll.terms[i - 1].operator}${roll.terms[i].total}`); + } + } } export class DualityDie extends foundry.dice.terms.Die { @@ -299,15 +310,8 @@ export class D20Roll extends DHRoll { value: d.total }; }); - config.roll.modifierTotal = 0; - for (let i = 0; i < roll.terms.length; i++) { - if ( - roll.terms[i] instanceof foundry.dice.terms.NumericTerm && - !!roll.terms[i - 1] && - roll.terms[i - 1] instanceof foundry.dice.terms.OperatorTerm - ) - config.roll.modifierTotal += Number(`${roll.terms[i - 1].operator}${roll.terms[i].total}`); - } + + this.calculateTotalModifiers(roll, config); } resetFormula() { @@ -468,6 +472,7 @@ export class DamageRoll extends DHRoll { static async postEvaluate(roll, config = {}) { super.postEvaluate(roll, config); config.roll.type = config.type; + this.calculateTotalModifiers(roll, config); if (config.source?.message) { const chatMessage = ui.chat.collection.get(config.source.message); chatMessage.update({ 'system.damage': config }); diff --git a/module/applications/sheets/applications/adversary-settings.mjs b/module/applications/sheets/applications/adversary-settings.mjs index cc18d7f6..2ecdcb60 100644 --- a/module/applications/sheets/applications/adversary-settings.mjs +++ b/module/applications/sheets/applications/adversary-settings.mjs @@ -103,7 +103,6 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl context.systemFields = this.actor.system.schema.fields; context.systemFields.attack.fields = this.actor.system.attack.schema.fields; context.isNPC = true; - console.log(context) return context; } diff --git a/module/data/action/action.mjs b/module/data/action/action.mjs index 7bda6089..ddf4fb5c 100644 --- a/module/data/action/action.mjs +++ b/module/data/action/action.mjs @@ -231,6 +231,7 @@ export class DHBaseAction extends foundry.abstract.DataModel { } if (this.hasRoll) { + console.log(config); const rollConfig = this.prepareRoll(config); config.roll = rollConfig; config = await this.actor.diceRoll(config); @@ -242,7 +243,6 @@ export class DHBaseAction extends foundry.abstract.DataModel { if(t.hit) { const target = game.canvas.tokens.get(t.id), actor = target?.actor; - console.log(actor) if(!actor) return; actor.saveRoll({ event, @@ -629,7 +629,7 @@ export class DHAttackAction extends DHDamageAction { return { value: { multiplier: 'prof', - dice: this.item?.system?.damage.value, + dice: this.item?.system?.damage.dice, bonus: this.item?.system?.damage.bonus ?? 0 }, type: this.item?.system?.damage.type, diff --git a/module/data/item/weapon.mjs b/module/data/item/weapon.mjs index 9154eb31..ee59a7f7 100644 --- a/module/data/item/weapon.mjs +++ b/module/data/item/weapon.mjs @@ -32,7 +32,8 @@ export default class DHWeapon extends BaseDataItem { burden: new fields.StringField({ required: true, choices: SYSTEM.GENERAL.burden, initial: 'oneHanded' }), //DAMAGE damage: new fields.SchemaField({ - value: new FormulaField({ initial: 'd6' }), + dice: new fields.StringField({ choices: SYSTEM.GENERAL.diceTypes, initial: 'd6' }), + bonus: new fields.NumberField({ nullable: true, initial: null }), type: new fields.StringField({ required: true, choices: SYSTEM.GENERAL.damageTypes, diff --git a/module/dialogs/d20RollDialog.mjs b/module/dialogs/d20RollDialog.mjs index b21e79df..26efaf7d 100644 --- a/module/dialogs/d20RollDialog.mjs +++ b/module/dialogs/d20RollDialog.mjs @@ -9,7 +9,6 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio this.config.experiences = []; if (config.source?.action) { - console.log(config) this.item = config.data.parent.items.get(config.source.item) ?? config.data.parent; this.action = config.data.attack?._id == config.source.action @@ -51,7 +50,6 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio }; async _prepareContext(_options) { - console.log(this.config, this.roll) const context = await super._prepareContext(_options); context.hasRoll = !!this.config.roll; context.roll = this.roll; @@ -77,7 +75,7 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio } context.extraFormula = this.config.extraFormula; context.formula = this.roll.constructFormula(this.config); - + return context; } @@ -87,10 +85,10 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio this.config.costs = foundry.utils.mergeObject(this.config.costs, rest.costs); } if (this.config.uses) this.config.uses = foundry.utils.mergeObject(this.config.uses, rest.uses); - if(rest.roll?.dice) { + if (rest.roll?.dice) { Object.entries(rest.roll.dice).forEach(([key, value]) => { this.roll[key] = value; - }) + }); } this.config.extraFormula = rest.extraFormula; this.render(); diff --git a/templates/chat/duality-roll.hbs b/templates/chat/duality-roll.hbs index ff1e9894..9a530649 100644 --- a/templates/chat/duality-roll.hbs +++ b/templates/chat/duality-roll.hbs @@ -123,7 +123,7 @@
- {{!-- {{> 'systems/daggerheart/templates/chat/parts/damage-chat.hbs' damage=damage noTitle=true}} --}} + {{> 'systems/daggerheart/templates/chat/parts/damage-chat.hbs' damage=damage noTitle=true}}
diff --git a/templates/chat/parts/damage-chat.hbs b/templates/chat/parts/damage-chat.hbs index 096f09dc..f8d7cfed 100644 --- a/templates/chat/parts/damage-chat.hbs +++ b/templates/chat/parts/damage-chat.hbs @@ -17,7 +17,8 @@ {{/each}} - {{/each}} + {{/each}} + {{#if damage.roll.modifierTotal}}
{{#if (gt damage.roll.modifierTotal 0)}}+{{/if}}{{damage.roll.modifierTotal}}
{{/if}}
Total: {{damage.roll.total}}
diff --git a/templates/sheets/items/weapon/header.hbs b/templates/sheets/items/weapon/header.hbs index 5d33c6ae..7a10bcc1 100644 --- a/templates/sheets/items/weapon/header.hbs +++ b/templates/sheets/items/weapon/header.hbs @@ -14,7 +14,8 @@ - {{localize (concat 'DAGGERHEART.Range.' source.system.range '.name')}} - - {{source.system.damage.value}} + {{log this}} + {{source.system.damage.dice}} + {{source.system.damage.bonus}} ({{localize (concat 'DAGGERHEART.DamageType.' source.system.damage.type '.abbreviation')}}) - {{localize (concat 'DAGGERHEART.Burden.' source.system.burden)}} diff --git a/templates/sheets/items/weapon/settings.hbs b/templates/sheets/items/weapon/settings.hbs index aaa5192b..b431f1dd 100644 --- a/templates/sheets/items/weapon/settings.hbs +++ b/templates/sheets/items/weapon/settings.hbs @@ -19,8 +19,10 @@
{{localize "DAGGERHEART.Sheets.Weapon.Damage.Title"}} - {{localize "DAGGERHEART.Sheets.Weapon.Damage.Value"}} - {{formGroup systemFields.damage.fields.value value=source.system.damage.value}} + {{localize "DAGGERHEART.Sheets.Weapon.Damage.Die"}} + {{formGroup systemFields.damage.fields.dice value=source.system.damage.dice}} + {{localize "DAGGERHEART.Sheets.Weapon.Damage.Bonus"}} + {{formGroup systemFields.damage.fields.bonus value=source.system.damage.bonus}} {{localize "DAGGERHEART.Sheets.Weapon.Damage.Type"}} {{formGroup systemFields.damage.fields.type value=source.system.damage.type localize=true}}