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

79 lines
2.1 KiB
JavaScript
Raw Normal View History

2022-07-23 16:48:42 +02:00
import { ENTITE_BLURETTE, ENTITE_INCARNE, ENTITE_NONINCARNE } from "./constants.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
/* -------------------------------------------- */
2020-11-10 13:53:51 +01:00
constructor(html, actor) {
2020-11-07 21:06:37 +01:00
// Common conf
let buttons = {};
if (!actor.isEntite()){
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])){
buttons = {
"cauchemar": { label: "cauchemar", callback: html => this.performEncaisser("cauchemar") }
}
}
2020-11-11 04:21:25 +01:00
let dialogConf = {
title: "Jet d'Encaissement",
2020-11-07 21:06:37 +01:00
content: html,
buttons: buttons,
default: "mortel"
2020-11-07 21:06:37 +01:00
}
2020-11-11 04:21:25 +01:00
let dialogOptions = {
classes: ["rdddialog"],
width: 320,
height: 240
}
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
}
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),
encaisserSpecial: this.encaisserSpecial,
loc: { result: 0, label: "" },
mortalite: mortalite
}
2020-11-11 04:21:25 +01:00
});
}
/* -------------------------------------------- */
activateListeners(html) {
2020-11-07 21:06:37 +01:00
super.activateListeners(html);
2020-11-10 13:53:51 +01:00
// Setup everything onload
2020-11-11 04:21:25 +01:00
$(function () {
$("#modificateurDegats").val("0");
2020-11-10 13:53:51 +01:00
});
html.find('#modificateurDegats').change((event) => {
2020-11-10 13:53:51 +01:00
this.modifier = event.currentTarget.value; // Update the selected bonus/malus
});
html.find('#encaisserSpecial').change((event) => {
this.encaisserSpecial = event.currentTarget.value; // Update the selected bonus/malus
});
2020-11-07 21:06:37 +01:00
}
2020-11-11 04:21:25 +01:00
2020-11-07 21:06:37 +01:00
}