Consommer nourriture, suite #168
This commit is contained in:
@ -3,56 +3,24 @@ 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;
|
||||
}
|
||||
static async create(actor, item, template = undefined, options = {}) {
|
||||
const consommerData = DialogConsommer.prepareData(actor, item, options);
|
||||
const html = await renderTemplate(template ?? `systems/foundryvtt-reve-de-dragon/templates/consommer/dialog-${Misc.data(item).type}.html`, consommerData);
|
||||
return new DialogConsommer(actor, item, consommerData, html, options)
|
||||
}
|
||||
|
||||
constructor(actor, item, consommerData, html, options = {}) {
|
||||
mergeObject(options, { classes: ["dialogconsommer"], width: 600, height: 500, 'z-index': 99999 }, { overwrite: false })
|
||||
|
||||
let conf = {
|
||||
title: consommerData.title,
|
||||
content: await renderTemplate(dialogConfig.html, consommerData),
|
||||
content: html,
|
||||
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();
|
||||
buttons: {
|
||||
[consommerData.buttonName]: {
|
||||
label: consommerData.buttonName, callback: it => {
|
||||
this.actor.consommer(this.item, this.consommerData.choix);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -60,66 +28,55 @@ export class DialogConsommer extends Dialog {
|
||||
super(conf, options);
|
||||
|
||||
this.actor = actor;
|
||||
this.item = item;
|
||||
this.consommerData = consommerData;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static prepareData(actor, item, options) {
|
||||
const itemData = duplicate(Misc.data(item));
|
||||
let consommerData = {
|
||||
item: itemData,
|
||||
choix: {
|
||||
doses: options.doses ?? 1,
|
||||
seForcer: options.seForcer ?? false,
|
||||
}
|
||||
}
|
||||
switch (itemData.type) {
|
||||
case 'nourritureboisson':
|
||||
consommerData.title = itemData.data.boisson ? `${itemData.name}: boire une dose` : `${itemData.name}: manger une portion`;
|
||||
consommerData.buttonName = itemData.data.boisson ? "Boire" : "Manger";
|
||||
break;
|
||||
case 'potion':
|
||||
buttonName.title = `${itemData.name}: boire la potion`;
|
||||
consommerData.buttonName = "Boire";
|
||||
break;
|
||||
}
|
||||
DialogConsommer.calculDoses(consommerData, consommerData.choix.doses)
|
||||
return consommerData;
|
||||
}
|
||||
|
||||
static calculDoses(consommerData) {
|
||||
const doses = consommerData.choix.doses;
|
||||
consommerData.totalSust = Misc.keepDecimals(doses * (consommerData.item.data.sust ?? 0), 2);
|
||||
consommerData.totalDesaltere = consommerData.item.data.boisson
|
||||
? Misc.keepDecimals(doses * (consommerData.item.data.desaltere ?? 0), 2)
|
||||
: 0;
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
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(".se-forcer").change(event => {
|
||||
this.consommerData.choix.seForcer = event.currentTarget.checked;
|
||||
});
|
||||
html.find(".consommer-doses").change(event => {
|
||||
this.u
|
||||
this.consommerData.choix.doses = Number(event.currentTarget.value);
|
||||
DialogConsommer.calculDoses(this.consommerData);
|
||||
$(".total-sust").text(this.consommerData.totalSust)
|
||||
$(".total-desaltere").text(this.consommerData.totalDesaltere)
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
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() {
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user