Corrections soins des blessures V2
This commit is contained in:
+9
-70
@@ -1936,7 +1936,7 @@ export class RdDActor extends RdDBaseActorSang {
|
||||
async getTacheBlessure(blesse, blessure) {
|
||||
const gravite = blessure?.system.gravite ?? 0;
|
||||
if (gravite > 0) {
|
||||
const tache = this.itemTypes['tache'].find(it => it.system.itemId == blessure.id)
|
||||
const tache = this.itemTypes[ITEM_TYPES.tache].find(it => it.system.itemId == blessure.id)
|
||||
?? await RdDItemBlessure.createTacheSoinBlessure(this, gravite);
|
||||
await blessure?.updateTacheSoinBlessure(tache);
|
||||
return tache
|
||||
@@ -1990,7 +1990,7 @@ export class RdDActor extends RdDBaseActorSang {
|
||||
selected: { tache: { key: tache.id, forced: options.forced } },
|
||||
type: { allowed: [PART_TACHE], current: PART_TACHE }
|
||||
}
|
||||
return await RollDialog.create(rollData)
|
||||
return await RollDialog.create(rollData, options)
|
||||
}
|
||||
|
||||
const compData = this.getCompetence(tache.system.competence)
|
||||
@@ -2034,8 +2034,8 @@ export class RdDActor extends RdDBaseActorSang {
|
||||
await this.santeIncDec("fatigue", rollData.tache.system.fatigue);
|
||||
|
||||
await RdDRollResult.displayRollData(rollData, this, 'chat-resultat-tache.hbs');
|
||||
if (options?.onRollAutomate) {
|
||||
options.onRollAutomate(rollData);
|
||||
if (options?.callbacks) {
|
||||
await Promise.all(callbacks.map(callback => callback(rollData)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2506,77 +2506,16 @@ export class RdDActor extends RdDBaseActorSang {
|
||||
if (!blessure.system.premierssoins.done) {
|
||||
const tache = await this.getTacheBlessure(blesse, blessure);
|
||||
return await this.rollTache(tache.id, {
|
||||
onRollAutomate: async r => blesse.onRollTachePremiersSoins(blessureId, r),
|
||||
title: 'Premiers soins',
|
||||
forced: true
|
||||
callbacks: [async r => await blesse.onRollTachePremiersSoins(blessureId, r, this.id)],
|
||||
title: 'Premiers soins', forced: true
|
||||
});
|
||||
}
|
||||
else if (!blessure.system.soinscomplets.done) {
|
||||
const diff = blessure.system.difficulte + (blessure.system.premierssoins.bonus ?? 0);
|
||||
return await this.rollCaracCompetence(CARACS.DEXTERITE, "Chirurgie", diff, {
|
||||
title: "Soins complets",
|
||||
onRollAutomate: r => blesse.onRollSoinsComplets(blessureId, r),
|
||||
forced: true
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async onRollTachePremiersSoins(blessureId, rollData) {
|
||||
if (!this.isOwner) {
|
||||
return RdDBaseActor.remoteActorCall({
|
||||
tokenId: this.token?.id,
|
||||
actorId: this.id,
|
||||
method: 'onRollTachePremiersSoins', args: [blessureId, rollData]
|
||||
})
|
||||
}
|
||||
const blessure = this.getItem(blessureId, 'blessure')
|
||||
|
||||
if (blessure && !blessure.system.premierssoins.done) {
|
||||
const tache = rollData.tache;
|
||||
if (rollData.rolled.isETotal) {
|
||||
await blessure.update({
|
||||
'system.difficulte': blessure.system.difficulte - 1,
|
||||
'system.premierssoins.tache': Math.max(0, tache.system.points_de_tache_courant)
|
||||
})
|
||||
}
|
||||
else {
|
||||
const bonus = tache.system.points_de_tache_courant - tache.system.points_de_tache
|
||||
await blessure.update({
|
||||
'system.premierssoins': {
|
||||
done: (bonus >= 0),
|
||||
bonus: Math.max(0, bonus),
|
||||
tache: Math.max(0, tache.system.points_de_tache_courant)
|
||||
}
|
||||
})
|
||||
if (bonus >= 0) {
|
||||
await this.deleteEmbeddedDocuments('Item', [tache.id])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async onRollSoinsComplets(blessureId, rollData) {
|
||||
if (!this.isOwner) {
|
||||
return RdDBaseActor.remoteActorCall({
|
||||
tokenId: this.token?.id,
|
||||
actorId: this.id,
|
||||
method: 'onRollSoinsComplets', args: [blessureId, rollData]
|
||||
})
|
||||
}
|
||||
const blessure = this.getItem(blessureId, 'blessure')
|
||||
if (blessure && blessure.system.premierssoins.done && !blessure.system.soinscomplets.done) {
|
||||
// TODO: update de la blessure: passer par le MJ!
|
||||
if (rollData.rolled.isETotal) {
|
||||
await blessure.setSoinsBlessure({
|
||||
difficulte: blessure.system.difficulte - 1,
|
||||
premierssoins: { done: false, bonus: 0 }, soinscomplets: { done: false, bonus: 0 },
|
||||
})
|
||||
}
|
||||
else {
|
||||
// soins complets finis
|
||||
await blessure.setSoinsBlessure({
|
||||
soinscomplets: { done: true, bonus: Math.max(0, rollData.rolled.ptTache) },
|
||||
callbacks: [async r => await blesse.onRollSoinsComplets(blessureId, r, this.id)],
|
||||
onRollDone: RollDialog.onRollDoneClose,
|
||||
title: "Soins complets", forced: true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user