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",
"features": "Features",
"healing": "Healing",
"hitPoints": {
"single": "Hit Point",
"plural": "Hit Points",

View file

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

View file

@ -208,7 +208,7 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
}
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) {
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);
}
@ -233,10 +232,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);
}
};

View file

@ -142,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'] = {
@ -216,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;

View file

@ -15,25 +15,25 @@ 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 };
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: [ 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() {

View file

@ -10,10 +10,11 @@ export default class DamageRoll extends DHRoll {
static DefaultDialog = DamageDialog;
static async buildEvaluate(rolls, config = {}, message = {}) {
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);
}
@ -22,7 +23,7 @@ export default class DamageRoll extends DHRoll {
return {
...roll,
...super.postEvaluate(roll.roll, config),
damageTypes: [...roll.damageTypes],
damageTypes: [...(roll.damageTypes ?? [])],
roll: roll.roll,
type: config.type,
modifierTotal: this.calculateTotalModifiers(roll.roll)

View file

@ -57,13 +57,13 @@ export default class DHRoll extends Roll {
// Create Chat Message
if (config.source?.message) {
console.log(config)
if(Array.isArray(config.roll?.parts)) {
const pool = foundry.dice.terms.PoolTerm.fromRolls(config.roll.parts.map(r => r.roll));
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 {
console.log(roll, config)
config.message = await this.toMessage(roll, config);
}
}

View file

@ -401,15 +401,15 @@ export default class DhpActor extends Actor {
const updates = [];
Object.entries(damages).forEach(([type, damage]) => {
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.type === type);
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, 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;
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) {
hpDamage.value = this.convertDamageToThreshold(hpDamage.value);
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) {
const { modifiedDamage, armorSpent, stressSpent } = armorStackResult;
updates.find(u => u.type === 'hitPoints').value = modifiedDamage;
updates.find(u => u.key === 'hitPoints').value = modifiedDamage;
updates.push(
...(armorSpent ? [{ value: armorSpent, key: 'armorStack' }] : []),
...(stressSpent ? [{ value: stressSpent, key: 'stress' }] : [])
@ -436,7 +436,11 @@ 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);
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 damage = Math.max(baseDamage - (flatReduction ?? 0), 0);
// const hpDamage = this.convertDamageToThreshold(damage);
return damage;
}
@ -469,8 +472,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) {

View file

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

View file

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

View file

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

View file

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