Adapt healing

This commit is contained in:
Dapoolp 2025-07-19 15:10:56 +02:00
parent 92feddce1b
commit 3186378872
12 changed files with 95 additions and 87 deletions

View file

@ -1259,6 +1259,7 @@
}, },
"fear": "Fear", "fear": "Fear",
"features": "Features", "features": "Features",
"healing": "Healing",
"hitPoints": { "hitPoints": {
"single": "Hit Point", "single": "Hit Point",
"plural": "Hit Points", "plural": "Hit Points",

View file

@ -10,7 +10,7 @@ export default class DamageReductionDialog extends HandlebarsApplicationMixin(Ap
this.reject = reject; this.reject = reject;
this.actor = actor; this.actor = actor;
this.damage = damage; this.damage = damage;
console.log(damageType)
const canApplyArmor = damageType.every(t => actor.system.armorApplicableDamageTypes[t] === true); const canApplyArmor = damageType.every(t => actor.system.armorApplicableDamageTypes[t] === true);
const maxArmorMarks = canApplyArmor const maxArmorMarks = canApplyArmor
? Math.min( ? Math.min(

View file

@ -208,7 +208,7 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
} }
if (targets.length === 0) 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 (let target of targets) { for (let target of targets) {
let damages = message.system.damage; let damages = message.system.damage;
@ -222,7 +222,6 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
}) })
}) })
} }
// damage = Math.ceil(damage * (CONFIG.DH.ACTIONS.damageOnSave[message.system.onSave]?.mod ?? 1));
target.actor.takeDamage(damages.roll); target.actor.takeDamage(damages.roll);
} }
@ -233,10 +232,10 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
const targets = Array.from(game.user.targets); const targets = Array.from(game.user.targets);
if (targets.length === 0) 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) { for (var target of targets) {
target.actor.takeHealing([{ value: message.system.roll.total, type: message.system.roll.type }]); target.actor.takeHealing(message.system.roll);
} }
}; };

View file

