Fixed so the damage calculation is correct. Fixed so the right tooltip is shown for attacks

This commit is contained in:
WBHarry 2025-12-01 16:25:59 +01:00
parent 8f917c3640
commit 51135b6a67
8 changed files with 48 additions and 32 deletions

View file

@ -161,6 +161,22 @@ export default class DamageField extends fields.SchemaField {
return formulaValue;
}
/**
* Return a display ready damage formula string
* Must be called within Action context or similar.
* @param {Array<object>} parts Damage Parts
* @param {object} data Action getRollData
* @returns Formula string
*/
static getFormulaString(parts) {
const strings = [];
for (const { value } of parts) {
strings.push(Roll.replaceFormulaData(value.getFormula(), this.actor?.getRollData() ?? {}));
}
return strings.join(' + ');
}
/**
* Prepare formulas for Damage Roll
* Must be called within Action context or similar.

View file

@ -35,14 +35,8 @@ export default class RegisterHandlebarsHelpers {
return accum;
}
static damageFormula(attack, actor) {
const traitTotal = actor.system.traits?.[attack.roll.trait]?.value;
const instances = [
attack.damage.parts.map(x => Roll.replaceFormulaData(x.value.getFormula(), actor)).join(' + '),
traitTotal
].filter(x => x);
return instances.join(traitTotal > 0 ? ' + ' : ' - ');
static damageFormula(attack) {
return game.system.api.fields.ActionFields.DamageField.getFormulaString.bind(attack)(attack.damage.parts);
}
static formulaValue(formula, item) {

View file

@ -64,9 +64,9 @@
</div>
<ul class="items-sidebar-list">
{{> 'daggerheart.inventory-item-compact'
item=document.system.attack
type='action'
noCompendiumEdit=true
item=document.system.attack
type='attack'
noCompendiumEdit=true
}}
</ul>
</div>

View file

@ -104,16 +104,16 @@
</div>
<ul class="items-sidebar-list">
{{#if document.system.usedUnarmed}}
{{> 'daggerheart.inventory-item-compact'
{{> 'daggerheart.inventory-item-compact'
item=document.system.usedUnarmed
type='action'
}}
type='attack'
}}
{{/if}}
{{#each document.items as |item|}}
{{#if item.system.equipped}}
{{> 'daggerheart.inventory-item-compact'
item=item
type=item.type
item=item
type=item.type
}}
{{/if}}
{{/each}}

View file

@ -28,7 +28,7 @@
<ul class="items-list">
{{> 'daggerheart.inventory-item-compact'
item=document.system.attack
type='action'
type='attack'
hideTooltip=true
}}
</ul>

View file

@ -44,7 +44,7 @@
</div>
<div class="tooltip-information">
<label>{{localize "DAGGERHEART.GENERAL.damage"}}</label>
<div>{{damageFormula item.system.attack item}}</div>
<div>{{damageFormula item.system.attack}}</div>
</div>
</div>

View file

@ -4,22 +4,28 @@
<div class="tooltip-description">{{{description}}}</div>
<div class="tooltip-information-section spaced">
<div class="tooltip-information">
<label>{{localize "DAGGERHEART.GENERAL.Trait.single"}}</label>
{{#with (lookup config.ACTOR.abilities attack.roll.trait) as | trait |}}
<div>{{localize trait.label}}</div>
{{/with}}
</div>
<div class="tooltip-information">
<label>{{localize "DAGGERHEART.GENERAL.range"}}</label>
{{#with (lookup config.GENERAL.range attack.range) as | range |}}
<div>{{localize range.label}}</div>
{{/with}}
</div>
{{#if (lookup config.ACTOR.abilities attack.roll.trait)}}
<div class="tooltip-information">
<label>{{localize "DAGGERHEART.GENERAL.Trait.single"}}</label>
{{#with (lookup config.ACTOR.abilities attack.roll.trait) as | trait |}}
<div>{{localize trait.label}}</div>
{{/with}}
</div>
{{/if}}
{{#if (lookup config.GENERAL.range attack.range)}}
<div class="tooltip-information">
<label>{{localize "DAGGERHEART.GENERAL.range"}}</label>
{{#with (lookup config.GENERAL.range attack.range) as | range |}}
<div>{{localize range.label}}</div>
{{/with}}
</div>
{{/if}}
<div class="tooltip-information">
<label>{{localize "DAGGERHEART.GENERAL.damage"}}</label>
<div>{{{damageFormula attack parent}}}</div>
<div>{{{damageFormula attack}}}</div>
</div>
<div class="tooltip-information">
<label>{{localize "DAGGERHEART.GENERAL.damageType"}}</label>

View file

@ -30,7 +30,7 @@
</div>
<div class="tooltip-information">
<label>{{localize "DAGGERHEART.GENERAL.damage"}}</label>
<div>{{{damageFormula item.system.attack item.parent}}}</div>
<div>{{{damageFormula item.system.attack}}}</div>
</div>
<div class="tooltip-information">
<label>{{localize "DAGGERHEART.GENERAL.damageType"}}</label>