2020-12-06 20:11:30 +01:00
|
|
|
import { RdDResolutionTable } from "./rdd-resolution-table.js";
|
|
|
|
import { Misc } from "./misc.js";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extend the base Dialog entity by defining a custom window to perform roll.
|
|
|
|
* @extends {Dialog}
|
|
|
|
*/
|
|
|
|
export class RdDRollDialogEthylisme extends Dialog {
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-04-06 23:39:27 +02:00
|
|
|
constructor(html, rollData, actor, onRoll) {
|
2020-12-06 20:11:30 +01:00
|
|
|
// Common conf
|
2021-04-06 23:39:27 +02:00
|
|
|
let dialogConf = {
|
|
|
|
title: "Test d'éthylisme",
|
|
|
|
content: html,
|
|
|
|
default: "rollButton",
|
|
|
|
buttons: { "rollButton": { label: "Test d'éthylisme", callback: html => this.onButton(html) } }
|
|
|
|
};
|
|
|
|
let dialogOptions = { classes: ["rdddialog"], width: 400, height: 220, 'z-index': 99999 }
|
2020-12-06 20:11:30 +01:00
|
|
|
super(dialogConf, dialogOptions)
|
2021-04-06 23:39:27 +02:00
|
|
|
|
2020-12-18 23:35:53 +01:00
|
|
|
//console.log("ETH", rollData);
|
2021-04-06 23:39:27 +02:00
|
|
|
this.onRoll = onRoll;
|
2020-12-06 20:11:30 +01:00
|
|
|
this.rollData = rollData;
|
|
|
|
this.actor = actor;
|
|
|
|
}
|
|
|
|
|
2021-04-06 23:39:27 +02:00
|
|
|
async onButton(html) {
|
|
|
|
this.onRoll(this.rollData);
|
|
|
|
}
|
|
|
|
|
2020-12-06 20:11:30 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
2021-04-06 23:39:27 +02:00
|
|
|
|
2020-12-06 20:11:30 +01:00
|
|
|
this.bringToTop(); // Ensure top level
|
|
|
|
// Get the rollData stuff
|
|
|
|
var rollData = this.rollData;
|
|
|
|
|
|
|
|
function updateRollResult(rollData) {
|
2021-04-06 23:39:27 +02:00
|
|
|
|
2020-12-29 01:34:15 +01:00
|
|
|
rollData.finalLevel = Number(rollData.etat) + Number(rollData.forceAlcool) + rollData.diffNbDoses;
|
2021-04-06 23:39:27 +02:00
|
|
|
|
2020-12-06 20:11:30 +01:00
|
|
|
// Mise à jour valeurs
|
|
|
|
$("#roll-param").text(rollData.vieValue + " / " + Misc.toSignedString(rollData.finalLevel));
|
|
|
|
$(".table-resolution").remove();
|
2020-12-29 01:34:15 +01:00
|
|
|
$("#resolutionTable").append(RdDResolutionTable.buildHTMLTableExtract(rollData.vieValue, rollData.finalLevel));
|
2020-12-06 20:11:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Setup everything onload
|
|
|
|
$(function () {
|
|
|
|
$("#forceAlcool").val(Misc.toInt(rollData.forceAlcool));
|
|
|
|
updateRollResult(rollData);
|
|
|
|
});
|
2021-04-06 23:39:27 +02:00
|
|
|
|
2020-12-06 20:11:30 +01:00
|
|
|
// Update !
|
|
|
|
html.find('#forceAlcool').change((event) => {
|
|
|
|
rollData.forceAlcool = Misc.toInt(event.currentTarget.value); // Update the selected bonus/malus
|
|
|
|
updateRollResult(rollData);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|