Fix nbBrins par défaut pour potion

This commit is contained in:
Vincent Vandemeulebrouck 2021-06-04 19:30:29 +02:00
parent 080a8b51b3
commit b5c8bb85fd

View File

@ -25,8 +25,8 @@ export class DialogFabriquerPotion extends Dialog {
/* -------------------------------------------- */ /* -------------------------------------------- */
static prepareData(actor, item) { static prepareData(actor, item) {
let potionData = duplicate(Misc.data(item)); let potionData = duplicate(Misc.data(item));
potionData.nbBrinsSelect = RdDUtility.buildListOptions( 1, potionData.data.quantite); potionData.nbBrinsSelect = RdDUtility.buildListOptions(1, potionData.data.quantite);
potionData.nbBrins = potionData.data.quantite; potionData.nbBrins = Math.min(potionData.data.quantite, DialogFabriquerPotion.getNombreBrinOptimal(potionData));
potionData.buttonName = "Fabriquer"; potionData.buttonName = "Fabriquer";
return potionData; return potionData;
} }
@ -35,9 +35,7 @@ export class DialogFabriquerPotion extends Dialog {
constructor(actor, potionData, conf, options) { constructor(actor, potionData, conf, options) {
conf.buttons = { conf.buttons = {
[potionData.buttonName]: { [potionData.buttonName]: {
label: potionData.buttonName, callback: it => { label: potionData.buttonName, callback: it => this.onFabriquer(it)
this.fabriquer();
}
} }
}; };
@ -47,6 +45,14 @@ export class DialogFabriquerPotion extends Dialog {
this.potionData = potionData; 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) { activateListeners(html) {
super.activateListeners(html); super.activateListeners(html);
@ -57,8 +63,9 @@ export class DialogFabriquerPotion extends Dialog {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async fabriquer() { async onFabriquer(it) {
this.actor.fabriquerPotion( this.potionData ); await $("#nbBrins").change();
this.actor.fabriquerPotion(this.potionData);
this.close(); this.close();
} }
} }