diff --git a/README.md b/README.md index 760194f4..a5c7fe48 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ - [Overview](#overview) - [User Install Guide](#user-install) -- [Developer Setup](#developer-setup) +- [Developer Setup](#development-setup) - [Contribution Info](#contributing) ## Overview diff --git a/lang/en.json b/lang/en.json index e0ef27cb..9a32afaa 100755 --- a/lang/en.json +++ b/lang/en.json @@ -38,6 +38,9 @@ "Settings": { "resultBased": { "label": "Formula based on Hope/Fear result." + }, + "applyTo": { + "label": "Targeted Resource" } }, "TYPES": { @@ -678,6 +681,10 @@ "armorStack": { "name": "Armor Stack", "abbreviation": "AS" + }, + "fear": { + "name": "Fear", + "abbreviation": "FR" } }, "ItemResourceType": { @@ -1275,6 +1282,7 @@ }, "fear": "Fear", "features": "Features", + "healing": "Healing", "hitPoints": { "single": "Hit Point", "plural": "Hit Points", diff --git a/module/applications/dialogs/damageDialog.mjs b/module/applications/dialogs/damageDialog.mjs index 70dcace8..78452054 100644 --- a/module/applications/dialogs/damageDialog.mjs +++ b/module/applications/dialogs/damageDialog.mjs @@ -43,10 +43,11 @@ export default class DamageDialog extends HandlebarsApplicationMixin(Application async _prepareContext(_options) { const context = await super._prepareContext(_options); + context.config = CONFIG.DH; context.title = this.config.title ? this.config.title : game.i18n.localize('DAGGERHEART.EFFECTS.ApplyLocations.damageRoll.name'); - context.extraFormula = this.config.extraFormula; + // context.extraFormula = this.config.extraFormula; context.formula = this.roll.constructFormula(this.config); context.directDamage = this.config.directDamage; context.selectedRollMode = this.config.selectedRollMode; @@ -55,13 +56,12 @@ export default class DamageDialog extends HandlebarsApplicationMixin(Application label, icon })); - return context; } static updateRollConfiguration(_event, _, formData) { const { ...rest } = foundry.utils.expandObject(formData.object); - this.config.extraFormula = rest.extraFormula; + foundry.utils.mergeObject(this.config.roll, rest.roll); this.config.selectedRollMode = rest.selectedRollMode; this.render(); diff --git a/module/applications/dialogs/damageReductionDialog.mjs b/module/applications/dialogs/damageReductionDialog.mjs index 984106d7..3e3bde44 100644 --- a/module/applications/dialogs/damageReductionDialog.mjs +++ b/module/applications/dialogs/damageReductionDialog.mjs @@ -15,7 +15,7 @@ export default class DamageReductionDialog extends HandlebarsApplicationMixin(Ap const maxArmorMarks = canApplyArmor ? Math.min( actor.system.armorScore - actor.system.armor.system.marks.value, - actor.system.rules.damageReduction.maxArmorMarked.total + actor.system.rules.damageReduction.maxArmorMarked.value ) : 0; @@ -100,7 +100,7 @@ export default class DamageReductionDialog extends HandlebarsApplicationMixin(Ap context.armorScore = this.actor.system.armorScore; context.armorMarks = currentMarks; context.basicMarksUsed = - selectedArmorMarks.length === this.actor.system.rules.damageReduction.maxArmorMarked.total; + selectedArmorMarks.length === this.actor.system.rules.damageReduction.maxArmorMarked.value; const stressReductionStress = this.availableStressReductions ? stressReductions.reduce((acc, red) => acc + red.cost, 0) diff --git a/module/applications/ui/chatLog.mjs b/module/applications/ui/chatLog.mjs index 4570b076..ee4e5bb2 100644 --- a/module/applications/ui/chatLog.mjs +++ b/module/applications/ui/chatLog.mjs @@ -187,7 +187,6 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo ui.notifications.info(game.i18n.localize('DAGGERHEART.UI.Notifications.attackTargetDoesNotExist')); return; } - game.canvas.pan(token); }; @@ -209,13 +208,25 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo } if (targets.length === 0) - ui.notifications.info(game.i18n.localize('DAGGERHEART.UI.Notifications.noTargetsSelected')); - for (let target of targets) { - let damage = message.system.roll.total; - if (message.system.onSave && message.system.targets.find(t => t.id === target.id)?.saved?.success === true) - damage = Math.ceil(damage * (CONFIG.DH.ACTIONS.damageOnSave[message.system.onSave]?.mod ?? 1)); + return ui.notifications.info(game.i18n.localize('DAGGERHEART.UI.Notifications.noTargetsSelected')); - target.actor.takeDamage(damage, message.system.damage.damageType); + for (let target of targets) { + let damages = message.system.damage; + if ( + message.system.onSave && + message.system.targets.find(t => t.id === target.id)?.saved?.success === true + ) { + const mod = CONFIG.DH.ACTIONS.damageOnSave[message.system.onSave]?.mod ?? 1; + Object.entries(damages).forEach((k, v) => { + let newTotal = 0; + v.forEach(part => { + v.total = Math.ceil(v.total * mod); + newTotal += v.total; + }); + }); + } + + target.actor.takeDamage(damages.roll); } }; @@ -224,10 +235,10 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo const targets = Array.from(game.user.targets); if (targets.length === 0) - ui.notifications.info(game.i18n.localize('DAGGERHEART.UI.Notifications.noTargetsSelected')); + return ui.notifications.info(game.i18n.localize('DAGGERHEART.UI.Notifications.noTargetsSelected')); for (var target of targets) { - target.actor.takeHealing([{ value: message.system.roll.total, type: message.system.roll.type }]); + target.actor.takeHealing(message.system.roll); } }; diff --git a/module/config/generalConfig.mjs b/module/config/generalConfig.mjs index 51e39b85..dd2fa3af 100644 --- a/module/config/generalConfig.mjs +++ b/module/config/generalConfig.mjs @@ -89,6 +89,11 @@ export const healingTypes = { id: 'armorStack', label: 'DAGGERHEART.CONFIG.HealingType.armorStack.name', abbreviation: 'DAGGERHEART.CONFIG.HealingType.armorStack.abbreviation' + }, + fear: { + id: 'fear', + label: 'DAGGERHEART.CONFIG.HealingType.fear.name', + abbreviation: 'DAGGERHEART.CONFIG.HealingType.fear.abbreviation' } }; diff --git a/module/data/action/actionDice.mjs b/module/data/action/actionDice.mjs index d71b390a..0361fbdd 100644 --- a/module/data/action/actionDice.mjs +++ b/module/data/action/actionDice.mjs @@ -93,23 +93,17 @@ export class DHDamageField extends fields.SchemaField { } } -export class DHDamageData extends foundry.abstract.DataModel { +export class DHResourceData extends foundry.abstract.DataModel { /** @override */ static defineSchema() { return { - base: new fields.BooleanField({ initial: false, readonly: true, label: 'Base' }), - type: new fields.SetField( - new fields.StringField({ - choices: CONFIG.DH.GENERAL.damageTypes, - initial: 'physical', - nullable: false, - required: true - }), - { - label: 'Type', - initial: 'physical' - } - ), + applyTo: new fields.StringField({ + choices: CONFIG.DH.GENERAL.healingTypes, + required: true, + blank: false, + initial: CONFIG.DH.GENERAL.healingTypes.hitPoints.id, + label: 'DAGGERHEART.ACTIONS.Settings.applyTo.label' + }), resultBased: new fields.BooleanField({ initial: false, label: 'DAGGERHEART.ACTIONS.Settings.resultBased.label' @@ -119,3 +113,24 @@ export class DHDamageData extends foundry.abstract.DataModel { }; } } + +export class DHDamageData extends DHResourceData { + /** @override */ + static defineSchema() { + return { + ...super.defineSchema(), + base: new fields.BooleanField({ initial: false, readonly: true, label: 'Base' }), + type: new fields.SetField( + new fields.StringField({ + choices: CONFIG.DH.GENERAL.damageTypes, + initial: 'physical', + nullable: false, + required: true + }), + { + label: 'Type' + } + ) + }; + } +} diff --git a/module/data/action/baseAction.mjs b/module/data/action/baseAction.mjs index a46b0a85..ad442951 100644 --- a/module/data/action/baseAction.mjs +++ b/module/data/action/baseAction.mjs @@ -1,4 +1,4 @@ -import { DHActionDiceData, DHActionRollData, DHDamageField } from './actionDice.mjs'; +import { DHActionDiceData, DHActionRollData, DHDamageData, DHDamageField, DHResourceData } from './actionDice.mjs'; import DhpActor from '../../documents/actor.mjs'; import D20RollDialog from '../../applications/dialogs/d20RollDialog.mjs'; @@ -96,21 +96,7 @@ export default class DHBaseAction extends foundry.abstract.DataModel { onSave: new fields.BooleanField({ initial: false }) }) ), - healing: new fields.SchemaField({ - type: new fields.StringField({ - choices: CONFIG.DH.GENERAL.healingTypes, - required: true, - blank: false, - initial: CONFIG.DH.GENERAL.healingTypes.hitPoints.id, - label: 'Healing' - }), - resultBased: new fields.BooleanField({ - initial: false, - label: 'DAGGERHEART.ACTIONS.Settings.resultBased.label' - }), - value: new fields.EmbeddedDataField(DHActionDiceData), - valueAlt: new fields.EmbeddedDataField(DHActionDiceData) - }), + healing: new fields.EmbeddedDataField(DHResourceData), beastform: new fields.SchemaField({ tierAccess: new fields.SchemaField({ exact: new fields.NumberField({ integer: true, nullable: true, initial: null }) @@ -156,7 +142,7 @@ export default class DHBaseAction extends foundry.abstract.DataModel { static getSourceConfig(parent) { const updateSource = {}; updateSource.img ??= parent?.img ?? parent?.system?.img; - if (parent?.type === 'weapon') { + if (parent?.type === 'weapon' && this === game.system.api.models.actions.actionsTypes.attack) { updateSource['damage'] = { includeBase: true }; updateSource['range'] = parent?.system?.attack?.range; updateSource['roll'] = { @@ -177,6 +163,7 @@ export default class DHBaseAction extends foundry.abstract.DataModel { } getRollData(data = {}) { + if (!this.actor) return null; const actorData = this.actor.getRollData(false); // Add Roll results to RollDatas @@ -191,6 +178,8 @@ export default class DHBaseAction extends foundry.abstract.DataModel { } async use(event, ...args) { + if (!this.actor) throw new Error("An Action can't be used outside of an Actor context."); + const isFastForward = event.shiftKey || (!this.hasRoll && !this.hasSave); // Prepare base Config const initConfig = this.initActionConfig(event); @@ -227,7 +216,6 @@ export default class DHBaseAction extends foundry.abstract.DataModel { if (Hooks.call(`${CONFIG.DH.id}.preUseAction`, this, config) === false) return; // Display configuration window if necessary - // if (config.dialog?.configure && this.requireConfigurationDialog(config)) { if (this.requireConfigurationDialog(config)) { config = await D20RollDialog.configure(null, config); if (!config) return; diff --git a/module/data/action/damageAction.mjs b/module/data/action/damageAction.mjs index 7702ab35..988e1844 100644 --- a/module/data/action/damageAction.mjs +++ b/module/data/action/damageAction.mjs @@ -1,3 +1,4 @@ +import { setsEqual } from '../../helpers/utils.mjs'; import DHBaseAction from './baseAction.mjs'; export default class DHDamageAction extends DHBaseAction { @@ -18,28 +19,41 @@ export default class DHDamageAction extends DHBaseAction { return formulaValue; } + formatFormulas(formulas, systemData) { + const formattedFormulas = []; + formulas.forEach(formula => { + if (isNaN(formula.formula)) + formula.formula = Roll.replaceFormulaData(formula.formula, this.getRollData(systemData)); + const same = formattedFormulas.find( + f => setsEqual(f.damageTypes, formula.damageTypes) && f.applyTo === formula.applyTo + ); + if (same) same.formula += ` + ${formula.formula}`; + else formattedFormulas.push(formula); + }); + return formattedFormulas; + } + async rollDamage(event, data) { const systemData = data.system ?? data; - let formula = this.damage.parts.map(p => this.getFormulaValue(p, data).getFormula(this.actor)).join(' + '), - damageTypes = [...new Set(this.damage.parts.reduce((a, c) => a.concat([...c.type]), []))]; - damageTypes = !damageTypes.length ? ['physical'] : damageTypes; + let formulas = this.damage.parts.map(p => ({ + formula: this.getFormulaValue(p, data).getFormula(this.actor), + damageTypes: p.applyTo === 'hitPoints' && !p.type.size ? new Set(['physical']) : p.type, + applyTo: p.applyTo + })); - if (!formula || formula == '') return; - let roll = { formula: formula, total: formula }, - bonusDamage = []; + if (!formulas.length) return; - if (isNaN(formula)) formula = Roll.replaceFormulaData(formula, this.getRollData(systemData)); + formulas = this.formatFormulas(formulas, systemData); const config = { title: game.i18n.format('DAGGERHEART.UI.Chat.damageRoll.title', { damage: game.i18n.localize(this.name) }), - roll: { formula }, + roll: formulas, targets: systemData.targets.filter(t => t.hit) ?? data.targets, hasSave: this.hasSave, isCritical: systemData.roll?.isCritical ?? false, source: systemData.source, data: this.getRollData(), - damageTypes, event }; if (this.hasSave) config.onSave = this.save.damageMod; @@ -50,10 +64,6 @@ export default class DHDamageAction extends DHBaseAction { config.directDamage = true; } - roll = CONFIG.Dice.daggerheart.DamageRoll.build(config); + return CONFIG.Dice.daggerheart.DamageRoll.build(config); } - - // get modifiers() { - // return []; - // } } diff --git a/module/data/action/healingAction.mjs b/module/data/action/healingAction.mjs index 4c1366a1..b7cc4a75 100644 --- a/module/data/action/healingAction.mjs +++ b/module/data/action/healingAction.mjs @@ -15,25 +15,27 @@ export default class DHHealingAction extends DHBaseAction { } async rollHealing(event, data) { - let formulaValue = this.getFormulaValue(data), - formula = formulaValue.getFormula(this.actor); - - if (!formula || formula == '') return; - let roll = { formula: formula, total: formula }, - bonusDamage = []; + const systemData = data.system ?? data; + let formulas = [ + { + formula: this.getFormulaValue(data).getFormula(this.actor), + applyTo: this.healing.applyTo + } + ]; const config = { title: game.i18n.format('DAGGERHEART.UI.Chat.healingRoll.title', { - healing: game.i18n.localize(CONFIG.DH.GENERAL.healingTypes[this.healing.type].label) + healing: game.i18n.localize(CONFIG.DH.GENERAL.healingTypes[this.healing.applyTo].label) }), - roll: { formula }, + roll: formulas, targets: (data.system?.targets ?? data.targets).filter(t => t.hit), messageType: 'healing', - type: this.healing.type, + source: systemData.source, + data: this.getRollData(), event }; - roll = CONFIG.Dice.daggerheart.DamageRoll.build(config); + return CONFIG.Dice.daggerheart.DamageRoll.build(config); } get chatTemplate() { diff --git a/module/data/actor/character.mjs b/module/data/actor/character.mjs index 605b92e1..e0f11d7e 100644 --- a/module/data/actor/character.mjs +++ b/module/data/actor/character.mjs @@ -208,11 +208,10 @@ export default class DhCharacter extends BaseDataActor { rules: new fields.SchemaField({ damageReduction: new fields.SchemaField({ maxArmorMarked: new fields.SchemaField({ - value: new fields.NumberField({ required: true, integer: true, initial: 1 }), - bonus: new fields.NumberField({ + value: new fields.NumberField({ required: true, integer: true, - initial: 0, + initial: 1, label: 'DAGGERHEART.GENERAL.Rules.damageReduction.maxArmorMarkedBonus' }), stressExtra: new fields.NumberField({ diff --git a/module/dice/d20Roll.mjs b/module/dice/d20Roll.mjs index 58d45f95..95cba5ca 100644 --- a/module/dice/d20Roll.mjs +++ b/module/dice/d20Roll.mjs @@ -92,7 +92,7 @@ export default class D20Roll extends DHRoll { configureModifiers() { this.applyAdvantage(); - + this.baseTerms = foundry.utils.deepClone(this.dice); this.options.roll.modifiers = this.applyBaseBonus(); @@ -140,28 +140,21 @@ export default class D20Roll extends DHRoll { return modifiers; } - static async buildEvaluate(roll, config = {}, message = {}) { - if (config.evaluate !== false) await roll.evaluate(); - - this.postEvaluate(roll, config); - } - static postEvaluate(roll, config = {}) { - super.postEvaluate(roll, config); + const data = super.postEvaluate(roll, config); if (config.targets?.length) { config.targets.forEach(target => { const difficulty = config.roll.difficulty ?? target.difficulty ?? target.evasion; target.hit = this.isCritical || roll.total >= difficulty; }); - } else if (config.roll.difficulty) - config.roll.success = roll.isCritical || roll.total >= config.roll.difficulty; - config.roll.advantage = { + } else if (config.roll.difficulty) data.success = roll.isCritical || roll.total >= config.roll.difficulty; + data.advantage = { type: config.roll.advantage, dice: roll.dAdvantage?.denomination, value: roll.dAdvantage?.total }; - config.roll.isCritical = roll.isCritical; - config.roll.extra = roll.dice + data.isCritical = roll.isCritical; + data.extra = roll.dice .filter(d => !roll.baseTerms.includes(d)) .map(d => { return { @@ -169,7 +162,8 @@ export default class D20Roll extends DHRoll { value: d.total }; }); - config.roll.modifierTotal = this.calculateTotalModifiers(roll); + data.modifierTotal = this.calculateTotalModifiers(roll); + return data; } resetFormula() { diff --git a/module/dice/damageRoll.mjs b/module/dice/damageRoll.mjs index bfbfc7d5..f89af747 100644 --- a/module/dice/damageRoll.mjs +++ b/module/dice/damageRoll.mjs @@ -10,10 +10,24 @@ export default class DamageRoll extends DHRoll { static DefaultDialog = DamageDialog; - static async postEvaluate(roll, config = {}) { - super.postEvaluate(roll, config); - config.roll.type = config.type; - config.roll.modifierTotal = this.calculateTotalModifiers(roll); + static async buildEvaluate(roll, config = {}, message = {}) { + if (config.evaluate !== false) { + for (const roll of config.roll) await roll.roll.evaluate(); + } + roll._evaluated = true; + const parts = config.roll.map(r => this.postEvaluate(r)); + config.roll = this.unifyDamageRoll(parts); + } + + static postEvaluate(roll, config = {}) { + return { + ...roll, + ...super.postEvaluate(roll.roll, config), + damageTypes: [...(roll.damageTypes ?? [])], + roll: roll.roll, + type: config.type, + modifierTotal: this.calculateTotalModifiers(roll.roll) + }; } static async buildPost(roll, config, message) { @@ -24,12 +38,50 @@ export default class DamageRoll extends DHRoll { } } - applyBaseBonus() { + static unifyDamageRoll(rolls) { + const unified = {}; + rolls.forEach(r => { + const resource = unified[r.applyTo] ?? { formula: '', total: 0, parts: [] }; + resource.formula += `${resource.formula !== '' ? ' + ' : ''}${r.formula}`; + resource.total += r.total; + resource.parts.push(r); + unified[r.applyTo] = resource; + }); + return unified; + } + + static formatGlobal(rolls) { + let formula, total; + const applyTo = new Set(rolls.flatMap(r => r.applyTo)); + if (applyTo.size > 1) { + const data = {}; + rolls.forEach(r => { + if (data[r.applyTo]) { + data[r.applyTo].formula += ` + ${r.formula}`; + data[r.applyTo].total += r.total; + } else { + data[r.applyTo] = { + formula: r.formula, + total: r.total + }; + } + }); + formula = Object.entries(data).reduce((a, [k, v]) => a + ` ${k}: ${v.formula}`, ''); + total = Object.entries(data).reduce((a, [k, v]) => a + ` ${k}: ${v.total}`, ''); + } else { + formula = rolls.map(r => r.formula).join(' + '); + total = rolls.reduce((a, c) => a + c.total, 0); + } + return { formula, total }; + } + + applyBaseBonus(part) { const modifiers = [], - type = this.options.messageType ?? 'damage'; + type = this.options.messageType ?? 'damage', + options = part ?? this.options; modifiers.push(...this.getBonus(`${type}`, `${type.capitalize()} Bonus`)); - this.options.damageTypes?.forEach(t => { + options.damageTypes?.forEach(t => { modifiers.push(...this.getBonus(`${type}.${t}`, `${t.capitalize()} ${type.capitalize()} Bonus`)); }); const weapons = ['primaryWeapon', 'secondaryWeapon']; @@ -42,13 +94,36 @@ export default class DamageRoll extends DHRoll { } constructFormula(config) { - super.constructFormula(config); + this.options.roll.forEach(part => { + part.roll = new Roll(part.formula); + this.constructFormulaPart(config, part); + }); + return this.options.roll; + } - if (config.isCritical) { - const tmpRoll = new Roll(this._formula)._evaluateSync({ maximize: true }), - criticalBonus = tmpRoll.total - this.constructor.calculateTotalModifiers(tmpRoll); - this.terms.push(...this.formatModifier(criticalBonus)); + constructFormulaPart(config, part) { + part.roll.terms = Roll.parse(part.roll.formula, config.data); + + if (part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) { + part.modifiers = this.applyBaseBonus(part); + this.addModifiers(part); + part.modifiers?.forEach(m => { + part.roll.terms.push(...this.formatModifier(m.value)); + }); } - return (this._formula = this.constructor.getFormula(this.terms)); + + if (part.extraFormula) { + part.roll.terms.push( + new foundry.dice.terms.OperatorTerm({ operator: '+' }), + ...this.constructor.parse(part.extraFormula, this.options.data) + ); + } + + if (config.isCritical && part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) { + const tmpRoll = Roll.fromTerms(part.roll.terms)._evaluateSync({ maximize: true }), + criticalBonus = tmpRoll.total - this.constructor.calculateTotalModifiers(tmpRoll); + part.roll.terms.push(...this.formatModifier(criticalBonus)); + } + return (part.roll._formula = this.constructor.getFormula(part.roll.terms)); } } diff --git a/module/dice/dhRoll.mjs b/module/dice/dhRoll.mjs index 33de251b..c50c126a 100644 --- a/module/dice/dhRoll.mjs +++ b/module/dice/dhRoll.mjs @@ -47,7 +47,7 @@ export default class DHRoll extends Roll { static async buildEvaluate(roll, config = {}, message = {}) { if (config.evaluate !== false) await roll.evaluate(); - this.postEvaluate(roll, config); + config.roll = this.postEvaluate(roll, config); } static async buildPost(roll, config, message) { @@ -57,25 +57,27 @@ export default class DHRoll extends Roll { // Create Chat Message if (config.source?.message) { + if (Object.values(config.roll)?.length) { + const pool = foundry.dice.terms.PoolTerm.fromRolls( + Object.values(config.roll).flatMap(r => r.parts.map(p => p.roll)) + ); + roll = Roll.fromTerms([pool]); + } if (game.modules.get('dice-so-nice')?.active) await game.dice3d.showForRoll(roll, game.user, true); - } else { - config.message = await this.toMessage(roll, config); - } + } else config.message = await this.toMessage(roll, config); } static postEvaluate(roll, config = {}) { - if (!config.roll) config.roll = {}; - config.roll.total = roll.total; - config.roll.formula = roll.formula; - config.roll.dice = []; - roll.dice.forEach(d => { - config.roll.dice.push({ + return { + total: roll.total, + formula: roll.formula, + dice: roll.dice.map(d => ({ dice: d.denomination, total: d.total, formula: d.formula, results: d.results - }); - }); + })) + }; } static async toMessage(roll, config) { @@ -118,8 +120,9 @@ export default class DHRoll extends Roll { return []; } - addModifiers() { - this.options.roll.modifiers?.forEach(m => { + addModifiers(roll) { + roll = roll ?? this.options.roll; + roll.modifiers?.forEach(m => { this.terms.push(...this.formatModifier(m.value)); }); } diff --git a/module/dice/dualityRoll.mjs b/module/dice/dualityRoll.mjs index 5fd71e6c..142f21e8 100644 --- a/module/dice/dualityRoll.mjs +++ b/module/dice/dualityRoll.mjs @@ -63,24 +63,22 @@ export default class DualityRoll extends D20Roll { } setRallyChoices() { - return this.data?.parent?.effects.reduce((a,c) => { - const change = c.changes.find(ch => ch.key === 'system.bonuses.rally'); - if(change) a.push({ value: c.id, label: change.value }); - return a; - }, []); + return this.data?.parent?.effects.reduce((a, c) => { + const change = c.changes.find(ch => ch.key === 'system.bonuses.rally'); + if (change) a.push({ value: c.id, label: change.value }); + return a; + }, []); } get dRally() { - if(!this.rallyFaces) return null; - if(this.hasDisadvantage || this.hasAdvantage) - return this.dice[3]; - else - return this.dice[2]; + if (!this.rallyFaces) return null; + if (this.hasDisadvantage || this.hasAdvantage) return this.dice[3]; + else return this.dice[2]; } get rallyFaces() { const rallyChoice = this.rallyChoices?.find(r => r.value === this._rallyIndex)?.label; - return rallyChoice ? this.getFaces(rallyChoice) : null; + return rallyChoice ? this.getFaces(rallyChoice) : null; } get isCritical() { @@ -129,13 +127,13 @@ export default class DualityRoll extends D20Roll { if (this.hasAdvantage || this.hasDisadvantage) { const dieFaces = this.advantageFaces, advDie = new foundry.dice.terms.Die({ faces: dieFaces, number: this.advantageNumber }); - if(this.advantageNumber > 1) advDie.modifiers = ['kh']; + if (this.advantageNumber > 1) advDie.modifiers = ['kh']; this.terms.push( new foundry.dice.terms.OperatorTerm({ operator: this.hasDisadvantage ? '-' : '+' }), advDie ); } - if(this.rallyFaces) + if (this.rallyFaces) this.terms.push( new foundry.dice.terms.OperatorTerm({ operator: this.hasDisadvantage ? '-' : '+' }), new foundry.dice.terms.Die({ faces: this.rallyFaces }) @@ -161,29 +159,31 @@ export default class DualityRoll extends D20Roll { } static postEvaluate(roll, config = {}) { - super.postEvaluate(roll, config); - - config.roll.hope = { + const data = super.postEvaluate(roll, config); + + data.hope = { dice: roll.dHope.denomination, value: roll.dHope.total }; - config.roll.fear = { + data.fear = { dice: roll.dFear.denomination, value: roll.dFear.total }; - config.roll.rally = { + data.rally = { dice: roll.dRally?.denomination, value: roll.dRally?.total }; - config.roll.result = { + data.result = { duality: roll.withHope ? 1 : roll.withFear ? -1 : 0, total: roll.dHope.total + roll.dFear.total, label: roll.totalLabel }; - if(roll._rallyIndex && roll.data?.parent) + if (roll._rallyIndex && roll.data?.parent) roll.data.parent.deleteEmbeddedDocuments('ActiveEffect', [roll._rallyIndex]); - setDiceSoNiceForDualityRoll(roll, config.roll.advantage.type); + setDiceSoNiceForDualityRoll(roll, data.advantage.type); + + return data; } } diff --git a/module/documents/actor.mjs b/module/documents/actor.mjs index 73a8a3db..83ece8ed 100644 --- a/module/documents/actor.mjs +++ b/module/documents/actor.mjs @@ -391,59 +391,75 @@ export default class DhpActor extends Actor { return canUseArmor || canUseStress; } - async takeDamage(baseDamage, type) { - if (Hooks.call(`${CONFIG.DH.id}.preTakeDamage`, this, baseDamage, type) === false) return null; + async takeDamage(damages) { + if (Hooks.call(`${CONFIG.DH.id}.preTakeDamage`, this, damages) === false) return null; if (this.type === 'companion') { await this.modifyResource([{ value: 1, key: 'stress' }]); return; } - type = !Array.isArray(type) ? [type] : type; + const updates = []; - const hpDamage = this.calculateDamage(baseDamage, type); - - if (!hpDamage) return; - - const updates = [{ value: hpDamage, type: 'hitPoints' }]; - - if (this.type === 'character' && this.system.armor && this.#canReduceDamage(hpDamage, type)) { - const armorStackResult = await this.owner.query('armorStack', { - actorId: this.uuid, - damage: hpDamage, - type: type + Object.entries(damages).forEach(([key, damage]) => { + damage.parts.forEach(part => { + if (part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) + part.total = this.calculateDamage(part.total, part.damageTypes); + const update = updates.find(u => u.key === key); + if (update) { + update.value += part.total; + update.damageTypes.add(...new Set(part.damageTypes)); + } else updates.push({ value: part.total, key, damageTypes: new Set(part.damageTypes) }); }); - if (armorStackResult) { - const { modifiedDamage, armorSpent, stressSpent } = armorStackResult; - updates.find(u => u.type === 'hitPoints').value = modifiedDamage; - updates.push( - ...(armorSpent ? [{ value: armorSpent, key: 'armorStack' }] : []), - ...(stressSpent ? [{ value: stressSpent, key: 'stress' }] : []) - ); + }); + + if (Hooks.call(`${CONFIG.DH.id}.postCalculateDamage`, this, damages) === false) return null; + + if (!updates.length) return; + + const hpDamage = updates.find(u => u.key === CONFIG.DH.GENERAL.healingTypes.hitPoints.id); + if (hpDamage) { + hpDamage.value = this.convertDamageToThreshold(hpDamage.value); + if ( + this.type === 'character' && + this.system.armor && + this.#canReduceDamage(hpDamage.value, hpDamage.damageTypes) + ) { + const armorStackResult = await this.owner.query('armorStack', { + actorId: this.uuid, + damage: hpDamage.value, + type: [...hpDamage.damageTypes] + }); + if (armorStackResult) { + const { modifiedDamage, armorSpent, stressSpent } = armorStackResult; + updates.find(u => u.key === 'hitPoints').value = modifiedDamage; + updates.push( + ...(armorSpent ? [{ value: armorSpent, key: 'armorStack' }] : []), + ...(stressSpent ? [{ value: stressSpent, key: 'stress' }] : []) + ); + } } } + 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}.postTakeDamage`, this, damage, type) === false) return null; + if (Hooks.call(`${CONFIG.DH.id}.postTakeDamage`, this, damages) === false) return null; } calculateDamage(baseDamage, type) { - if (Hooks.call(`${CONFIG.DH.id}.preCalculateDamage`, this, baseDamage, type) === false) return null; - - /* if(this.system.resistance[type]?.immunity) return 0; - if(this.system.resistance[type]?.resistance) baseDamage = Math.ceil(baseDamage / 2); */ if (this.canResist(type, 'immunity')) return 0; if (this.canResist(type, 'resistance')) baseDamage = Math.ceil(baseDamage / 2); - // const flatReduction = this.system.resistance[type].reduction; const flatReduction = this.getDamageTypeReduction(type); const damage = Math.max(baseDamage - (flatReduction ?? 0), 0); - const hpDamage = this.convertDamageToThreshold(damage); - if (Hooks.call(`${CONFIG.DH.id}.postCalculateDamage`, this, baseDamage, type) === false) return null; - - return hpDamage; + return damage; } canResist(type, resistance) { @@ -461,8 +477,13 @@ export default class DhpActor extends Actor { } async takeHealing(resources) { - resources.forEach(r => (r.value *= -1)); - await this.modifyResource(resources); + const updates = Object.entries(resources).map(([key, value]) => ({ + key: key, + value: !(key === 'fear' || this.system?.resources?.[key]?.isReversed === false) + ? value.total * -1 + : value.total + })); + await this.modifyResource(updates); } async modifyResource(resources) { diff --git a/module/documents/token.mjs b/module/documents/token.mjs index ea159fc2..34be55c9 100644 --- a/module/documents/token.mjs +++ b/module/documents/token.mjs @@ -16,7 +16,7 @@ export default class DHToken extends TokenDocument { }); bars.sort((a, b) => a.label.compare(b.label)); - const invalidAttributes = ['gold', 'levelData', 'actions', 'rules.damageReduction.maxArmorMarked.value']; + const invalidAttributes = ['gold', 'levelData', 'actions']; const values = attributes.value.reduce((acc, v) => { const a = v.join('.'); if (invalidAttributes.some(x => a.startsWith(x))) return acc; diff --git a/module/helpers/utils.mjs b/module/helpers/utils.mjs index eac03654..bf4a5c29 100644 --- a/module/helpers/utils.mjs +++ b/module/helpers/utils.mjs @@ -241,3 +241,9 @@ export const itemAbleRollParse = (value, actor, item) => { return ''; } }; + +export const arraysEqual = (a, b) => + a.length === b.length && + [...new Set([...a, ...b])].every(v => a.filter(e => e === v).length === b.filter(e => e === v).length); + +export const setsEqual = (a, b) => a.size === b.size && [...a].every(value => b.has(value)); diff --git a/styles/less/global/dialog.less b/styles/less/global/dialog.less index 11a4eee9..8c86e825 100644 --- a/styles/less/global/dialog.less +++ b/styles/less/global/dialog.less @@ -56,4 +56,15 @@ color: light-dark(@dark, @beige); } + + .damage-formula { + display: flex; + justify-content: space-between; + .damage-details { + font-style: italic; + display: flex; + align-items: center; + gap: 5px; + } + } } diff --git a/styles/less/global/elements.less b/styles/less/global/elements.less index 9d38e386..b9509b38 100755 --- a/styles/less/global/elements.less +++ b/styles/less/global/elements.less @@ -109,7 +109,7 @@ height: 34px; .tags { justify-content: flex-start; - margin: 5px; + margin: 4px; height: inherit; .tag { padding: 0.3rem 0.5rem; diff --git a/styles/less/ui/chat/chat.less b/styles/less/ui/chat/chat.less index 12e8ba0c..6b5db1b9 100644 --- a/styles/less/ui/chat/chat.less +++ b/styles/less/ui/chat/chat.less @@ -164,6 +164,11 @@ } } } + + .damage-resource { + font-weight: 600; + margin-top: 5px; + } } .dice-total { diff --git a/templates/actionTypes/damage.hbs b/templates/actionTypes/damage.hbs index 3c125bd7..bfbbc592 100644 --- a/templates/actionTypes/damage.hbs +++ b/templates/actionTypes/damage.hbs @@ -22,7 +22,12 @@ {{formField ../fields.value.fields.bonus value=dmg.value.bonus name=(concat ../path "damage.parts." index ".value.bonus") localize=true classes="inline-child"}} {{/if}} - {{formField ../fields.type value=dmg.type name=(concat ../path "damage.parts." index ".type") localize=true}} +
+ {{formField ../fields.applyTo value=dmg.applyTo name=(concat ../path "damage.parts." realIndex ".applyTo") localize=true}} + {{#if (eq dmg.applyTo 'hitPoints')}} + {{formField ../fields.type value=dmg.type name=(concat ../path "damage.parts." index ".type") localize=true}} + {{/if}} +
{{#if ../horde}}
{{localize "DAGGERHEART.ACTORS.Adversary.hordeDamage"}} @@ -56,7 +61,12 @@ {{> formula fields=../../fields.value.fields type=../fields.type dmg=dmg source=dmg.value target="value" realIndex=realIndex}}
{{/if}} - {{formField ../../fields.type value=dmg.type name=(concat "damage.parts." realIndex ".type") localize=true}} +
+ {{formField ../../fields.applyTo value=dmg.applyTo name=(concat "damage.parts." realIndex ".applyTo") localize=true}} + {{#if (eq dmg.applyTo 'hitPoints')}} + {{formField ../../fields.type value=dmg.type name=(concat "damage.parts." realIndex ".type") localize=true}} + {{/if}} +
{{#unless dmg.base}}
{{/unless}} diff --git a/templates/actionTypes/healing.hbs b/templates/actionTypes/healing.hbs index 5bf46f7a..4b095174 100644 --- a/templates/actionTypes/healing.hbs +++ b/templates/actionTypes/healing.hbs @@ -1,43 +1,41 @@ -
- -
Healing
+
+ + {{localize "DAGGERHEART.GENERAL.healing"}} -
-
- {{formField fields.type value=source.type name="healing.type" localize=true}} - {{#if (and (not @root.isNPC) @root.hasRoll)}} - {{formField fields.resultBased value=source.resultBased name="healing.resultBased" localize=true}} - {{/if}} - {{#if (and (not @root.isNPC) @root.hasRoll source.resultBased)}} -
- -
With Hope
-
- {{> formula fields=fields.value.fields source=source.value target="value"}} -
-
- -
With Fear
-
- {{> formula fields=fields.valueAlt.fields source=source.valueAlt target="valueAlt"}} -
- {{else}} + {{#if (and (not @root.isNPC) @root.hasRoll)}} + {{formField fields.resultBased value=source.resultBased name="healing.resultBased" localize=true classes="checkbox"}} + {{/if}} + {{#if (and (not @root.isNPC) @root.hasRoll source.resultBased)}} +
+
+ +
With Hope
+
{{> formula fields=fields.value.fields source=source.value target="value"}} - {{/if}} -
-
+
+
+ +
With Fear
+
+ {{> formula fields=fields.valueAlt.fields source=source.valueAlt target="valueAlt"}} +
+
+ {{else}} + {{> formula fields=fields.value.fields source=source.value target="value"}} + {{/if}} + {{formField fields.applyTo value=source.type name="healing.applyTo" localize=true}}
{{#*inline "formula"}} -
- {{formField fields.custom.fields.enabled value=source.custom.enabled name=(concat "healing." target ".custom.enabled")}} - {{#if source.custom.enabled}} - {{formField fields.custom.fields.formula value=source.custom.formula name=(concat "healing." target ".custom.formula") localize=true}} - {{else}} + {{formField fields.custom.fields.enabled value=source.custom.enabled name=(concat "healing." target ".custom.enabled") classes="checkbox"}} + {{#if source.custom.enabled}} + {{formField fields.custom.fields.formula value=source.custom.formula name=(concat "healing." target ".custom.formula") localize=true}} + {{else}} +
{{formField fields.multiplier value=source.multiplier name=(concat "healing." target ".multiplier") localize=true}} {{formField fields.dice value=source.dice name=(concat "healing." target ".dice")}} {{formField fields.bonus value=source.bonus name=(concat "healing." target ".bonus") localize=true}} - {{/if}} -
+
+ {{/if}} {{/inline}} \ No newline at end of file diff --git a/templates/dialogs/dice-roll/damageSelection.hbs b/templates/dialogs/dice-roll/damageSelection.hbs index bd97cfdf..3e47cf68 100644 --- a/templates/dialogs/dice-roll/damageSelection.hbs +++ b/templates/dialogs/dice-roll/damageSelection.hbs @@ -2,10 +2,26 @@

{{title}}

- Formula: {{@root.formula}} -
- -
+ {{#each @root.formula}} +
+ Formula: {{roll.formula}} + + {{#with (lookup @root.config.GENERAL.healingTypes applyTo)}} + {{localize label}} + {{/with}} + {{#if damageTypes}} + {{#each damageTypes as | type | }} + {{#with (lookup @root.config.GENERAL.damageTypes type)}} + + {{/with}} + {{/each}} + {{/if}} + +
+
+ +
+ {{/each}}
{{#if directDamage}}