166 - Damage Reduction (#180)

* Temp

* Fixed Stress Reductions

* Changed from index based to object
This commit is contained in:
WBHarry 2025-06-24 23:36:02 +02:00 committed by GitHub
parent e1dd59454c
commit 5dafdaafcd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 1688 additions and 1013 deletions

View file

@ -4,6 +4,7 @@ import RollSelectionDialog from '../applications/rollSelectionDialog.mjs';
import { GMUpdateEvent, socketEvent } from '../helpers/socket.mjs';
import { setDiceSoNiceForDualityRoll } from '../helpers/utils.mjs';
import DHDualityRoll from '../data/chat-message/dualityRoll.mjs';
import DamageReductionDialog from '../applications/damageReductionDialog.mjs';
export default class DhpActor extends Actor {
async _preCreate(data, options, user) {
@ -265,9 +266,9 @@ export default class DhpActor extends Actor {
* @param {object} [config.costs]
*/
async diceRoll(config, action) {
config.source = {...(config.source ?? {}), actor: this._id};
config.data = this.getRollData()
const roll = await CONFIG.Dice.daggerheart[this.type === 'character' ? 'DualityRoll' : 'D20Roll'].build(config)
config.source = { ...(config.source ?? {}), actor: this._id };
config.data = this.getRollData();
const roll = await CONFIG.Dice.daggerheart[this.type === 'character' ? 'DualityRoll' : 'D20Roll'].build(config);
return config;
}
@ -361,66 +362,78 @@ export default class DhpActor extends Actor {
async takeDamage(damage, type) {
const hpDamage =
damage >= this.system.damageThresholds.severe
? -3
? 3
: damage >= this.system.damageThresholds.major
? -2
? 2
: damage >= this.system.damageThresholds.minor
? -1
? 1
: 0;
await this.modifyResource([{value: hpDamage, type}]);
/* const update = {
'system.resources.hitPoints.value': Math.min(
this.system.resources.hitPoints.value + hpDamage,
this.system.resources.hitPoints.max
)
};
if (game.user.isGM) {
await this.update(update);
if (
this.type === 'character' &&
this.system.armor &&
this.system.armor.system.marks.value < this.system.armorScore
) {
new Promise((resolve, reject) => {
new DamageReductionDialog(resolve, reject, this, hpDamage).render(true);
})
.then(async ({ modifiedDamage, armorSpent, stressSpent }) => {
const resources = [
{ value: modifiedDamage, type: 'hitPoints' },
...(armorSpent ? [{ value: armorSpent, type: 'armorStack' }] : []),
...(stressSpent ? [{ value: stressSpent, type: 'stress' }] : [])
];
await this.modifyResource(resources);
})
.catch(() => {
const cls = getDocumentClass('ChatMessage');
const msg = new cls({
user: game.user.id,
content: game.i18n.format('DAGGERHEART.DamageReduction.Notifications.DamageIgnore', {
character: this.name
})
});
cls.create(msg.toObject());
});
} else {
await game.socket.emit(`system.${SYSTEM.id}`, {
action: socketEvent.GMUpdate,
data: {
action: GMUpdateEvent.UpdateDocument,
uuid: this.uuid,
update: update
}
});
} */
await this.modifyResource([{ value: hpDamage, type: 'hitPoints' }]);
}
}
async modifyResource(resources) {
if(!resources.length) return;
let updates = { actor: { target: this, resources: {} }, armor: { target: this.armor, resources: {} } };
if (!resources.length) return;
let updates = { actor: { target: this, resources: {} }, armor: { target: this.system.armor, resources: {} } };
resources.forEach(r => {
switch (type) {
case 'armorStrack':
// resource = 'system.stacks.value';
// target = this.armor;
// update = Math.min(this.marks.value + value, this.marks.max);
updates.armor.resources['system.stacks.value'] = Math.min(this.marks.value + value, this.marks.max);
switch (r.type) {
case 'armorStack':
updates.armor.resources['system.marks.value'] = Math.min(
this.system.armor.system.marks.value + r.value,
this.system.armorScore
);
break;
default:
// resource = `system.resources.${type}`;
// target = this;
// update = Math.min(this.resources[type].value + value, this.resources[type].max);
updates.armor.resources[`system.resources.${type}`] = Math.min(this.resources[type].value + value, this.resources[type].max);
updates.actor.resources[`system.resources.${r.type}.value`] = Math.min(
this.system.resources[r.type].value + r.value,
this.system.resources[r.type].max
);
break;
}
})
Object.values(updates).forEach(async (u) => {
if (game.user.isGM) {
await u.target.update(u.resources);
} else {
await game.socket.emit(`system.${SYSTEM.id}`, {
action: socketEvent.GMUpdate,
data: {
action: GMUpdateEvent.UpdateDocument,
uuid: u.target.uuid,
update: u.resources
}
});
});
Object.values(updates).forEach(async u => {
if (Object.keys(u.resources).length > 0) {
if (game.user.isGM) {
await u.target.update(u.resources);
} else {
await game.socket.emit(`system.${SYSTEM.id}`, {
action: socketEvent.GMUpdate,
data: {
action: GMUpdateEvent.UpdateDocument,
uuid: u.target.uuid,
update: u.resources
}
});
}
}
})
});
}
}