diff --git a/daggerheart.mjs b/daggerheart.mjs index 94f243b8..4641c34a 100644 --- a/daggerheart.mjs +++ b/daggerheart.mjs @@ -24,7 +24,7 @@ import TokenManager from './module/documents/tokenManager.mjs'; CONFIG.DH = SYSTEM; CONFIG.TextEditor.enrichers.push(...enricherConfig); -CONFIG.Dice.rolls = [BaseRoll, Roll, DHRoll, DualityRoll, D20Roll, DamageRoll, FateRoll]; +CONFIG.Dice.rolls = [Roll = BaseRoll, DHRoll, DualityRoll, D20Roll, DamageRoll, FateRoll]; CONFIG.Dice.daggerheart = { DHRoll: DHRoll, DualityRoll: DualityRoll, diff --git a/module/applications/dialogs/damageDialog.mjs b/module/applications/dialogs/damageDialog.mjs index ce613ade..8b37cf2d 100644 --- a/module/applications/dialogs/damageDialog.mjs +++ b/module/applications/dialogs/damageDialog.mjs @@ -77,10 +77,7 @@ export default class DamageDialog extends HandlebarsApplicationMixin(Application static updateRollConfiguration(_event, _, formData) { const data = foundry.utils.expandObject(formData.object); - - if (this.config.damageFormula) - foundry.utils.mergeObject(this.config.damageFormula, data.damageFormula); - + foundry.utils.mergeObject(this.config.damageFormula, data.damageFormula); foundry.utils.mergeObject(this.config.resourceFormulas, data.resourceFormulas); foundry.utils.mergeObject(this.config.modifiers, data.modifiers); this.config.selectedMessageMode = data.selectedMessageMode; diff --git a/module/applications/dialogs/tagTeamDialog.mjs b/module/applications/dialogs/tagTeamDialog.mjs index 594b136f..c54720f4 100644 --- a/module/applications/dialogs/tagTeamDialog.mjs +++ b/module/applications/dialogs/tagTeamDialog.mjs @@ -553,10 +553,8 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio const { memberKey } = button.dataset; this.updatePartyData( { - [`system.tagTeam.members.${memberKey}.damageRollData`]: { - main: null, - resources: _replace({}) - } + [`system.tagTeam.members.${memberKey}.damageRollData.types`]: + _replace({}) }, this.getUpdatingParts(button) ); @@ -579,19 +577,19 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio async getCriticalDamage(origDamage) { const newDamage = origDamage ? ChatDamageData.fromJSON(JSON.stringify(origDamage)) : null; - if (newDamage?.main) { - const criticalDamage = await getCritDamageBonus(newDamage.main.formula); - if (criticalDamage) { - const criticalTerm = new foundry.dice.terms.NumericTerm({ number: criticalDamage, evaluated: true }); - criticalTerm.evaluate(); - newDamage.main = await Roll.fromTerms([ - ...origDamage.main.terms, - new foundry.dice.terms.OperatorTerm({ operator: '+' }), - criticalTerm - ]); - newDamage.main.options = foundry.utils.deepClone(origDamage.main.options); - } - } + for (let key in newDamage?.types ?? {}) { + const criticalDamage = await getCritDamageBonus(newDamage.types[key].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, + new foundry.dice.terms.OperatorTerm({ operator: '+' }), + criticalTerm + ]); + newDamage.types[key].options = foundry.utils.deepClone(origDamage.types[key].options); + } return newDamage; } @@ -646,47 +644,25 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio ? await this.getCriticalDamage(secondaryRoll.damageRollData) : secondaryRoll.damageRollData; if (mainRoll.damageRollData) { - if (secondaryDamage.main) { - if (mainRoll.damageRollData.main) { - mainRoll.damageRollData.main = Roll.fromTerms([ - ...baseMainRoll.damageRollData.main.terms, + 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, new foundry.dice.terms.OperatorTerm({ operator: '+' }), - ...baseSecondaryRoll.damageRollData.main.terms + ...baseSecondaryRoll.damageRollData.types[key].terms ]); /* Joining the roll.options of both rolls */ const joinedDamageTypes = new Set([ - ...baseMainRoll.damageRollData.main.options.damageTypes, - ...baseSecondaryRoll.damageRollData.main.options.damageTypes + ...baseMainRoll.damageRollData.types[key].options.damageTypes, + ...baseSecondaryRoll.damageRollData.types[key].options.damageTypes ]); - mainRoll.damageRollData.main.options = { - ...baseMainRoll.damageRollData.main.options, + mainRoll.damageRollData.types[key].options = { + ...baseMainRoll.damageRollData.types[key].options, damageTypes: [...joinedDamageTypes] }; } else { - mainRoll.damageRollData.main = secondaryDamage.main; - } - } - - for (const [key, damage] of Object.entries(secondaryDamage.resources ?? {})) { - if (key in mainRoll.damageRollData.resources) { - mainRoll.damageRollData.resources[key] = Roll.fromTerms([ - ...baseMainRoll.damageRollData.resources[key].terms, - new foundry.dice.terms.OperatorTerm({ operator: '+' }), - ...baseSecondaryRoll.damageRollData.resources[key].terms - ]); - - /* Joining the roll.options of both rolls */ - const joinedDamageTypes = new Set([ - ...baseMainRoll.damageRollData.resources[key].options.damageTypes, - ...baseSecondaryRoll.damageRollData.resources[key].options.damageTypes - ]); - mainRoll.damageRollData.resources[key].options = { - ...baseMainRoll.damageRollData.resources[key].options, - damageTypes: [...joinedDamageTypes] - }; - } else { - mainRoll.damageRollData.resources[key] = damage; + mainRoll.damageRollData.types[key] = damage; } } } else { @@ -751,12 +727,8 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio ...mainRoll.options, damage: joinedRoll.damageRollData?.toJSON() }; - - if (joinedRoll.damageRollData.main) { - systemData.damage.main = joinedRoll.damageRollData.toJSON(); - } - for (const type of Object.keys(joinedRoll.damageRollData?.resources ?? {})) { - systemData.damage.resources[type] = joinedRoll.damageRollData.resources[type].toJSON(); + for (const type of Object.keys(joinedRoll.damageRollData?.types ?? {})) { + systemData.damage.types[type] = joinedRoll.damageRollData.types[type].toJSON(); } const cls = getDocumentClass('ChatMessage'), diff --git a/module/applications/sheets-configs/adversary-settings.mjs b/module/applications/sheets-configs/adversary-settings.mjs index 0bf18ee6..c5f036ed 100644 --- a/module/applications/sheets-configs/adversary-settings.mjs +++ b/module/applications/sheets-configs/adversary-settings.mjs @@ -9,8 +9,8 @@ export default class DHAdversarySettings extends DHBaseActorSettings { classes: ['adversary-settings'], position: { width: 455, height: 'auto' }, actions: { - addExperience: this.#onAddExperience, - removeExperience: this.#onRemoveExperience, + addExperience: DHAdversarySettings.#onAddExperience, + removeExperience: DHAdversarySettings.#onRemoveExperience, addDamage: this.#onAddDamage, removeDamage: this.#onRemoveDamage } diff --git a/module/data/action/attackAction.mjs b/module/data/action/attackAction.mjs index dadc85f0..6c205de6 100644 --- a/module/data/action/attackAction.mjs +++ b/module/data/action/attackAction.mjs @@ -13,19 +13,18 @@ export default class DHAttackAction extends DHDamageAction { if (this.damage.includeBase) { const baseDamage = this.getParentHitPointDamage(); if (baseDamage) { - if (!this.damage.main) { - this.damage.main = baseDamage; + if (!this.damage.parts.hitPoints) { + this.damage.parts.hitPoints = baseDamage; } else { - for (const type of baseDamage.type) this.damage.main.type.add(type); + for (const type of baseDamage.type) this.damage.parts.hitPoints.type.add(type); - this.damage.main.value.custom = { + this.damage.parts.hitPoints.value.custom = { enabled: true, - formula: `${baseDamage.value.getFormula()} + ${this.damage.main.value.getFormula()}` + formula: `${baseDamage.value.getFormula()} + ${this.damage.parts.hitPoints.value.getFormula()}` }; } } } - if (this.roll.useDefault) { this.roll.trait = this.item.system.attack.roll.trait; this.roll.type = 'attack'; @@ -34,18 +33,18 @@ export default class DHAttackAction extends DHDamageAction { } getParentHitPointDamage() { - return this.item?.system?.attack.damage.main; + return this.item?.system?.attack.damage.parts.hitPoints; } get damageFormula() { - const hitPointsPart = this.damage.main; + const hitPointsPart = this.damage.parts.hitPoints; if (!hitPointsPart) return '0'; return hitPointsPart.value.getFormula(); } get altDamageFormula() { - const hitPointsPart = this.damage.main; + const hitPointsPart = this.damage.parts.hitPoints; if (!hitPointsPart) return '0'; return hitPointsPart.valueAlt.getFormula(); diff --git a/module/data/action/baseAction.mjs b/module/data/action/baseAction.mjs index a94d7d61..f773ae32 100644 --- a/module/data/action/baseAction.mjs +++ b/module/data/action/baseAction.mjs @@ -288,6 +288,7 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel hasEffect: this.hasEffect, hasSave: this.hasSave, onSave: this.save?.damageMod, + isDirect: !!this.damage?.direct, selectedMessageMode: game.settings.get('core', 'messageMode'), data: this.getRollData(), evaluate: this.hasRoll, @@ -305,20 +306,20 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel }; if (this.damage) { - config.isDirect = !!this.damage.main?.direct; + config.isDirect = this.damage.direct; - const groupAttackTokens = this.damage.main?.groupAttack + const groupAttackTokens = this.damage.groupAttack ? game.system.api.fields.ActionFields.DamageField.getGroupAttackTokens( this.actor.id, - this.damage.main.groupAttack + this.damage.groupAttack ) : null; config.damageOptions = { - groupAttack: this.damage.main?.groupAttack + groupAttack: this.damage.groupAttack ? { numAttackers: Math.max(groupAttackTokens.length, 1), - range: this.damage.main.groupAttack + range: this.damage.groupAttack } : null }; @@ -428,11 +429,11 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel } get hasDamage() { - return this.type !== 'healing' && (Boolean(this.damage.main) || !foundry.utils.isEmpty(this.damage.resources)); + return this.type !== 'healing' && Boolean(this.damage.main) || Boolean(this.damage.resources.length); } get hasHealing() { - return this.type === 'healing' && !foundry.utils.isEmpty(this.damage.resources); + return this.type === 'healing' && Boolean(this.damage.main) || Boolean(this.damage.resources.length); } get hasSave() { diff --git a/module/data/actor/tierAdjustment.mjs b/module/data/actor/tierAdjustment.mjs index 4bf74a45..8b9e5bdc 100644 --- a/module/data/actor/tierAdjustment.mjs +++ b/module/data/actor/tierAdjustment.mjs @@ -40,17 +40,17 @@ export function getTierAdjustedAdversary(source, tier) { // Store initial attack damage for abilities that have you deal a "standard attack" const initialAttack = { - type: source.system.attack.damage?.main?.type?.toSorted(), - value: getFormula(source.system.attack.damage?.main?.value) + type: source.system.attack.damage?.parts.hitPoints?.type?.toSorted(), + value: getFormula(source.system.attack.damage?.parts.hitPoints?.value) }; // Update damage of base attack. try { const damage = source.system.attack.damage; - if (!damage?.main) throw new Error('Unexpected missing damage in adversary'); + if (!damage?.parts.hitPoints) throw new Error('Unexpected missing attack in adversary'); for (const property of ['value', 'valueAlt']) { - const data = damage.main[property]; + const data = damage.parts.hitPoints[property]; const previousFormula = getFormula(data); const value = calculateAdjustedDamage(previousFormula, 'attack', damageMeta); applyAdjustedDamage(data, value); @@ -82,12 +82,12 @@ export function getTierAdjustedAdversary(source, tier) { // Update damage in item actions and convert all formula matches in the descriptions to the new damage for (const action of Object.values(item.system.actions)) { - if (!action.damage?.main) continue; + if (!action.damage?.parts.hitPoints) continue; try { // Apply conversions and save a record. If it matches attack damage *and* Its not in the description, use attack conversion instead const result = []; for (const property of ['value', 'valueAlt']) { - const { [property]: data, type: damageType } = action.damage.main; + const { [property]: data, type: damageType } = action.damage.parts.hitPoints; const previousFormula = getFormula(data); const isActuallyAttack = previousFormula === initialAttack.value && @@ -199,7 +199,7 @@ function calculateAdjustedDamage(formula, type, { currentDamageRange, newDamageR } /** - * Get formula from either damage data *or* a simple formula object. + * Get formula from either damage parts *or* a simple formula object. * @returns {string} the new formula data */ function getFormula(data) { diff --git a/module/data/chat-message/actorRoll.mjs b/module/data/chat-message/actorRoll.mjs index 376e7e3a..2d578a0f 100644 --- a/module/data/chat-message/actorRoll.mjs +++ b/module/data/chat-message/actorRoll.mjs @@ -188,36 +188,31 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel { } static migrateData(source) { - const { main, resources, ...flatDamageKeys } = source.damage; - if (!main && !resources) { - source.damage.main = null; - source.damage.resources = {}; - + if (source.hasDamage && !source.damage.resources === undefined) { const getRoll = key => { const damageData = source.damage[key]; const oldRoll = damageData.parts[0]?.roll; - return oldRoll ? JSON.stringify({ + return oldRoll ? { ...oldRoll, - class: 'BaseRoll', options: { ...oldRoll.options, damageTypes: damageData.parts[0].damageTypes ?? [] } - }) : null; + } : null; }; - for (const key of Object.keys(flatDamageKeys)) { - if (key === 'hitPoints' && source.hasDamage && !source.hasHealing) { - source.damage.main = getRoll('hitPoints'); - } - else { - source.damage.resources[key] = getRoll(key); - } - } - } + source.damage = { + main: source.damage.hitPoints ? getRoll('hitPoints') : null, + resources: Object.keys(source.damage).reduce((acc, key) => { + if (key === 'hitPoints') return acc; - for (const key of Object.keys(flatDamageKeys)) { - delete source.damage[key]; + const roll = getRoll(key); + if (!roll) return acc; + + acc[key] = roll; + return acc; + }, {}) + }; } return source; diff --git a/module/data/chat-message/chatDamageData.mjs b/module/data/chat-message/chatDamageData.mjs index b7679ee1..c612729e 100644 --- a/module/data/chat-message/chatDamageData.mjs +++ b/module/data/chat-message/chatDamageData.mjs @@ -28,7 +28,10 @@ export class ChatDamageData extends foundry.abstract.DataModel { } _prepareRolls() { - this.main &&= Roll.fromData(this.main); + if (this.main) { + this.main = Roll.fromData(this.main); + } + for (const key of Object.keys(this.resources)) { this.resources[key] = Roll.fromData(this.resources[key]); } diff --git a/module/data/fields/action/damageField.mjs b/module/data/fields/action/damageField.mjs index c2db4b51..9f382b59 100644 --- a/module/data/fields/action/damageField.mjs +++ b/module/data/fields/action/damageField.mjs @@ -99,7 +99,7 @@ export default class DamageField extends fields.SchemaField { : actor.prototypeToken; if (config.hasHealing) damagePromises.push( - actor.takeHealing(config.damage).then(updates => targetDamage.push({ token, updates })) + actor.takeHealing(config.damage.types).then(updates => targetDamage.push({ token, updates })) ); else { const configDamage = config.damage.clone(); @@ -177,12 +177,12 @@ export default class DamageField extends fields.SchemaField { static formatFormulas(damageData, data) { const formulas = damageData.map(x => ({ formula: DamageField.getFormulaValue.call(this, x, data).getFormula(this.actor), - damageTypes: x.type ?? new Set(), + damageTypes: x.applyTo === 'hitPoints' && !x.type.size ? new Set(['physical']) : x.type, applyTo: x.applyTo })); const formattedFormulas = []; - for (const formula of formulas) { + formulas.forEach(formula => { if (isNaN(formula.formula)) formula.formula = Roll.replaceFormulaData(formula.formula, this.getRollData(data)); const same = formattedFormulas.find( @@ -190,7 +190,7 @@ export default class DamageField extends fields.SchemaField { ); if (same) same.formula += ` + ${formula.formula}`; else formattedFormulas.push(formula); - } + }); return formattedFormulas; } diff --git a/module/dice/damageRoll.mjs b/module/dice/damageRoll.mjs index c78a42e9..64077e1f 100644 --- a/module/dice/damageRoll.mjs +++ b/module/dice/damageRoll.mjs @@ -27,14 +27,10 @@ export default class DamageRoll extends DHRoll { return roll.roll; } - if (!config.damage) config.damage = { main: null, resources: {} }; - - if (config.damageFormula) { - config.damage.main = await evaluateRoll(config.damageFormula); - config.damage.main.options = { damageTypes: - config.damageFormula.damageTypes ? [...config.damageFormula.damageTypes] : [] - }; - } + config.damage.main = await evaluateRoll(config.damageFormula); + config.damage.main.options = { damageTypes: + config.damageFormula.damageTypes ? [...config.damageFormula.damageTypes] : [] + }; for (const roll of config.resourceFormulas) { config.damage.resources[roll.applyTo] = await evaluateRoll(roll); @@ -120,10 +116,12 @@ export default class DamageRoll extends DHRoll { const type = this.options.messageType ?? (this.options.hasHealing ? 'healing' : 'damage'); const changeKeys = []; - for (const damageType of this.options.damageFormula?.damageTypes?.values?.() ?? []) { - changeKeys.push(`system.bonuses.${type}.${damageType}`); + for (const roll of this.options.roll) { + for (const damageType of roll.damageTypes?.values?.() ?? []) { + changeKeys.push(`system.bonuses.${type}.${damageType}`); + } } - + const item = this.data.parent?.items?.get(this.options.source.item); if (item) { switch (item.type) { @@ -147,7 +145,6 @@ export default class DamageRoll extends DHRoll { } constructFormula(formulaData, config, isDamage) { - if (!formulaData) return null; this.options.isCritical = config.isCritical; const isHitpointPart = formulaData.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id; diff --git a/module/documents/actor.mjs b/module/documents/actor.mjs index de55b4b7..5048abef 100644 --- a/module/documents/actor.mjs +++ b/module/documents/actor.mjs @@ -662,57 +662,60 @@ export default class DhpActor extends Actor { if (Hooks.call(`${CONFIG.DH.id}.postCalculateDamage`, this, damages) === false) return null; - // Convert deducted resources to a record of updates. Return if nothing to do. - const updates = Object.entries(damages.resources).map(([key, damage]) => ({ key, value: damage.total })); - if (!updates.some(u => u.value) && !damages.main) return; - + // Convert deducted resources and damage to a record of updates, merging damage to hp with hp marked + const updates = []; + for (const [key, damage] of Object.entries(damages.resources)) { + updates.push({ key, value: damage.total }); + } if (damages.main) { - const hpDamage = { - value: this.convertDamageToThreshold(damages.main.total), - damageTypes: new Set(damages.main.options.damageTypes), - key: CONFIG.DH.GENERAL.healingTypes.hitPoints.id - }; - if (this.type === 'character' && !isDirect && this.#canReduceDamage(hpDamage.total, hpDamage.damageTypes)) { - const armorSlotResult = await this.owner.query( - 'armorSlot', - { - actorId: this.uuid, - damage: hpDamage.value, - type: [...hpDamage.damageTypes] - }, - { - timeout: 30000 - } - ); - if (armorSlotResult) { - const { modifiedDamage, armorChanges, stressSpent } = armorSlotResult; - hpDamage.value = modifiedDamage; - for (const armorChange of armorChanges) { - updates.push({ value: armorChange.amount, key: 'armor', uuid: armorChange.uuid }); - } - if (stressSpent) { - const stressUpdate = updates.find(u => u.key === 'stress'); - if (stressUpdate) stressUpdate.value += stressSpent; - else updates.push({ value: stressSpent, key: 'stress' }); - } + const existing = updates.find(u => u.key === CONFIG.DH.GENERAL.healingTypes.hitPoints.id); + const value = this.convertDamageToThreshold(damages.main.total) + (existing?.value ?? 0); + const damageTypes = new Set(damages.main.options.damageTypes); + if (existing) { + existing.value = value; + existing.damageTypes = damageTypes; + } else { + updates.push({ value, damageTypes, key: CONFIG.DH.GENERAL.healingTypes.hitPoints.id }); + } + } + if (!updates.some(u => u.value !== 0)) return; // early return if nothing to do + + const hpDamage = updates.find(u => u.key === CONFIG.DH.GENERAL.healingTypes.hitPoints.id); + if (hpDamage && this.type === 'character' && !isDirect && this.#canReduceDamage(hpDamage.total, hpDamage.damageTypes)) { + const armorSlotResult = await this.owner.query( + 'armorSlot', + { + actorId: this.uuid, + damage: hpDamage.value, + type: [...hpDamage.damageTypes] + }, + { + timeout: 30000 } - } else if (this.type === 'adversary') { - const reducedSeverity = hpDamage.damageTypes.reduce((value, curr) => { - return Math.max(this.system.rules.damageReduction.reduceSeverity[curr], value); - }, 0); - hpDamage.value = Math.max(hpDamage.value - reducedSeverity, 0); - if (this.system.rules.damageReduction.thresholdImmunities[getDamageKey(hpDamage.value)]) { - hpDamage.value = Math.max(0, hpDamage.value - 1); + ); + if (armorSlotResult) { + const { modifiedDamage, armorChanges, stressSpent } = armorSlotResult; + hpDamage.value = modifiedDamage; + for (const armorChange of armorChanges) { + updates.push({ value: armorChange.amount, key: 'armor', uuid: armorChange.uuid }); + } + if (stressSpent) { + const stressUpdate = updates.find(u => u.key === 'stress'); + if (stressUpdate) stressUpdate.value += stressSpent; + else updates.push({ value: stressSpent, key: 'stress' }); } } + } else if (hpDamage && this.type === 'adversary') { + const reducedSeverity = hpDamage.damageTypes.reduce((value, curr) => { + return Math.max(this.system.rules.damageReduction.reduceSeverity[curr], value); + }, 0); + hpDamage.value = Math.max(hpDamage.value - reducedSeverity, 0); - // Merge existing hitPoint deduction with finalised damage deduction - const existing = updates.find(u => u.key === CONFIG.DH.GENERAL.healingTypes.hitPoints.id); - if (existing) { - existing.value += hpDamage.value; - existing.damageTypes = hpDamage.damageTypes; - } else { - updates.push(hpDamage); + if ( + hpDamage.value && + this.system.rules.damageReduction.thresholdImmunities[getDamageKey(hpDamage.value)] + ) { + hpDamage.value -= 1; } } @@ -728,36 +731,16 @@ export default class DhpActor extends Actor { for (var result of results) resourceMap.addResources(result.updates); resourceMap.updateResources(); } - - for (const u of updates) { - u.value = u.key === 'fear' || this.system?.resources?.[u.key]?.isReversed === false ? u.value * -1 : u.value; - } - - await this.modifyResource(updates); - - if (Hooks.call(`${CONFIG.DH.id}.postTakeDamage`, this, updates) === false) return null; - - return updates; - } - - async takeHealing(healings) { - if (Hooks.call(`${CONFIG.DH.id}.preTakeHealing`, this, healings) === false) return null; - - const updates = Object.entries(healings.resources).map(([key, damage]) => ({ - key, - value: damage.total - })); updates.forEach( u => - (u.value = !(u.key === 'fear' || this.system?.resources?.[u.key]?.isReversed === false) - ? u.value * -1 - : u.value) + (u.value = + u.key === 'fear' || this.system?.resources?.[u.key]?.isReversed === false ? u.value * -1 : u.value) ); await this.modifyResource(updates); - if (Hooks.call(`${CONFIG.DH.id}.postTakeHealing`, this, updates) === false) return null; + if (Hooks.call(`${CONFIG.DH.id}.postTakeDamage`, this, updates) === false) return null; return updates; } @@ -786,6 +769,30 @@ export default class DhpActor extends Actor { return reduction === Infinity ? 0 : reduction; } + async takeHealing(healings) { + if (Hooks.call(`${CONFIG.DH.id}.preTakeHealing`, this, healings) === false) return null; + + const updates = []; + Object.entries(healings).forEach(([key, healing]) => { + const update = updates.find(u => u.key === key); + if (update) update.value += healing.roll.total; + else updates.push({ value: healing.roll.total, key }); + }); + + updates.forEach( + u => + (u.value = !(u.key === 'fear' || this.system?.resources?.[u.key]?.isReversed === false) + ? u.value * -1 + : u.value) + ); + + await this.modifyResource(updates); + + if (Hooks.call(`${CONFIG.DH.id}.postTakeHealing`, this, updates) === false) return null; + + return updates; + } + /** * Resources are modified asynchronously, so be careful not to update the same resource in * quick succession. diff --git a/styles/less/dialog/damage-selection/sheet.less b/styles/less/dialog/damage-selection/sheet.less index cb2c14e5..9f8cfc8a 100644 --- a/styles/less/dialog/damage-selection/sheet.less +++ b/styles/less/dialog/damage-selection/sheet.less @@ -17,12 +17,6 @@ } } - .section-header { - font-size: var(--font-size-20); - color: light-dark(@dark, @beige); - text-align: center; - } - .bonuses { gap: 4px; .critical-chip { diff --git a/templates/dialogs/dice-roll/damageSelection.hbs b/templates/dialogs/dice-roll/damageSelection.hbs index 117df634..cc12e26f 100644 --- a/templates/dialogs/dice-roll/damageSelection.hbs +++ b/templates/dialogs/dice-roll/damageSelection.hbs @@ -15,53 +15,12 @@ {{/each}} {{/if}} - - {{#if @root.damageFormula}} - {{#with @root.damageFormula}} -