2021-04-11 12:07:43 +02:00
|
|
|
import { Grammar } from "./grammar.js";
|
|
|
|
import { Misc } from "./misc.js";
|
|
|
|
import { RdDUtility } from "./rdd-utility.js";
|
|
|
|
|
|
|
|
export class DialogFabriquerPotion extends Dialog {
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async create(actor, item, dialogConfig) {
|
|
|
|
let potionData = DialogFabriquerPotion.prepareData(actor, item);
|
|
|
|
|
|
|
|
let conf = {
|
|
|
|
title: `Fabriquer une potion de ${potionData.data.categorie}`,
|
|
|
|
content: await renderTemplate(dialogConfig.html, potionData),
|
|
|
|
default: potionData.buttonName,
|
|
|
|
};
|
|
|
|
|
|
|
|
let options = { classes: ["dialogfabriquerpotion"], width: 600, height: 160, 'z-index': 99999 };
|
|
|
|
mergeObject(options, dialogConfig.options ?? {}, { overwrite: true })
|
|
|
|
|
|
|
|
const dialog = new DialogFabriquerPotion(actor, potionData, conf, options);
|
|
|
|
dialog.render(true);
|
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static prepareData(actor, item) {
|
2022-06-12 09:46:58 +02:00
|
|
|
let potionData = duplicate(item)
|
2021-06-04 19:30:29 +02:00
|
|
|
potionData.nbBrinsSelect = RdDUtility.buildListOptions(1, potionData.data.quantite);
|
|
|
|
potionData.nbBrins = Math.min(potionData.data.quantite, DialogFabriquerPotion.getNombreBrinOptimal(potionData));
|
2021-04-11 12:07:43 +02:00
|
|
|
potionData.buttonName = "Fabriquer";
|
|
|
|
return potionData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
constructor(actor, potionData, conf, options) {
|
|
|
|
conf.buttons = {
|
|
|
|
[potionData.buttonName]: {
|
2021-06-04 19:30:29 +02:00
|
|
|
label: potionData.buttonName, callback: it => this.onFabriquer(it)
|
2021-04-11 12:07:43 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
super(conf, options);
|
|
|
|
|
|
|
|
this.actor = actor;
|
|
|
|
this.potionData = potionData;
|
|
|
|
}
|
|
|
|
|
2021-06-04 19:30:29 +02:00
|
|
|
static getNombreBrinOptimal(herbeData) {
|
|
|
|
switch (herbeData.data.categorie ?? '') {
|
|
|
|
case "Soin": return 12 - herbeData.data.niveau;
|
|
|
|
case "Repos": return 7 - herbeData.data.niveau;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-04-11 12:07:43 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
|
|
|
|
|
|
|
html.find("#nbBrins").change(event => {
|
2021-06-04 19:30:29 +02:00
|
|
|
this.potionData.nbBrins = Misc.toInt(event.currentTarget.value);
|
2021-04-11 12:07:43 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-06-04 19:30:29 +02:00
|
|
|
async onFabriquer(it) {
|
|
|
|
await $("#nbBrins").change();
|
|
|
|
this.actor.fabriquerPotion(this.potionData);
|
2021-04-11 12:07:43 +02:00
|
|
|
this.close();
|
|
|
|
}
|
|
|
|
}
|