From e8626f356661ddeb20c5683c0e660f45ab6ce379 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Tue, 6 Apr 2021 23:39:27 +0200 Subject: [PATCH] =?UTF-8?q?Option=20pour=20=C3=A9tat=20g=C3=A9n=C3=A9ral?= =?UTF-8?q?=20hors=20=C3=A9thylisme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Préparation pour les abus de nourriture et boissons --- module/actor-sheet.js | 2 +- module/actor.js | 25 +++++++++++++++---------- module/rdd-roll-ethylisme.js | 31 ++++++++++++++++++------------- 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 72674ea8..95a13276 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -546,7 +546,7 @@ export class RdDActorSheet extends ActorSheet { this.render(true); }); html.find('#ethylisme-test').click((event) => { - this.actor.ethylismeTest(); + this.actor.jetEthylisme(); this.render(true); }); diff --git a/module/actor.js b/module/actor.js index 93b6e66d..06d8af97 100644 --- a/module/actor.js +++ b/module/actor.js @@ -227,8 +227,14 @@ export class RdDActor extends Actor { return Misc.toInt(Misc.templateData(this).attributs.protection.value); } /* -------------------------------------------- */ - getEtatGeneral() { - return Misc.toInt(Misc.templateData(this).compteurs.etat?.value); + getEtatGeneral(options = { ethylisme: false }) { + const tplData = Misc.templateData(this); + let etatGeneral = Misc.toInt(tplData.compteurs.etat?.value); + if (options.ethylisme) { + // Pour les jets d'Ethylisme, on ignore le degré d'éthylisme (p.162) + etatGeneral -= Math.min(0, tplData.compteurs.ethylisme.value); + } + return etatGeneral; } getMalusArmure() { return Misc.toInt(Misc.templateData(this).attributs?.malusarmure?.value); @@ -1461,8 +1467,8 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ _calculAjustementMoral(succes, moral, situation) { switch (situation) { - case 'heureuse': return succes ? 1 : 0; - case 'malheureuse': return succes ? 0 : -1; + case 'heureux': case 'heureuse': return succes ? 1 : 0; + case 'malheureuse': case 'malheureux': return succes ? 0 : -1; case 'neutre': if (succes && moral <= 0) return 1; if (!succes && moral > 0) return -1; @@ -1482,19 +1488,18 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - async ethylismeTest() { + async jetEthylisme(forceAlcool = 0) { const actorData = Misc.data(this); let rollData = { vieValue: actorData.data.sante.vie.value, - etat: this.getEtatGeneral() - Math.min(0, actorData.data.compteurs.ethylisme.value), // Pour les jets d'Ethylisme, on ignore le degré d'éthylisme (p.162) + forceAlcool: forceAlcool, + etat: this.getEtatGeneral({ ethylisme: true }), diffNbDoses: -Number(actorData.data.compteurs.ethylisme.nb_doses || 0), finalLevel: 0, - diffConditions: 0, - ajustementsConditions: CONFIG.RDD.ajustementsConditions, - forceAlcool: 0 + diffConditions: 0 } let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-roll-ethylisme.html', rollData); - new RdDRollDialogEthylisme(html, rollData, this).render(true); + new RdDRollDialogEthylisme(html, rollData, this, r => this.performEthylisme(r)).render(true); } /* -------------------------------------------- */ diff --git a/module/rdd-roll-ethylisme.js b/module/rdd-roll-ethylisme.js index 0b4a9eca..6eb77c34 100644 --- a/module/rdd-roll-ethylisme.js +++ b/module/rdd-roll-ethylisme.js @@ -8,34 +8,39 @@ import { Misc } from "./misc.js"; export class RdDRollDialogEthylisme extends Dialog { /* -------------------------------------------- */ - constructor(html, rollData, actor) { - - let myButtons = { - rollButton: { label: "Test d'éthylisme", callback: html => this.actor.performEthylisme(this.rollData) } - }; - + constructor(html, rollData, actor, onRoll) { // Common conf - let dialogConf = { content: html, title: "Test d'éthylisme", buttons: myButtons, default: "rollButton" }; - let dialogOptions = { classes: ["rdddialog"], width: 400, height: 220, 'z-index': 99999 } + let dialogConf = { + title: "Test d'éthylisme", + content: html, + default: "rollButton", + buttons: { "rollButton": { label: "Test d'éthylisme", callback: html => this.onButton(html) } } + }; + let dialogOptions = { classes: ["rdddialog"], width: 400, height: 220, 'z-index': 99999 } super(dialogConf, dialogOptions) - + //console.log("ETH", rollData); + this.onRoll = onRoll; this.rollData = rollData; this.actor = actor; } + async onButton(html) { + this.onRoll(this.rollData); + } + /* -------------------------------------------- */ activateListeners(html) { super.activateListeners(html); - + this.bringToTop(); // Ensure top level // Get the rollData stuff var rollData = this.rollData; function updateRollResult(rollData) { - + rollData.finalLevel = Number(rollData.etat) + Number(rollData.forceAlcool) + rollData.diffNbDoses; - + // Mise à jour valeurs $("#roll-param").text(rollData.vieValue + " / " + Misc.toSignedString(rollData.finalLevel)); $(".table-resolution").remove(); @@ -47,7 +52,7 @@ export class RdDRollDialogEthylisme extends Dialog { $("#forceAlcool").val(Misc.toInt(rollData.forceAlcool)); updateRollResult(rollData); }); - + // Update ! html.find('#forceAlcool').change((event) => { rollData.forceAlcool = Misc.toInt(event.currentTarget.value); // Update the selected bonus/malus