modify weapon data to split formula.

This commit is contained in:
IrkTheImp 2025-07-03 11:28:04 -05:00
parent b9be9b9667
commit 4d64a99bb9
6 changed files with 26 additions and 50 deletions

View file

@ -1546,7 +1546,8 @@
"Range": "Range", "Range": "Range",
"Damage": { "Damage": {
"Title": "Damage", "Title": "Damage",
"Value": "Value", "Die": "Die",
"Bonus": "Bonus",
"Type": "Type" "Type": "Type"
}, },
"Burden": "Burden", "Burden": "Burden",

View file

@ -123,6 +123,18 @@ export class DHRoll extends Roll {
} }
return (this._formula = this.constructor.getFormula(this.terms)); 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 { export class DualityDie extends foundry.dice.terms.Die {
@ -298,15 +310,8 @@ export class D20Roll extends DHRoll {
value: d.total value: d.total
}; };
}); });
config.roll.modifierTotal = 0;
for (let i = 0; i < roll.terms.length; i++) { this.calculateTotalModifiers(roll, config);
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}`);
}
} }
resetFormula() { resetFormula() {
@ -464,17 +469,10 @@ export class DamageRoll extends DHRoll {
static DefaultDialog = DamageDialog; static DefaultDialog = DamageDialog;
static async getDamageModifiers(roll) {
const modifierFormula = roll.formula.replace(/[\d]+d[\d]+([a-zA-Z0-9.<>!=]*)?/g, '').replace(/\s*\+\s*/, '');
const modifierRoll = new Roll(modifierFormula);
await modifierRoll.evaluate();
return modifierRoll.total;
}
static async postEvaluate(roll, config = {}) { static async postEvaluate(roll, config = {}) {
super.postEvaluate(roll, config); super.postEvaluate(roll, config);
config.roll.type = config.type; config.roll.type = config.type;
config.roll.modifierTotal = await this.getDamageModifiers(roll); this.calculateTotalModifiers(roll, config);
if (config.source?.message) { if (config.source?.message) {
const chatMessage = ui.chat.collection.get(config.source.message); const chatMessage = ui.chat.collection.get(config.source.message);
chatMessage.update({ 'system.damage': config }); chatMessage.update({ 'system.damage': config });

View file

@ -621,43 +621,15 @@ export class DHAttackAction extends DHDamageAction {
super.prepareData(); super.prepareData();
if (this.damage.includeBase && !!this.item?.system?.damage) { if (this.damage.includeBase && !!this.item?.system?.damage) {
const baseDamage = this.getParentDamage(); const baseDamage = this.getParentDamage();
this.cleanBaseDamage(baseDamage);
this.damage.parts.unshift(new DHDamageData(baseDamage)); this.damage.parts.unshift(new DHDamageData(baseDamage));
} }
} }
cleanBaseDamage(baseDamage) {
let possibleRoll = new Roll(baseDamage.value.dice);
let die = 'd6';
let modifier = 0;
let nextOperator = '+';
possibleRoll.terms.forEach(term => {
if (term instanceof DiceTerm) {
die = `d${term._faces}`;
}
if (term instanceof OperatorTerm) {
nextOperator = term.operator;
}
if (term instanceof NumericTerm) {
if (nextOperator == '+') {
modifier += term.number;
}
if (nextOperator == '-') {
modifier -= term.number;
}
}
});
return (baseDamage.value = { ...baseDamage.value, dice: die, bonus: modifier });
}
getParentDamage() { getParentDamage() {
return { return {
value: { value: {
multiplier: 'prof', multiplier: 'prof',
dice: this.item?.system?.damage.value, dice: this.item?.system?.damage.dice,
bonus: this.item?.system?.damage.bonus ?? 0 bonus: this.item?.system?.damage.bonus ?? 0
}, },
type: this.item?.system?.damage.type, type: this.item?.system?.damage.type,

View file

@ -32,6 +32,8 @@ export default class DHWeapon extends BaseDataItem {
burden: new fields.StringField({ required: true, choices: SYSTEM.GENERAL.burden, initial: 'oneHanded' }), burden: new fields.StringField({ required: true, choices: SYSTEM.GENERAL.burden, initial: 'oneHanded' }),
//DAMAGE //DAMAGE
damage: new fields.SchemaField({ damage: new fields.SchemaField({
dice: new fields.StringField({ choices: SYSTEM.GENERAL.diceTypes, initial: 'd6' }),
bonus: new fields.NumberField({ nullable: true, initial: null }),
value: new FormulaField({ initial: 'd6' }), value: new FormulaField({ initial: 'd6' }),
type: new fields.StringField({ type: new fields.StringField({
required: true, required: true,

View file

@ -14,7 +14,8 @@
<span>-</span> <span>-</span>
{{localize (concat 'DAGGERHEART.Range.' source.system.range '.name')}} {{localize (concat 'DAGGERHEART.Range.' source.system.range '.name')}}
<span>-</span> <span>-</span>
{{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.DamageType.' source.system.damage.type '.abbreviation')}})
<span>-</span> <span>-</span>
{{localize (concat 'DAGGERHEART.Burden.' source.system.burden)}} {{localize (concat 'DAGGERHEART.Burden.' source.system.burden)}}

View file

@ -19,8 +19,10 @@
<fieldset class="two-columns"> <fieldset class="two-columns">
<legend>{{localize "DAGGERHEART.Sheets.Weapon.Damage.Title"}}</legend> <legend>{{localize "DAGGERHEART.Sheets.Weapon.Damage.Title"}}</legend>
<span>{{localize "DAGGERHEART.Sheets.Weapon.Damage.Value"}}</span> <span>{{localize "DAGGERHEART.Sheets.Weapon.Damage.Die"}}</span>
{{formGroup systemFields.damage.fields.value value=source.system.damage.value}} {{formGroup systemFields.damage.fields.dice value=source.system.damage.dice}}
<span>{{localize "DAGGERHEART.Sheets.Weapon.Damage.Bonus"}}</span>
{{formGroup systemFields.damage.fields.bonus value=source.system.damage.bonus}}
<span>{{localize "DAGGERHEART.Sheets.Weapon.Damage.Type"}}</span> <span>{{localize "DAGGERHEART.Sheets.Weapon.Damage.Type"}}</span>
{{formGroup systemFields.damage.fields.type value=source.system.damage.type localize=true}} {{formGroup systemFields.damage.fields.type value=source.system.damage.type localize=true}}
</fieldset> </fieldset>