From b5c8bb85fdf3b5ff36c254cb88d319e9302ef1ad Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Fri, 4 Jun 2021 19:30:29 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20nbBrins=20par=20d=C3=A9faut=20pour=20poti?= =?UTF-8?q?on?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/dialog-fabriquer-potion.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/module/dialog-fabriquer-potion.js b/module/dialog-fabriquer-potion.js index c6b2096b..c23287aa 100644 --- a/module/dialog-fabriquer-potion.js +++ b/module/dialog-fabriquer-potion.js @@ -25,8 +25,8 @@ export class DialogFabriquerPotion extends Dialog { /* -------------------------------------------- */ static prepareData(actor, item) { let potionData = duplicate(Misc.data(item)); - potionData.nbBrinsSelect = RdDUtility.buildListOptions( 1, potionData.data.quantite); - potionData.nbBrins = potionData.data.quantite; + potionData.nbBrinsSelect = RdDUtility.buildListOptions(1, potionData.data.quantite); + potionData.nbBrins = Math.min(potionData.data.quantite, DialogFabriquerPotion.getNombreBrinOptimal(potionData)); potionData.buttonName = "Fabriquer"; return potionData; } @@ -35,9 +35,7 @@ export class DialogFabriquerPotion extends Dialog { constructor(actor, potionData, conf, options) { conf.buttons = { [potionData.buttonName]: { - label: potionData.buttonName, callback: it => { - this.fabriquer(); - } + label: potionData.buttonName, callback: it => this.onFabriquer(it) } }; @@ -47,18 +45,27 @@ export class DialogFabriquerPotion extends Dialog { this.potionData = potionData; } + static getNombreBrinOptimal(herbeData) { + switch (herbeData.data.categorie ?? '') { + case "Soin": return 12 - herbeData.data.niveau; + case "Repos": return 7 - herbeData.data.niveau; + } + return 1; + } + /* -------------------------------------------- */ activateListeners(html) { super.activateListeners(html); html.find("#nbBrins").change(event => { - this.potionData.nbBrins = Misc.toInt(event.currentTarget.value); + this.potionData.nbBrins = Misc.toInt(event.currentTarget.value); }); } /* -------------------------------------------- */ - async fabriquer() { - this.actor.fabriquerPotion( this.potionData ); + async onFabriquer(it) { + await $("#nbBrins").change(); + this.actor.fabriquerPotion(this.potionData); this.close(); } } \ No newline at end of file