diff --git a/module/actor.js b/module/actor.js index faa060a5..a21e2410 100644 --- a/module/actor.js +++ b/module/actor.js @@ -408,19 +408,18 @@ export class RdDActor extends RdDBaseActorSang { /* -------------------------------------------- */ async remiseANeuf() { - ChatMessage.create({ - whisper: ChatUtility.getOwners(this), - content: 'Remise à neuf de ' + this.name - }); - await this.supprimerBlessures(it => true); - await this.removeEffects(e => e.id != STATUSES.StatusDemiReve); - const updates = { + await this.update({ 'system.sante.endurance.value': this.system.sante.endurance.max, 'system.sante.vie.value': this.system.sante.vie.max, 'system.sante.fatigue.value': 0, 'system.compteurs.ethylisme': { value: 1, nb_doses: 0, jet_moral: false } - }; - await this.update(updates); + }) + await this.removeEffects(e => e.id != STATUSES.StatusDemiReve); + await this.supprimerBlessures(it => true); + await ChatMessage.create({ + whisper: ChatUtility.getOwners(this), + content: 'Remise à neuf de ' + this.name + }); } /* -------------------------------------------- */ @@ -524,7 +523,7 @@ export class RdDActor extends RdDBaseActorSang { jet_moral: false, value: value } - }); + }) } /* -------------------------------------------- */ @@ -1891,8 +1890,8 @@ export class RdDActor extends RdDBaseActorSang { } rollData.tache.system.tentatives = rollData.tache.system.nb_jet_succes + rollData.tache.system.nb_jet_echec; - this.updateEmbeddedDocuments('Item', [rollData.tache]); - this.santeIncDec("fatigue", rollData.tache.system.fatigue); + await this.updateEmbeddedDocuments('Item', [rollData.tache]); + await this.santeIncDec("fatigue", rollData.tache.system.fatigue); await RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-tache.html'); if (options?.onRollAutomate) { @@ -2590,7 +2589,7 @@ export class RdDActor extends RdDBaseActorSang { for (const armure of armures) { protection += await RdDDice.rollTotal(armure.system.protection.toString()); if (dmg > 0 && attackerRoll.dmg.encaisserSpecial != "noarmure") { - armure.deteriorerArmure(dmg); + await armure.deteriorerArmure(dmg) dmg = 0; } } diff --git a/module/item/armure.js b/module/item/armure.js index 14096a8b..03f011ec 100644 --- a/module/item/armure.js +++ b/module/item/armure.js @@ -11,7 +11,7 @@ export class RdDItemArmure extends RdDItem { return "systems/foundryvtt-reve-de-dragon/icons/armes_armures/armure_plaques.webp"; } - deteriorerArmure(dmg) { + async deteriorerArmure(dmg) { if (!ReglesOptionnelles.isUsing('deteriorationArmure') || this.system.protection == '0') { return; } @@ -23,12 +23,10 @@ export class RdDItemArmure extends RdDItem { protection = this.calculProtectionDeterioree(); ChatMessage.create({ content: `Votre armure ${this.name} s'est détériorée, elle protège maintenant de ${protection}` }); } - this.update({ - system: { - deterioration: deterioration, - protection: protection - } - }); + await this.update({ + 'system.deterioration': deterioration, + 'system.protection': protection + }) } calculProtectionDeterioree() { diff --git a/module/item/blessure.js b/module/item/blessure.js index d58eb4f0..d028a745 100644 --- a/module/item/blessure.js +++ b/module/item/blessure.js @@ -30,7 +30,7 @@ export class RdDItemBlessure extends RdDItem { prepareDerivedData() { super.prepareDerivedData(); - this.system.label = this.getLabelGravite() + this.system.label = RdDItemBlessure.getLabelGravite(this.system.gravite) } static prepareTacheSoin(gravite) { @@ -43,29 +43,32 @@ export class RdDItemBlessure extends RdDItem { } static async applyFullBlessure(actor, gravite) { - const definition = RdDItemBlessure.getDefinition(gravite) - - let lostEndurance = 0 - let lostVie = 0 - if (definition.endurance) { - lostEndurance = new Roll(definition.endurance) - await lostEndurance.roll(); - actor.santeIncDec("endurance", -Number(lostEndurance.total)); - } + const definition = foundry.utils.duplicate(RdDItemBlessure.getDefinition(gravite)) + if (definition.vie) { - lostVie = definition.vie - actor.santeIncDec("vie", definition.vie) + await actor.santeIncDec("vie", definition.vie) + } + const lostEndurance = await RdDItemBlessure.rollLostEndurance(definition.endurance) + if (lostEndurance) { + await actor.santeIncDec("endurance", -Number(lostEndurance)); } - await this.createBlessure(actor, gravite) ChatMessage.create({ - content: `Blessure ${definition.label} appliquée à ${actor.name}`+ - `
Perte d'endurance : ${lostEndurance}`+ - `
Perte de Vie : ${lostVie}`, + //TODO: hbs + content: `Blessure ${definition.label} appliquée à ${actor.name}
Perte d'endurance : ${lostEndurance} (${definition.endurance})
Perte de Vie : ${definition.vie}`, whisper: ChatUtility.getOwners(actor) }); + actor.sheet?.render() + } + static async rollLostEndurance(formula) { + if (formula) { + const roll = new Roll(formula) + await roll.evaluate() + return roll.total + } + return 0 } static async createBlessure(actor, gravite, localisation = '', attackerToken) { @@ -125,10 +128,10 @@ export class RdDItemBlessure extends RdDItem { } if (this.system.gravite > 0) { const update = { system: { premierssoins: { bonus: 0 }, soinscomplets: { bonus: 0 } } } - const gravite = this.system.gravite; - const graviteMoindre = gravite - 2; + const gravite = this.system.gravite + const graviteMoindre = gravite - 2 const moindres = blessures.filter(it => it.system.gravite == graviteMoindre, 'blessures').length - const label = this.getLabelGravite(); + const label = RdDItemBlessure.getLabelGravite(this.system.gravite) let rolled = await actor.jetRecuperationConstitution(this.system.soinscomplets.bonus, message); @@ -158,7 +161,7 @@ export class RdDItemBlessure extends RdDItem { } peutRetrograder(graviteMoindre, moindres) { - return moindres < RdDItemBlessure.getDefinition(graviteMoindre).max + return moindres < RdDItemBlessure.maxBlessures(graviteMoindre) } async calculerFinPeriodeTemporel(debut) { @@ -182,16 +185,16 @@ export class RdDItemBlessure extends RdDItem { return `systems/foundryvtt-reve-de-dragon/icons/sante/${soins ? 'blessure-soins' : img}.webp` } - getLabelGravite() { - return RdDItemBlessure.getDefinition(this.system.gravite).label + static getLabelGravite(gravite) { + return definitionsBlessures.find(it => it.gravite >= gravite).label } static getDefinition(gravite) { - return definitionsBlessures.sort(Misc.ascending(it => it.gravite)) - .find(it => it.gravite >= gravite); + return definitionsBlessures.find(it => it.gravite >= gravite) } + static maxBlessures(gravite) { - return RdDItemBlessure.getDefinition(gravite).max + return definitionsBlessures.find(it => it.gravite >= gravite).max } isContusion() { @@ -216,7 +219,7 @@ export class RdDItemBlessure extends RdDItem { `Heure et Date: ${new RdDTimestamp(this.system.temporel.debut).formatDateHeure()}`, RdDItem.propertyIfDefined('Blessé', this.parent?.name, this.parent), `Localisation: ${this.system.localisation}`, - `Gravité: ${RdDItemBlessure.getDefinition(this.system.gravite).label}`, + `Gravité: ${this.system.label}`, `Difficulté des soins: ${this.system.difficulte}`, (this.system.soinscomplets.done ? `Bonus soins complets: ${this.system.soinscomplets.bonus}` : diff --git a/templates/actor/header-compteurs.html b/templates/actor/header-compteurs.html index 89904278..8d86aa34 100644 --- a/templates/actor/header-compteurs.html +++ b/templates/actor/header-compteurs.html @@ -1,41 +1,47 @@