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