mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 23:49:02 +01:00
Fixed so that costs can be used
This commit is contained in:
parent
d9d7b23838
commit
e294c7906c
7 changed files with 177 additions and 102 deletions
|
|
@ -476,7 +476,7 @@ export default class DhpActor extends Actor {
|
|||
if (Hooks.call(`${CONFIG.DH.id}.preTakeDamage`, this, baseDamage, type) === false) return null;
|
||||
|
||||
if (this.type === 'companion') {
|
||||
await this.modifyResource([{ value: 1, type: 'stress' }]);
|
||||
await this.modifyResource([{ value: 1, key: 'stress' }]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -500,8 +500,8 @@ export default class DhpActor extends Actor {
|
|||
const { modifiedDamage, armorSpent, stressSpent } = armorStackResult;
|
||||
updates.find(u => u.type === 'hitPoints').value = modifiedDamage;
|
||||
updates.push(
|
||||
...(armorSpent ? [{ value: armorSpent, type: 'armorStack' }] : []),
|
||||
...(stressSpent ? [{ value: stressSpent, type: 'stress' }] : [])
|
||||
...(armorSpent ? [{ value: armorSpent, key: 'armorStack' }] : []),
|
||||
...(stressSpent ? [{ value: stressSpent, key: 'stress' }] : [])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -520,51 +520,77 @@ export default class DhpActor extends Actor {
|
|||
if (!resources.length) return;
|
||||
|
||||
if (resources.find(r => r.type === 'stress')) this.convertStressDamageToHP(resources);
|
||||
let updates = { actor: { target: this, resources: {} }, armor: { target: this.system.armor, resources: {} } };
|
||||
let updates = {
|
||||
actor: { target: this, resources: {} },
|
||||
armor: { target: this.system.armor, resources: {} },
|
||||
items: {}
|
||||
};
|
||||
resources.forEach(r => {
|
||||
switch (r.type) {
|
||||
case 'fear':
|
||||
ui.resources.updateFear(
|
||||
game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Resources.Fear) + r.value
|
||||
);
|
||||
break;
|
||||
case 'armorStack':
|
||||
updates.armor.resources['system.marks.value'] = Math.max(
|
||||
Math.min(this.system.armor.system.marks.value + r.value, this.system.armorScore),
|
||||
0
|
||||
);
|
||||
break;
|
||||
default:
|
||||
updates.actor.resources[`system.resources.${r.type}.value`] = Math.max(
|
||||
Math.min(
|
||||
this.system.resources[r.type].value + r.value,
|
||||
this.system.resources[r.type].maxTotal ?? this.system.resources[r.type].max
|
||||
),
|
||||
0
|
||||
);
|
||||
break;
|
||||
if (r.keyIsUUID) {
|
||||
updates.items[r.key] = {
|
||||
uuid: r.key,
|
||||
target: r.target,
|
||||
resources: {
|
||||
'system.resource.value': r.target.system.resource.value + r.value
|
||||
}
|
||||
};
|
||||
} else {
|
||||
switch (r.key) {
|
||||
case 'fear':
|
||||
ui.resources.updateFear(
|
||||
game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Resources.Fear) + r.value
|
||||
);
|
||||
break;
|
||||
case 'armorStack':
|
||||
updates.armor.resources['system.marks.value'] = Math.max(
|
||||
Math.min(this.system.armor.system.marks.value + r.value, this.system.armorScore),
|
||||
0
|
||||
);
|
||||
break;
|
||||
default:
|
||||
updates.actor.resources[`system.resources.${r.type}.value`] = Math.max(
|
||||
Math.min(
|
||||
this.system.resources[r.type].value + r.value,
|
||||
this.system.resources[r.type].maxTotal ?? this.system.resources[r.type].max
|
||||
),
|
||||
0
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
Object.values(updates).forEach(async u => {
|
||||
if (Object.keys(u.resources).length > 0) {
|
||||
await emitAsGM(
|
||||
GMUpdateEvent.UpdateDocument,
|
||||
u.target.update.bind(u.target),
|
||||
u.resources,
|
||||
u.target.uuid
|
||||
);
|
||||
/* if (game.user.isGM) {
|
||||
await u.target.update(u.resources);
|
||||
} else {
|
||||
await game.socket.emit(`system.${CONFIG.DH.id}`, {
|
||||
action: socketEvent.GMUpdate,
|
||||
data: {
|
||||
action: GMUpdateEvent.UpdateDocument,
|
||||
uuid: u.target.uuid,
|
||||
update: u.resources
|
||||
}
|
||||
});
|
||||
} */
|
||||
Object.keys(updates).forEach(async key => {
|
||||
const u = updates[key];
|
||||
if (key === 'items') {
|
||||
Object.values(u).forEach(async item => {
|
||||
await emitAsGM(
|
||||
GMUpdateEvent.UpdateDocument,
|
||||
item.target.update.bind(item.target),
|
||||
item.resources,
|
||||
item.target.uuid
|
||||
);
|
||||
});
|
||||
} else {
|
||||
if (Object.keys(u.resources).length > 0) {
|
||||
await emitAsGM(
|
||||
GMUpdateEvent.UpdateDocument,
|
||||
u.target.update.bind(u.target),
|
||||
u.resources,
|
||||
u.target.uuid
|
||||
);
|
||||
/* if (game.user.isGM) {
|
||||
await u.target.update(u.resources);
|
||||
} else {
|
||||
await game.socket.emit(`system.${CONFIG.DH.id}`, {
|
||||
action: socketEvent.GMUpdate,
|
||||
data: {
|
||||
action: GMUpdateEvent.UpdateDocument,
|
||||
uuid: u.target.uuid,
|
||||
update: u.resources
|
||||
}
|
||||
});
|
||||
} */
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue