foundryvtt-reve-de-dragon/module/rdd-roll-encaisser.js

78 lines
2.4 KiB
JavaScript
Raw Permalink Normal View History

import { ENTITE_BLURETTE, ENTITE_INCARNE } from "./constants.js";
import { RdDUtility } from "./rdd-utility.js";
2020-11-07 21:06:37 +01:00
/**
* Extend the base Dialog entity by defining a custom window to perform roll.
* @extends {Dialog}
*/
export class RdDEncaisser extends Dialog {
2020-11-11 04:21:25 +01:00
static async encaisser(actor) {
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-roll-encaisser.html',
{ ajustementsEncaissement: RdDUtility.getAjustementsEncaissement() }
);
new RdDEncaisser(html, actor).render(true);
}
2020-11-11 04:21:25 +01:00
/* -------------------------------------------- */
2020-11-10 13:53:51 +01:00
constructor(html, actor) {
let dialogConf = {
title: "Jet d'Encaissement",
content: html,
}
if (!actor.isEntite()) {
dialogConf.default = "mortel";
dialogConf.buttons = {
"mortel": { label: "Mortel", callback: html => this.performEncaisser("mortel") },
"non-mortel": { label: "Non-mortel", callback: html => this.performEncaisser("non-mortel") },
"sonne": { label: "Sonné", callback: html => this.actor.setSonne() },
};
}
else if (actor.isEntite([ENTITE_BLURETTE, ENTITE_INCARNE])) {
2023-03-14 02:38:21 +01:00
dialogConf.default = "entiteincarnee"
dialogConf.buttons = {
2023-03-14 02:38:21 +01:00
"entiteincarnee": { label: "Entité incarnée", callback: html => this.performEncaisser("entiteincarnee") }
}
}
2020-11-11 04:21:25 +01:00
let dialogOptions = {
classes: ["rdd-roll-dialog"],
2020-11-11 04:21:25 +01:00
width: 320,
height: 'fit-content'
2020-11-11 04:21:25 +01:00
}
2020-11-07 21:06:37 +01:00
// Select proper roll dialog template and stuff
super(dialogConf, dialogOptions);
2020-11-11 04:21:25 +01:00
this.actor = actor;
2020-11-10 13:53:51 +01:00
this.modifier = 0;
this.encaisserSpecial = "aucun";
2020-11-07 21:06:37 +01:00
}
activateListeners(html) {
super.activateListeners(html);
this.html = html;
this.html.find('[name="modificateurDegats"]').val("0");
this.html.find('[name="modificateurDegats"]').change((event) => {
this.modifier = event.currentTarget.value; // Update the selected bonus/malus
});
this.html.find('[name="encaisserSpecial"]').change((event) => {
this.encaisserSpecial = event.currentTarget.value; // Update the selected bonus/malus
});
}
2020-11-11 04:21:25 +01:00
/* -------------------------------------------- */
performEncaisser(mortalite) {
2020-11-11 04:21:25 +01:00
this.actor.encaisserDommages({
dmg: {
total: Number(this.modifier),
ajustement: Number(this.modifier),
encaisserSpecial: this.encaisserSpecial,
mortalite: mortalite
}
2020-11-11 04:21:25 +01:00
});
}
2020-11-07 21:06:37 +01:00
}