@ -142,7 +142,7 @@ export default class DHBaseAction extends foundry.abstract.DataModel {
static getSourceConfig(parent) { static getSourceConfig(parent) {
const updateSource = {}; const updateSource = {};
updateSource.img ??= parent?.img ?? parent?.system?.img; 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['damage'] = { includeBase: true };
updateSource['range'] = parent?.system?.attack?.range; updateSource['range'] = parent?.system?.attack?.range;
updateSource['roll'] = { updateSource['roll'] = {
@ -216,7 +216,6 @@ export default class DHBaseAction extends foundry.abstract.DataModel {
if (Hooks.call(`${CONFIG.DH.id}.preUseAction`, this, config) === false) return; if (Hooks.call(`${CONFIG.DH.id}.preUseAction`, this, config) === false) return;
// Display configuration window if necessary // Display configuration window if necessary
// if (config.dialog?.configure && this.requireConfigurationDialog(config)) {
if (this.requireConfigurationDialog(config)) { if (this.requireConfigurationDialog(config)) {
config = await D20RollDialog.configure(null, config); config = await D20RollDialog.configure(null, config);
if (!config) return; if (!config) return;

View file

@ -15,25 +15,25 @@ export default class DHHealingAction extends DHBaseAction {
} }
async rollHealing(event, data) { async rollHealing(event, data) {
let formulaValue = this.getFormulaValue(data), const systemData = data.system ?? data;
formula = formulaValue.getFormula(this.actor); let formulas = [{
formula: this.getFormulaValue(data).getFormula(this.actor),
if (!formula || formula == '') return; applyTo: this.healing.applyTo
let roll = { formula: formula, total: formula }; }];
const config = { const config = {
title: game.i18n.format('DAGGERHEART.UI.Chat.healingRoll.title', { 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,
roll: [ formula ],
targets: (data.system?.targets ?? data.targets).filter(t => t.hit), targets: (data.system?.targets ?? data.targets).filter(t => t.hit),
messageType: 'healing', messageType: 'healing',
type: this.healing.type, source: systemData.source,
data: this.getRollData(),
event event
}; };
roll = CONFIG.Dice.daggerheart.DamageRoll.build(config); return CONFIG.Dice.daggerheart.DamageRoll.build(config);
} }
get chatTemplate() { get chatTemplate() {

View file

@ -10,10 +10,11 @@ export default class DamageRoll extends DHRoll {
static DefaultDialog = DamageDialog; static DefaultDialog = DamageDialog;
static async buildEvaluate(rolls, config = {}, message = {}) { static async buildEvaluate(roll, config = {}, message = {}) {
if ( config.evaluate !== false ) { if ( config.evaluate !== false ) {
for ( const roll of config.roll ) await roll.roll.evaluate(); for ( const roll of config.roll ) await roll.roll.evaluate();
} }
roll._evaluated = true;
const parts = config.roll.map(r => this.postEvaluate(r)); const parts = config.roll.map(r => this.postEvaluate(r));
config.roll = this.unifyDamageRoll(parts); config.roll = this.unifyDamageRoll(parts);
} }
@ -22,7 +23,7 @@ export default class DamageRoll extends DHRoll {
return { return {
...roll, ...roll,
...super.postEvaluate(roll.roll, config), ...super.postEvaluate(roll.roll, config),
damageTypes: [...roll.damageTypes], damageTypes: [...(roll.damageTypes ?? [])],
roll: roll.roll, roll: roll.roll,
type: config.type, type: config.type,
modifierTotal: this.calculateTotalModifiers(roll.roll) modifierTotal: this.calculateTotalModifiers(roll.roll)

View file

@ -57,13 +57,13 @@ export default class DHRoll extends Roll {
// Create Chat Message // Create Chat Message
if (config.source?.message) { if (config.source?.message) {
console.log(config) if(Object.values(config.roll)?.length) {
if(Array.isArray(config.roll?.parts)) { const pool = foundry.dice.terms.PoolTerm.fromRolls(Object.values(config.roll).flatMap(r => r.parts.map(p => p.roll)));
const pool = foundry.dice.terms.PoolTerm.fromRolls(config.roll.parts.map(r => r.roll));
roll = Roll.fromTerms([pool]); roll = Roll.fromTerms([pool]);
} }
if (game.modules.get('dice-so-nice')?.active) await game.dice3d.showForRoll(roll, game.user, true); if (game.modules.get('dice-so-nice')?.active) await game.dice3d.showForRoll(roll, game.user, true);
} else { } else {
console.log(roll, config)
config.message = await this.toMessage(roll, config); config.message = await this.toMessage(roll, config);
} }
} }

View file

@ -401,15 +401,15 @@ export default class DhpActor extends Actor {
const updates = []; const updates = [];
Object.entries(damages).forEach(([type, damage]) => { Object.entries(damages).forEach(([key, damage]) => {
damage.parts.forEach(part => { damage.parts.forEach(part => {
if(part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) if(part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id)
part.total = this.calculateDamage(part.total, part.damageTypes); part.total = this.calculateDamage(part.total, part.damageTypes);
const update = updates.find(u => u.type === type); const update = updates.find(u => u.key === key);
if(update) { if(update) {
update.value += part.total; update.value += part.total;
update.damageTypes.add(...new Set(part.damageTypes)); update.damageTypes.add(...new Set(part.damageTypes));
} else updates.push({ value: part.total, type, damageTypes: new Set(part.damageTypes) }) } else updates.push({ value: part.total, key, damageTypes: new Set(part.damageTypes) })
}) })
}); });
@ -417,7 +417,7 @@ export default class DhpActor extends Actor {
if(!updates.length) return; if(!updates.length) return;
const hpDamage = updates.find(u => u.type === CONFIG.DH.GENERAL.healingTypes.hitPoints.id); const hpDamage = updates.find(u => u.key === CONFIG.DH.GENERAL.healingTypes.hitPoints.id);
if(hpDamage) { if(hpDamage) {
hpDamage.value = this.convertDamageToThreshold(hpDamage.value); hpDamage.value = this.convertDamageToThreshold(hpDamage.value);
if (this.type === 'character' && this.system.armor && this.#canReduceDamage(hpDamage.value, hpDamage.damageTypes)) { if (this.type === 'character' && this.system.armor && this.#canReduceDamage(hpDamage.value, hpDamage.damageTypes)) {
@ -428,7 +428,7 @@ export default class DhpActor extends Actor {
}); });
if (armorStackResult) { if (armorStackResult) {
const { modifiedDamage, armorSpent, stressSpent } = armorStackResult; const { modifiedDamage, armorSpent, stressSpent } = armorStackResult;
updates.find(u => u.type === 'hitPoints').value = modifiedDamage; updates.find(u => u.key === 'hitPoints').value = modifiedDamage;
updates.push( updates.push(
...(armorSpent ? [{ value: armorSpent, key: 'armorStack' }] : []), ...(armorSpent ? [{ value: armorSpent, key: 'armorStack' }] : []),
...(stressSpent ? [{ value: stressSpent, key: 'stress' }] : []) ...(stressSpent ? [{ value: stressSpent, key: 'stress' }] : [])
@ -437,6 +437,10 @@ export default class DhpActor extends Actor {
} }
} }
updates.forEach( u =>
u.value = u.key === 'fear' || this.system?.resources?.[u.key]?.isReversed === false ? u.value * -1 : u.value
);
await this.modifyResource(updates); await this.modifyResource(updates);
if (Hooks.call(`${CONFIG.DH.id}.postTakeDamage`, this, damages) === false) return null; if (Hooks.call(`${CONFIG.DH.id}.postTakeDamage`, this, damages) === false) return null;
@ -449,7 +453,6 @@ export default class DhpActor extends Actor {
const flatReduction = this.getDamageTypeReduction(type); const flatReduction = this.getDamageTypeReduction(type);
const damage = Math.max(baseDamage - (flatReduction ?? 0), 0); const damage = Math.max(baseDamage - (flatReduction ?? 0), 0);
// const hpDamage = this.convertDamageToThreshold(damage);
return damage; return damage;
} }
@ -469,8 +472,13 @@ export default class DhpActor extends Actor {
} }
async takeHealing(resources) { async takeHealing(resources) {
resources.forEach(r => (r.value *= -1)); const updates = Object.entries(resources).map(([key, value]) => (
await this.modifyResource(resources); {
key: key,
value: !(key === 'fear' || this.system?.resources?.[key]?.isReversed === false) ? value.total * -1 : value.total
}
))
await this.modifyResource(updates);
} }
async modifyResource(resources) { async modifyResource(resources) {

View file

@ -1,43 +1,41 @@
<fieldset class="action-category"> <fieldset class="one-column">
<legend class="action-category-label" data-action="toggleSection" data-section="effects"> <legend>
<div>Healing</div> {{localize "DAGGERHEART.GENERAL.healing"}}
</legend> </legend>
<div class="action-category-data open">
<fieldset>
{{formField fields.type value=source.type name="healing.type" localize=true}}
{{#if (and (not @root.isNPC) @root.hasRoll)}} {{#if (and (not @root.isNPC) @root.hasRoll)}}
{{formField fields.resultBased value=source.resultBased name="healing.resultBased" localize=true}} {{formField fields.resultBased value=source.resultBased name="healing.resultBased" localize=true classes="checkbox"}}
{{/if}} {{/if}}
{{#if (and (not @root.isNPC) @root.hasRoll source.resultBased)}} {{#if (and (not @root.isNPC) @root.hasRoll source.resultBased)}}
<fieldset> <div class="nest-inputs">
<fieldset class="one-column">
<legend> <legend>
<div>With Hope</div> <div>With Hope</div>
</legend> </legend>
{{> formula fields=fields.value.fields source=source.value target="value"}} {{> formula fields=fields.value.fields source=source.value target="value"}}
</fieldset> </fieldset>
<fieldset> <fieldset class="one-column">
<legend> <legend>
<div>With Fear</div> <div>With Fear</div>
</legend> </legend>
{{> formula fields=fields.valueAlt.fields source=source.valueAlt target="valueAlt"}} {{> formula fields=fields.valueAlt.fields source=source.valueAlt target="valueAlt"}}
</fieldset> </fieldset>
</div>
{{else}} {{else}}
{{> formula fields=fields.value.fields source=source.value target="value"}} {{> formula fields=fields.value.fields source=source.value target="value"}}
{{/if}} {{/if}}
</fieldset> {{formField fields.applyTo value=source.type name="healing.applyTo" localize=true}}
</div>
</fieldset> </fieldset>
{{#*inline "formula"}} {{#*inline "formula"}}
<div class="multi-display"> {{formField fields.custom.fields.enabled value=source.custom.enabled name=(concat "healing." target ".custom.enabled") classes="checkbox"}}
{{formField fields.custom.fields.enabled value=source.custom.enabled name=(concat "healing." target ".custom.enabled")}}
{{#if source.custom.enabled}} {{#if source.custom.enabled}}
{{formField fields.custom.fields.formula value=source.custom.formula name=(concat "healing." target ".custom.formula") localize=true}} {{formField fields.custom.fields.formula value=source.custom.formula name=(concat "healing." target ".custom.formula") localize=true}}
{{else}} {{else}}
<div class="nest-inputs">
{{formField fields.multiplier value=source.multiplier name=(concat "healing." target ".multiplier") localize=true}} {{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.dice value=source.dice name=(concat "healing." target ".dice")}}
{{formField fields.bonus value=source.bonus name=(concat "healing." target ".bonus") localize=true}} {{formField fields.bonus value=source.bonus name=(concat "healing." target ".bonus") localize=true}}
{{/if}}
</div> </div>
{{/if}}
{{/inline}} {{/inline}}

View file

@ -5,7 +5,6 @@
{{#each @root.formula}} {{#each @root.formula}}
<div class="damage-formula"> <div class="damage-formula">
<span class="damage-resource"><b>Formula:</b> {{roll.formula}}</span> <span class="damage-resource"><b>Formula:</b> {{roll.formula}}</span>
{{!-- <span>{{localize (concat 'CONFIG.DH.GENERAL.healingTypes.' applyTo '.label')}}</span> --}}
<span class="damage-details"> <span class="damage-details">
{{#with (lookup @root.config.GENERAL.healingTypes applyTo)}} {{#with (lookup @root.config.GENERAL.healingTypes applyTo)}}
{{localize label}} {{localize label}}

View file

@ -1,27 +1,31 @@
<div class="dice-roll daggerheart chat roll" data-action="expandRoll"> <div class="dice-roll daggerheart chat roll" data-action="expandRoll">
<div class="dice-flavor">{{title}}</div> <div class="dice-flavor">{{title}}</div>
<div class="dice-result"> <div class="dice-result">
<div class="dice-formula">{{roll.formula}}</div> {{#each roll as | resource index | }}
<div class="dice-formula">{{resource.formula}}</div>
<div class="dice-tooltip"> <div class="dice-tooltip">
<div class="wrapper"> <div class="wrapper">
{{#each resource.parts}}
<section class="tooltip-part"> <section class="tooltip-part">
{{#each roll.dice}}
<div class="dice"> <div class="dice">
<header class="part-header flexrow"> <header class="part-header flexrow">
<span class="part-formula">{{formula}}</span> <span class="part-formula">{{formula}}</span>
<span class="part-total">{{total}}</span> <span class="part-total">{{total}}</span>
</header> </header>
<ol class="dice-rolls"> <ol class="dice-rolls">
{{#each dice}}
{{#each results}} {{#each results}}
<li class="roll die {{../denomination}} min">{{result}}</li> <li class="roll die {{../dice}} min">{{result}}</li>
{{/each}}
{{/each}} {{/each}}
</ol> </ol>
</div> </div>
{{/each}}
</section> </section>
{{/each}}
</div> </div>
</div> </div>
<div class="dice-total">{{roll.total}}</div> <div class="dice-total">{{resource.total}}</div>
{{/each}}
<div class="flexrow"> <div class="flexrow">
<button class="healing-button"><span>{{localize "DAGGERHEART.UI.Chat.healingRoll.heal"}}</span></button> <button class="healing-button"><span>{{localize "DAGGERHEART.UI.Chat.healingRoll.heal"}}</span></button>
</div> </div>

View file

@ -1,5 +1,4 @@
<div class="dice-roll daggerheart chat roll" data-action="expandRoll"> <div class="dice-roll daggerheart chat roll" data-action="expandRoll">
{{log damage}}
{{#unless noTitle}}<div class="dice-flavor">{{damage.title}}</div>{{/unless}} {{#unless noTitle}}<div class="dice-flavor">{{damage.title}}</div>{{/unless}}
<div class="dice-result"> <div class="dice-result">
{{#each damage.roll as | roll index | }} {{#each damage.roll as | roll index | }}