import { ENTITE_NONINCARNE, RDD_CONFIG, renderTemplate } from "./constants.js"; import { RdDUtility } from "./rdd-utility.js"; /** * Extend the base Dialog entity by defining a custom window to perform roll. * @extends {Dialog} */ export class RdDEncaisser extends Dialog { static async encaisser(actor) { let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-roll-encaisser.hbs', { ajustementsEncaissement: RdDUtility.getAjustementsEncaissement() } ); new RdDEncaisser(html, actor).render(true); } /* -------------------------------------------- */ constructor(html, actor) { if (actor.isEntiteNonIncarnee([ENTITE_NONINCARNE])) { throw `${actor.name} est une entité non incarnée et ne peut pas subnir de dommages` } const dialogConf = { title: "Jet d'Encaissement", content: html, default: RDD_CONFIG.encaissement.mortel, buttons: { [RDD_CONFIG.encaissement.mortel]: { label: "Mortel", callback: html => this.performEncaisser(RDD_CONFIG.encaissement.mortel) }, } } if (!actor.isEntite()) { dialogConf.buttons[RDD_CONFIG.encaissement.nonmortel] = { label: "Non-mortel", callback: html => this.performEncaisser(RDD_CONFIG.encaissement.nonmortel) } dialogConf.buttons["sonne"] = { label: "Sonné", callback: html => this.actor.setSonne() } } // Select proper roll dialog template and stuff super(dialogConf, { classes: ["rdd-roll-dialog"], width: 320, height: 'fit-content' }); this.actor = actor; this.modifier = 0; this.encaisserSpecial = "aucun"; } 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 }); } /* -------------------------------------------- */ performEncaisser(mortalite) { this.actor.encaisserDommages({ total: Number(this.modifier), ajustement: Number(this.modifier), encaisserSpecial: this.encaisserSpecial, mortalite: mortalite, penetration: 0 }) } }