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

@ -26,7 +26,7 @@ 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.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,6 +45,14 @@ 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);
@ -57,7 +63,8 @@ export class DialogFabriquerPotion extends Dialog {
}
/* -------------------------------------------- */
async fabriquer() {
async onFabriquer(it) {
await $("#nbBrins").change();
this.actor.fabriquerPotion(this.potionData);
this.close();
}