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 DialogChateauDormant extends Dialog {
|
|
|
|
|
|
|
|
static async create() {
|
|
|
|
const date = game.system.rdd.calendrier.dateCourante();
|
2023-02-10 02:01:43 +01:00
|
|
|
const actors = game.actors.filter(actor => actor.hasPlayerOwner && actor.isPersonnage());
|
2023-02-07 18:06:45 +01:00
|
|
|
|
|
|
|
const dialogData = {
|
2023-02-10 02:01:43 +01:00
|
|
|
actors: actors,
|
2023-02-07 18:06:45 +01:00
|
|
|
date: date,
|
|
|
|
motifStress: `Nuit du ${date}`,
|
|
|
|
finChateauDormant: game.system.rdd.calendrier.getTimestampFinChateauDormant()
|
|
|
|
};
|
|
|
|
const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/sommeil/dialog-chateau-dormant.hbs",
|
|
|
|
dialogData);
|
|
|
|
|
|
|
|
new DialogChateauDormant(dialogData, html)
|
|
|
|
.render(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(dialogData, html) {
|
|
|
|
const options = {
|
|
|
|
classes: ["rdd-dialog-chateau-dormant"],
|
|
|
|
width: 600,
|
|
|
|
height: 'fit-content',
|
|
|
|
'z-index': 99999
|
|
|
|
};
|
|
|
|
const conf = {
|
|
|
|
title: "De Chateau dormant à Vaisseau",
|
|
|
|
content: html,
|
|
|
|
buttons: {
|
|
|
|
chateauDormant: { label: "Passer à Vaisseau!", callback: it => { this.onChateauDormant(); } }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
super(conf, options);
|
|
|
|
this.dialogData = dialogData;
|
|
|
|
}
|
|
|
|
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
|
|
|
this.html = html;
|
|
|
|
this.html.find('input.sommeil-insomnie').change(event => this.onInsomnie(event));
|
|
|
|
this._activateListenerOnActorMoral(this.html);
|
|
|
|
}
|
|
|
|
|
|
|
|
_activateListenerOnActorMoral(html) {
|
|
|
|
html.find(`span.sommeil-actor-moral a`).click(event => this.onActorMoral(event));
|
|
|
|
}
|
|
|
|
|
|
|
|
onInsomnie(event) {
|
|
|
|
const sommeilInsomnie = this.html.find(event.currentTarget);
|
|
|
|
const isInsomnie = sommeilInsomnie.is(':checked');
|
|
|
|
const sommeilHeures = sommeilInsomnie.parents('.set-sommeil-actor').find('input.sommeil-heures');
|
|
|
|
sommeilHeures.prop('disabled', isInsomnie);
|
|
|
|
if (isInsomnie) {
|
|
|
|
sommeilHeures.val('0');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async onActorMoral(event) {
|
|
|
|
const selected = this.html.find(event.currentTarget);
|
|
|
|
const actorRow = selected.parents('.set-sommeil-actor');
|
|
|
|
const actorId = actorRow.data('actor-id');
|
2023-02-10 02:01:43 +01:00
|
|
|
const actor = this.getActor(actorId);
|
|
|
|
actor.system.sommeil.moral = selected.data('moral');
|
|
|
|
const htmlMoral = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/sommeil/sommeil-actor-moral.hbs', actor.system.sommeil)
|
|
|
|
actorRow.find('.sommeil-actor-moral').html(htmlMoral);
|
|
|
|
// re-attach listeners for actor row
|
|
|
|
this._activateListenerOnActorMoral(actorRow);
|
2023-02-07 18:06:45 +01:00
|
|
|
}
|
|
|
|
|
2023-02-10 02:01:43 +01:00
|
|
|
getActor(actorId) {
|
|
|
|
return this.dialogData.actors.find(it => it.id == actorId);
|
2023-02-07 18:06:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async onChateauDormant() {
|
|
|
|
const motifStress = this.html.find("form input[name='motifStress']").val();
|
2023-02-10 02:01:43 +01:00
|
|
|
const consignesChateauDormant = jQuery.map(this.html.find('li.set-sommeil-actor'), it => {
|
2023-02-07 18:06:45 +01:00
|
|
|
const actorRow = this.html.find(it);
|
|
|
|
const actorId = actorRow.data('actor-id');
|
2023-02-10 02:01:43 +01:00
|
|
|
const actor = this.getActor(actorId);
|
|
|
|
const insomnie = actorRow.find('input.sommeil-insomnie').is(':checked');
|
2023-02-07 18:06:45 +01:00
|
|
|
return {
|
2023-02-10 02:01:43 +01:00
|
|
|
actor,
|
2023-02-07 18:06:45 +01:00
|
|
|
ignorer: actorRow.find('input.sommeil-ignorer').is(':checked'),
|
|
|
|
stress: {
|
|
|
|
motif: motifStress,
|
|
|
|
valeur: Number.parseInt(actorRow.find('input.sommeil-stress').val()),
|
|
|
|
},
|
|
|
|
sommeil: {
|
2023-02-10 02:01:43 +01:00
|
|
|
nouveaujour: true,
|
|
|
|
date: this.dialogData.finChateauDormant,
|
|
|
|
insomnie: insomnie,
|
|
|
|
heures: insomnie ? 0 : Number.parseInt(actorRow.find('input.sommeil-heures').val()),
|
|
|
|
moral: actor.moral,
|
2023-02-07 18:06:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2023-02-10 02:01:43 +01:00
|
|
|
consignesChateauDormant.forEach(async consigne => await consigne.actor.prepareChateauDormant(consigne))
|
2023-02-07 18:06:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|