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) {
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();
}
}