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

@ -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) {