2023-02-07 18:06:45 +01:00
|
|
|
import { ReglesOptionelles } from "../settings/regles-optionelles.js";
|
2023-02-10 02:01:43 +01:00
|
|
|
import { EffetsDraconiques } from "../tmr/effets-draconiques.js";
|
2023-02-07 18:06:45 +01:00
|
|
|
|
|
|
|
export class DialogRepos extends Dialog {
|
|
|
|
|
|
|
|
static async create(actor) {
|
|
|
|
if (!ReglesOptionelles.isUsing("chateau-dormant-gardien")) {
|
|
|
|
actor.system.sommeil = {
|
|
|
|
"nouveaujour": true,
|
2023-02-10 02:01:43 +01:00
|
|
|
"insomnie": EffetsDraconiques.isSujetInsomnie(actor),
|
2023-02-07 18:06:45 +01:00
|
|
|
"moral": "neutre",
|
|
|
|
"heures": 4
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/sommeil/dialog-repos.html", actor);
|
|
|
|
const dialog = new DialogRepos(html, actor);
|
|
|
|
dialog.render(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(html, actor) {
|
|
|
|
let options = { classes: ["DialogCreateSigneDraconiqueActorsActors"], width: 400, height: 'fit-content', 'z-index': 99999 };
|
|
|
|
let conf = {
|
|
|
|
title: "Se reposer",
|
|
|
|
content: html,
|
|
|
|
default: "repos",
|
|
|
|
buttons: {
|
|
|
|
"repos": { label: "Se reposer", callback: async it => { this.repos(); } }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
super(conf, options);
|
|
|
|
this.actor = actor;
|
|
|
|
}
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
|
|
|
this.html = html;
|
|
|
|
this.html.find(`.sommeil-actor-moral a`).click(event => this.onActorMoral(event));
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
|
|
|
async repos() {
|
|
|
|
const selection = await this.html.find("[name='repos']:checked").val();
|
|
|
|
switch (selection) {
|
|
|
|
case "sieste": return await this.sieste();
|
|
|
|
case "nuit": return await this.nuit();
|
|
|
|
case "chateau-dormant": return await this.chateauDormant();
|
|
|
|
case "gris-reve": return await this.grisReve();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async grisReve() {
|
|
|
|
await this.html.find("[name='nb-jours']").change();
|
|
|
|
const nbJours = Number.parseInt(await this.html.find("[name='nb-jours']").val());
|
|
|
|
await this.actor.grisReve(nbJours);
|
|
|
|
}
|
|
|
|
|
|
|
|
async chateauDormant() {
|
|
|
|
await this.actor.dormirChateauDormant();
|
|
|
|
}
|
|
|
|
|
|
|
|
async nuit() {
|
|
|
|
await this.html.find("[name='sommeil.heures']").change();
|
2023-02-10 02:01:43 +01:00
|
|
|
const val = await this.html.find("[name='sommeil.heures']").val();
|
|
|
|
const sommeilHeures = Number.parseInt(val ?? '0');
|
2023-02-07 18:06:45 +01:00
|
|
|
await this.actor.dormir(sommeilHeures, { chateauDormant: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
async sieste() {
|
|
|
|
await this.html.find("[name='sieste.heures']").change();
|
|
|
|
const siesteHeures = Number.parseInt(await this.html.find("[name='sieste.heures']").val());
|
|
|
|
await this.actor.dormir(siesteHeures);
|
|
|
|
}
|
|
|
|
|
|
|
|
async onActorMoral(event) {
|
|
|
|
const selected = this.html.find(event.currentTarget);
|
|
|
|
const parentDiv = selected.parents().find('.sommeil-actor-moral');
|
|
|
|
const situationMoral = selected.data('moral');
|
2023-02-10 02:01:43 +01:00
|
|
|
await this.actor.setInfoSommeilMoral(situationMoral);
|
2023-02-07 18:06:45 +01:00
|
|
|
const htmlMoral = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/sommeil/sommeil-actor-moral.hbs', {
|
|
|
|
moral: situationMoral
|
|
|
|
});
|
|
|
|
parentDiv.html(htmlMoral);
|
|
|
|
this.html.find(`.sommeil-actor-moral a`).click(event => this.onActorMoral(event));
|
|
|
|
}
|
|
|
|
}
|