124 lines
3.7 KiB
JavaScript
124 lines
3.7 KiB
JavaScript
|
import { Grammar } from "./grammar.js";
|
||
|
import { Misc } from "./misc.js";
|
||
|
|
||
|
export class DialogConsommer extends Dialog {
|
||
|
|
||
|
static async create(actor, item, dialogConfig) {
|
||
|
let consommerData = DialogConsommer.prepareData(actor, item);
|
||
|
if (!consommerData) {
|
||
|
ui.notifications.warn(`Impossible de consommer un ${consommerData.name}, ce n'est pas de la nourriture, une boisson ou une potion`);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
let conf = {
|
||
|
title: consommerData.title,
|
||
|
content: await renderTemplate(dialogConfig.html, consommerData),
|
||
|
default: consommerData.buttonName,
|
||
|
};
|
||
|
|
||
|
|
||
|
let options = { classes: ["dialogconsommer"], width: 600, height: 500, 'z-index': 99999 };
|
||
|
mergeObject(options, dialogConfig.options ?? {}, { overwrite: true })
|
||
|
|
||
|
console.log('consommer', actor, consommerData, conf, options);
|
||
|
const dialog = new DialogConsommer(actor, consommerData, conf, options);
|
||
|
dialog.render(true);
|
||
|
return dialog;
|
||
|
}
|
||
|
|
||
|
static prepareData(actor, item) {
|
||
|
let consommerData = duplicate(Misc.data(item));
|
||
|
switch (consommerData.type) {
|
||
|
default:
|
||
|
return undefined;
|
||
|
case 'nourritureboisson':
|
||
|
consommerData.doses = 1;
|
||
|
consommerData.title = consommerData.data.boisson ? `${consommerData.name}: boire une dose` : `${consommerData.name}: manger une portion`;
|
||
|
consommerData.buttonName = consommerData.data.boisson ? "Boire" : "Manger";
|
||
|
break;
|
||
|
case 'potion':
|
||
|
buttonName.title = `${consommerData.name}: boire la potion`;
|
||
|
consommerData.buttonName = "Boire";
|
||
|
consommerData.alchimie = Misc.data(actor.getCompetence('alchimie'));
|
||
|
break;
|
||
|
}
|
||
|
consommerData.cuisine = Misc.data(actor.getCompetence('cuisine'));
|
||
|
consommerData.seForcer = false;
|
||
|
return consommerData;
|
||
|
}
|
||
|
|
||
|
|
||
|
constructor(actor, consommerData, conf, options) {
|
||
|
conf.buttons = {
|
||
|
[consommerData.buttonName]: {
|
||
|
label: consommerData.buttonName, callback: it => {
|
||
|
this.consommer();
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
super(conf, options);
|
||
|
|
||
|
this.actor = actor;
|
||
|
this.consommerData = consommerData;
|
||
|
}
|
||
|
|
||
|
activateListeners(html) {
|
||
|
super.activateListeners(html);
|
||
|
|
||
|
function updateConsommerData(rollData) {
|
||
|
|
||
|
rollData.finalLevel = Number(rollData.etat) + Number(rollData.forceAlcool) + rollData.diffNbDoses;
|
||
|
|
||
|
// Mise à jour valeurs
|
||
|
$("#roll-param").text(rollData.vieValue + " / " + Misc.toSignedString(rollData.finalLevel));
|
||
|
$(".table-resolution").remove();
|
||
|
$("#resolutionTable").append(RdDResolutionTable.buildHTMLTableExtract(rollData.vieValue, rollData.finalLevel));
|
||
|
}
|
||
|
|
||
|
html.find(".consommer-doses").change(event => {
|
||
|
this.u
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/* -------------------------------------------- */
|
||
|
async consommer() {
|
||
|
switch (this.consommerData.type) {
|
||
|
default:
|
||
|
return undefined;
|
||
|
case 'nourritureboisson':
|
||
|
return await this.consommerNourritureBoisson();
|
||
|
case 'potion':
|
||
|
return await this.consommerPotion();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
async consommerNourritureBoisson() {
|
||
|
const surmonteExotisme = await this.actor.surmonterExotisme(this.consommerData);
|
||
|
if (!surmonteExotisme) {
|
||
|
return;
|
||
|
}
|
||
|
await this.actor.apprecierCuisine(this.consommerData);
|
||
|
if (this.isAlcool()) {
|
||
|
await this.actor.alcool(this.consommerData.data.force);
|
||
|
}
|
||
|
await this.actor.manger(this.consommerData.data.sust);
|
||
|
await this.actor.boire(this.consommerData.data.desaltere);
|
||
|
}
|
||
|
|
||
|
isAlcool() {
|
||
|
return this.consommerData.data.boisson && this.consommerData.data.alcoolise;
|
||
|
}
|
||
|
|
||
|
async apprecierCuisine(qualite) {
|
||
|
const jetGoutCuisine = await this.jetGoutCuisine();
|
||
|
if (jetGoutCuisine) {
|
||
|
await this.actor.jetDeMoral('heureux');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
async consommerPotion() {
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|