diff --git a/module/applications/dialogs/tagTeamDialog.mjs b/module/applications/dialogs/tagTeamDialog.mjs index 2b865304..e6492c50 100644 --- a/module/applications/dialogs/tagTeamDialog.mjs +++ b/module/applications/dialogs/tagTeamDialog.mjs @@ -612,13 +612,14 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio async getCriticalDamage(origDamage) { const newDamage = origDamage ? ChatDamageData.fromJSON(JSON.stringify(origDamage)) : null; for (let key in newDamage?.types ?? {}) { - const criticalDamage = await getCritDamageBonus(newDamage.types[key].formula); + const damage = newDamage.types[key]; + const criticalDamage = await getCritDamageBonus(damage.roll.formula); if (!criticalDamage) continue; const criticalTerm = new foundry.dice.terms.NumericTerm({ number: criticalDamage, evaluated: true }); criticalTerm.evaluate(); - newDamage.types[key] = await Roll.fromTerms([ - ...origDamage.types[key].terms, + damage.roll = await Roll.fromTerms([ + ...origDamage.types[key].roll.terms, new foundry.dice.terms.OperatorTerm({ operator: '+' }), criticalTerm ]); @@ -674,10 +675,10 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio if (mainRoll.damageRollData) { for (const [key, damage] of Object.entries(secondaryDamage.types ?? {})) { if (key in mainRoll.damageRollData.types) { - mainRoll.damageRollData.types[key] = Roll.fromTerms([ - ...baseMainRoll.damageRollData.types[key].terms, + mainRoll.damageRollData.types[key].roll = Roll.fromTerms([ + ...baseMainRoll.damageRollData.types[key].roll.terms, new foundry.dice.terms.OperatorTerm({ operator: '+' }), - ...baseSecondaryRoll.damageRollData.types[key].terms + ...baseSecondaryRoll.damageRollData.types[key].roll.terms ]); } else { mainRoll.damageRollData.types[key] = damage; @@ -743,10 +744,10 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio /* This could assumably be done better. For some reason rolls don't get correctly done through rollData.toJSON */ const systemData = { ...mainRoll.options, - damage: joinedRoll.damageRollData?.toJSON() + damage: joinedRoll.damageRollData.toJSON() }; - for (const type of Object.keys(joinedRoll.damageRollData?.types ?? {})) { - systemData.damage.types[type] = joinedRoll.damageRollData.types[type].toJSON(); + for (const type of Object.keys(joinedRoll.damageRollData.types)) { + systemData.damage.types[type].roll = joinedRoll.damageRollData.types[type].roll.toJSON(); } const cls = getDocumentClass('ChatMessage'), diff --git a/module/applications/ui/chatLog.mjs b/module/applications/ui/chatLog.mjs index 1c462930..60b6cceb 100644 --- a/module/applications/ui/chatLog.mjs +++ b/module/applications/ui/chatLog.mjs @@ -258,7 +258,9 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo await message.system.damage.rerollDamageDie(damageType, dice, result); await message.update({ 'system.damage.types': { - [damageType]: message.system.damage.types[damageType].toJSON() + [damageType]: { + roll: message.system.damage.types[damageType].roll.toJSON() + } } }); } else { diff --git a/module/data/chat-message/actorRoll.mjs b/module/data/chat-message/actorRoll.mjs index 0b5d2678..c2655610 100644 --- a/module/data/chat-message/actorRoll.mjs +++ b/module/data/chat-message/actorRoll.mjs @@ -140,9 +140,9 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel { const update = { system: { damage: { types: {} } } }; for (const key of Object.keys(this.damage.types)) { const type = this.damage.types[key]; - const reroll = await type.reroll(); + const reroll = await type.roll.reroll(); rerolls.push(reroll); - update.system.damage.types[key] = reroll.toJSON(); + update.system.damage.types[key] = { roll: reroll.toJSON() }; } await triggerChatRollFx(rerolls); @@ -192,15 +192,10 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel { source.damage = { types: Object.keys(source.damage).reduce((acc, key) => { const damageData = source.damage[key]; - const oldRoll = damageData.parts[0]?.roll; - acc[key] = oldRoll ? { - ...oldRoll, - options: { - ...oldRoll.options, - damageTypes: damageData.parts[0].damageTypes ?? [] - } - } : null; - + acc[key] = { + roll: damageData.parts[0]?.roll ?? null, + damageTypes: damageData.parts[0]?.damageTypes ?? [] + }; return acc; }, {}) }; diff --git a/module/data/chat-message/chatDamageData.mjs b/module/data/chat-message/chatDamageData.mjs index b866ddaf..c233781c 100644 --- a/module/data/chat-message/chatDamageData.mjs +++ b/module/data/chat-message/chatDamageData.mjs @@ -11,7 +11,10 @@ export class ChatDamageData extends foundry.abstract.DataModel { const fields = foundry.data.fields; return { - types: new fields.TypedObjectField(new fields.JSONField({validate: ChatDamageData.#validateRoll})) + types: new fields.TypedObjectField(new fields.SchemaField({ + roll: new fields.JSONField({validate: ChatDamageData.#validateRoll}), + damageTypes: new fields.ArrayField(new fields.StringField({ choices: CONFIG.DH.GENERAL.damageTypes })) + })) }; } @@ -28,14 +31,14 @@ export class ChatDamageData extends foundry.abstract.DataModel { for (const key of Object.keys(this.types)) { const type = this.types[key]; try { - this.types[key] = Roll.fromData(type); - this.types[key].options.modifierTotal = CONFIG.Dice.daggerheart.DHRoll.calculateTotalModifiers(type); + type.roll = Roll.fromData(type.roll); + type.roll.modifierTotal = CONFIG.Dice.daggerheart.DHRoll.calculateTotalModifiers(type.roll); } catch {} } } async rerollDamageDie(damageType, dice, resultIndex) { - const reroll = this.types[damageType]; + const reroll = this.types[damageType].roll; const rerollDice = reroll.dice[dice]; await rerollDice.rerollResult(resultIndex); await reroll._evaluate(); diff --git a/module/dice/damageRoll.mjs b/module/dice/damageRoll.mjs index 56712337..14b88c15 100644 --- a/module/dice/damageRoll.mjs +++ b/module/dice/damageRoll.mjs @@ -19,10 +19,12 @@ export default class DamageRoll extends DHRoll { for (const roll of config.roll) { await roll.roll.evaluate(); - roll.roll.options = { damageTypes: roll.damageTypes ?? [] }; - + if (!config.damage?.types) config.damage = { types: {} }; - config.damage.types[roll.applyTo] = roll.roll; + config.damage.types[roll.applyTo] = { + roll: roll.roll, + damageTypes: roll.damageTypes ?? [] + }; } roll._evaluated = true; diff --git a/templates/dialogs/tagTeamDialog/parts/tagTeamDamageParts.hbs b/templates/dialogs/tagTeamDialog/parts/tagTeamDamageParts.hbs index 5f37c6d1..90f720cf 100644 --- a/templates/dialogs/tagTeamDialog/parts/tagTeamDamageParts.hbs +++ b/templates/dialogs/tagTeamDialog/parts/tagTeamDamageParts.hbs @@ -1,24 +1,25 @@ -{{#each damage.types as |roll key|}} +{{#each damage.types as |damage key|}}