2020-11-27 10:21:20 +01:00
|
|
|
import { RdDItemSort } from "./item-sort.js";
|
2020-11-15 02:07:41 +01:00
|
|
|
import { Misc } from "./misc.js";
|
2020-11-11 22:39:36 +01:00
|
|
|
import { RdDResolutionTable } from "./rdd-resolution-table.js";
|
|
|
|
|
2020-06-03 21:35:18 +02:00
|
|
|
/**
|
|
|
|
* Extend the base Dialog entity by defining a custom window to perform roll.
|
|
|
|
* @extends {Dialog}
|
|
|
|
*/
|
|
|
|
export class RdDRollDialog extends Dialog {
|
2020-11-11 22:39:36 +01:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2020-12-01 17:36:13 +01:00
|
|
|
constructor(mode, html, rollData, actor, attacker = undefined) {
|
2020-11-11 22:39:36 +01:00
|
|
|
|
|
|
|
let myButtons
|
2020-07-26 17:26:17 +02:00
|
|
|
if (mode == "sort") {
|
2020-11-11 22:39:36 +01:00
|
|
|
myButtons = {
|
|
|
|
rollButton: { label: "Lancer le sort", callback: html => this.performRollSort(html, false) },
|
|
|
|
reserveButton: { label: "Mettre en reserve", callback: html => this.performRollSort(html, true) }
|
|
|
|
}
|
2020-07-26 17:26:17 +02:00
|
|
|
}
|
2020-11-11 22:39:36 +01:00
|
|
|
else {
|
|
|
|
myButtons = {
|
|
|
|
rollButton: { label: "Lancer", callback: html => this.actor.performRoll(this.rollData) }
|
|
|
|
};
|
2020-07-26 17:26:17 +02:00
|
|
|
}
|
2020-11-11 22:39:36 +01:00
|
|
|
|
|
|
|
// Common conf
|
|
|
|
let dialogConf = { content: html, title: "Test", buttons: myButtons, default: "rollButton" }
|
2020-11-23 21:59:35 +01:00
|
|
|
let dialogOptions = { classes: ["rdddialog"], width: 600, height: 460, 'z-index': 99999 }
|
2020-11-20 13:46:43 +01:00
|
|
|
|
2020-06-03 21:35:18 +02:00
|
|
|
// Select proper roll dialog template and stuff
|
2020-11-11 22:39:36 +01:00
|
|
|
if (mode == "competence") {
|
|
|
|
dialogConf.title = "Test de compétence"
|
2020-12-05 22:21:13 +01:00
|
|
|
dialogOptions.height = 430
|
2020-06-07 23:16:29 +02:00
|
|
|
} else if (mode == "arme") {
|
2020-11-11 22:39:36 +01:00
|
|
|
dialogConf.title = "Test de combat/arme"
|
2020-12-05 22:21:13 +01:00
|
|
|
dialogOptions.height = 460
|
2020-06-12 22:46:04 +02:00
|
|
|
} else if (mode == "carac") {
|
2020-11-11 22:39:36 +01:00
|
|
|
dialogConf.title = "Test de caractéristique"
|
2020-12-05 22:21:13 +01:00
|
|
|
dialogOptions.height = 420
|
2020-07-23 22:09:40 +02:00
|
|
|
} else if (mode == "sort") {
|
2020-11-11 22:39:36 +01:00
|
|
|
dialogConf.title = "Lancer un sort"
|
2020-11-23 21:59:35 +01:00
|
|
|
dialogOptions.height = 460
|
2020-06-07 23:16:29 +02:00
|
|
|
}
|
2020-11-11 22:39:36 +01:00
|
|
|
super(dialogConf, dialogOptions)
|
2020-06-03 21:35:18 +02:00
|
|
|
|
2020-12-04 20:52:04 +01:00
|
|
|
this.mode = mode;
|
|
|
|
this.rollData = rollData;
|
|
|
|
this.actor = actor;
|
|
|
|
if (attacker)
|
|
|
|
this.attacker = attacker;
|
2020-11-11 22:39:36 +01:00
|
|
|
}
|
2020-06-03 21:35:18 +02:00
|
|
|
|
2020-11-11 22:39:36 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-11-14 03:16:03 +01:00
|
|
|
performRollSort(html, isSortReserve = false) {
|
|
|
|
this.rollData.isSortReserve = isSortReserve;
|
2020-12-04 20:52:04 +01:00
|
|
|
this.actor.performRoll(this.rollData, this.attacker);
|
2020-06-03 21:35:18 +02:00
|
|
|
}
|
|
|
|
|
2020-11-11 22:39:36 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
activateListeners(html) {
|
2020-06-03 21:35:18 +02:00
|
|
|
super.activateListeners(html);
|
2020-11-20 16:45:20 +01:00
|
|
|
|
|
|
|
this.bringToTop(); // Ensure top level
|
2020-06-03 21:35:18 +02:00
|
|
|
// Get the rollData stuff
|
2020-11-11 22:39:36 +01:00
|
|
|
var rollData = this.rollData;
|
|
|
|
|
|
|
|
function updateRollResult(rollData) {
|
|
|
|
let caracValue = parseInt(rollData.selectedCarac.value)
|
|
|
|
let rollLevel = RdDRollDialog._computeFinalLevel(rollData);
|
|
|
|
|
|
|
|
rollData.finalLevel = rollLevel;
|
2020-11-25 00:46:11 +01:00
|
|
|
rollData.caracValue = caracValue
|
2020-12-05 01:10:06 +01:00
|
|
|
|
|
|
|
if (RdDRollDialog._isEtatGeneralApplicable(rollData)) {
|
|
|
|
$(".etat-general").show();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$(".etat-general").hide();
|
|
|
|
}
|
2020-11-13 11:24:56 +01:00
|
|
|
// Sort management
|
|
|
|
if ( rollData.selectedSort ) {
|
|
|
|
//console.log("Toggle show/hide", rollData.selectedSort);
|
2020-11-27 10:21:20 +01:00
|
|
|
if (RdDItemSort.isDifficulteVariable(rollData.selectedSort)) {
|
2020-11-13 11:24:56 +01:00
|
|
|
$("#div-sort-difficulte").show();
|
|
|
|
} else {
|
|
|
|
$("#div-sort-difficulte").hide();
|
|
|
|
}
|
2020-11-27 10:21:20 +01:00
|
|
|
if (RdDItemSort.isCoutVariable(rollData.selectedSort)) {
|
2020-11-13 11:24:56 +01:00
|
|
|
$("#div-sort-ptreve").show();
|
|
|
|
} else {
|
|
|
|
$("#div-sort-ptreve").hide();
|
|
|
|
}
|
|
|
|
}
|
2020-11-11 22:39:36 +01:00
|
|
|
|
2020-12-02 14:00:54 +01:00
|
|
|
// Mise à jour valeurs
|
2020-11-15 02:07:41 +01:00
|
|
|
$("#roll-param").text(rollData.selectedCarac.value + " / " + Misc.toSignedString(rollData.finalLevel));
|
2020-11-11 22:39:36 +01:00
|
|
|
$("#compdialogTitle").text(RdDRollDialog._getTitle(rollData));
|
2020-06-03 21:35:18 +02:00
|
|
|
$(".table-resolution").remove();
|
2020-11-12 23:37:12 +01:00
|
|
|
$("#resolutionTable").append(RdDResolutionTable.buildHTMLTableExtract(caracValue, rollLevel));
|
2020-06-03 21:35:18 +02:00
|
|
|
}
|
2020-11-11 22:39:36 +01:00
|
|
|
|
2020-06-03 21:35:18 +02:00
|
|
|
// Setup everything onload
|
2020-11-11 22:39:36 +01:00
|
|
|
$(function () {
|
2020-06-03 21:35:18 +02:00
|
|
|
// Update html, according to data
|
2020-06-12 22:46:04 +02:00
|
|
|
if (rollData.competence) {
|
|
|
|
// Set the default carac from the competence item
|
2020-11-13 11:24:56 +01:00
|
|
|
//console.log("RdDDialogRoll", rollData.competence.data.defaut_carac, rollData.carac);
|
2020-06-12 22:46:04 +02:00
|
|
|
rollData.selectedCarac = rollData.carac[rollData.competence.data.defaut_carac];
|
2020-11-11 22:39:36 +01:00
|
|
|
$("#carac").val(rollData.competence.data.defaut_carac);
|
2020-06-12 22:46:04 +02:00
|
|
|
}
|
2020-11-27 10:21:20 +01:00
|
|
|
RdDItemSort.setCoutReveReel(rollData.selectedSort);
|
2020-11-15 02:07:41 +01:00
|
|
|
$("#diffLibre").val(Misc.toInt(rollData.diffLibre));
|
|
|
|
$("#diffConditions").val(Misc.toInt(rollData.diffConditions));
|
2020-06-03 21:35:18 +02:00
|
|
|
updateRollResult(rollData);
|
|
|
|
});
|
2020-11-13 11:24:56 +01:00
|
|
|
|
2020-06-03 21:35:18 +02:00
|
|
|
// Update !
|
2020-11-15 02:07:41 +01:00
|
|
|
html.find('#diffLibre').change((event) => {
|
|
|
|
rollData.diffLibre = Misc.toInt(event.currentTarget.value); // Update the selected bonus/malus
|
2020-11-13 11:24:56 +01:00
|
|
|
//console.log("RdDRollDialog","BM CLICKED !!!", rollData);
|
2020-06-03 21:35:18 +02:00
|
|
|
updateRollResult(rollData);
|
|
|
|
});
|
2020-11-15 02:07:41 +01:00
|
|
|
html.find('#diffConditions').change((event) => {
|
|
|
|
rollData.diffConditions = Misc.toInt(event.currentTarget.value); // Update the selected bonus/malus
|
|
|
|
//console.log("RdDRollDialog","BM CLICKED !!!", rollData);
|
|
|
|
updateRollResult(rollData);
|
|
|
|
});
|
|
|
|
html.find('#carac').change((event) => {
|
2020-11-11 22:39:36 +01:00
|
|
|
let caracKey = event.currentTarget.value;
|
2020-11-13 11:24:56 +01:00
|
|
|
this.rollData.selectedCarac = rollData.carac[caracKey]; // Update the selectedCarac
|
|
|
|
//console.log("RdDRollDialog","CARAC CLICKED !!!", rollData);
|
2020-06-03 21:35:18 +02:00
|
|
|
updateRollResult(rollData);
|
2020-11-11 22:39:36 +01:00
|
|
|
});
|
2020-11-15 02:07:41 +01:00
|
|
|
html.find('#draconic').change((event) => {
|
|
|
|
let draconicKey = Misc.toInt(event.currentTarget.value);
|
2020-11-13 11:24:56 +01:00
|
|
|
this.rollData.selectedDraconic = rollData.draconicList[draconicKey]; // Update the selectedCarac
|
|
|
|
//console.log("RdDRollDialog","CARAC CLICKED !!!", rollData);
|
2020-07-23 22:09:40 +02:00
|
|
|
updateRollResult(rollData);
|
2020-11-11 22:39:36 +01:00
|
|
|
});
|
2020-11-15 02:07:41 +01:00
|
|
|
html.find('#sort').change((event) => {
|
|
|
|
let sortKey = Misc.toInt(event.currentTarget.value);
|
2020-11-13 11:24:56 +01:00
|
|
|
this.rollData.selectedSort = rollData.sortList[sortKey]; // Update the selectedCarac
|
2020-11-27 10:21:20 +01:00
|
|
|
RdDItemSort.setCoutReveReel(rollData.selectedSort);
|
2020-11-13 11:24:56 +01:00
|
|
|
//console.log("RdDRollDialog - Sort selection", rollData.selectedSort);
|
|
|
|
updateRollResult(rollData);
|
|
|
|
});
|
2020-11-15 02:07:41 +01:00
|
|
|
html.find('#ptreve-variable').change((event) => {
|
|
|
|
let ptreve = Misc.toInt(event.currentTarget.value);
|
2020-11-27 10:21:20 +01:00
|
|
|
this.rollData.selectedSort.data.ptreve_reel = ptreve;
|
2020-11-13 11:24:56 +01:00
|
|
|
console.log("RdDRollDialog - Cout reve", ptreve);
|
2020-07-23 22:09:40 +02:00
|
|
|
updateRollResult(rollData);
|
2020-11-11 22:39:36 +01:00
|
|
|
});
|
2020-11-27 12:20:13 +01:00
|
|
|
html.find('#ptreve-variable').change((event) => {
|
|
|
|
let ptreve = Misc.toInt(event.currentTarget.value);
|
|
|
|
this.rollData.selectedSort.data.ptreve_reel = ptreve; // Update the selectedCarac
|
|
|
|
console.log("RdDRollDialog - Cout reve", ptreve);
|
|
|
|
updateRollResult(rollData);
|
|
|
|
});
|
2020-11-15 11:15:36 +01:00
|
|
|
html.find('#coupsNonMortels').change((event) => {
|
|
|
|
this.rollData.mortalite = event.currentTarget.checked ? "non-mortel" : "non-mortel";
|
|
|
|
});
|
2020-12-05 22:21:13 +01:00
|
|
|
html.find('#isCharge').change((event) => {
|
|
|
|
this.rollData.isCharge = event.currentTarget.checked;
|
|
|
|
});
|
2020-11-27 12:20:13 +01:00
|
|
|
html.find('#surencMalusApply').change((event) => {
|
|
|
|
this.rollData.surencMalusApply = event.currentTarget.checked;
|
|
|
|
updateRollResult(rollData);
|
|
|
|
});
|
2020-11-27 15:47:18 +01:00
|
|
|
html.find('#useEncForNatation').change((event) => {
|
|
|
|
this.rollData.useEncForNatation = event.currentTarget.checked;
|
|
|
|
updateRollResult(rollData);
|
|
|
|
});
|
2020-11-11 22:39:36 +01:00
|
|
|
}
|
2020-11-12 16:35:51 +01:00
|
|
|
|
2020-12-05 01:10:06 +01:00
|
|
|
static _isEtatGeneralApplicable(rollData) {
|
|
|
|
if (rollData.selectedCarac.label == 'Chance') return false;
|
|
|
|
if (rollData.selectedCarac.label == 'Rêve Actuel') return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-12 16:35:51 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-11-11 22:39:36 +01:00
|
|
|
static _computeFinalLevel(rollData) {
|
2020-12-05 01:10:06 +01:00
|
|
|
const etat = RdDRollDialog._isEtatGeneralApplicable(rollData) ? Misc.toInt(rollData.etat) : 0;
|
2020-11-15 02:07:41 +01:00
|
|
|
const diffConditions = Misc.toInt(rollData.diffConditions);
|
2020-11-27 12:23:22 +01:00
|
|
|
let malusEnc = (rollData.surencMalusApply ) ? rollData.surencMalusValue : 0;
|
2020-11-27 10:21:20 +01:00
|
|
|
let diffLibre = Misc.toInt(rollData.diffLibre);
|
2020-11-27 15:47:18 +01:00
|
|
|
let malusEncNatation = (rollData.useEncForNatation) ? -rollData.encValueForNatation : 0;
|
2020-12-05 22:21:13 +01:00
|
|
|
let chargeBonus = (rollData.isCharge) ? 4 : 0; // gestion de la charge en mélée
|
2020-12-02 14:00:54 +01:00
|
|
|
|
|
|
|
// Gestion malus armure
|
|
|
|
let malusArmureValue = 0;
|
|
|
|
if ( rollData.malusArmureValue != 0 && (rollData.selectedCarac.label == "Agilité" || rollData.selectedCarac.label == "Dérobée" )) {
|
|
|
|
$("#addon-message").text("Malus armure appliqué : " + rollData.malusArmureValue );
|
|
|
|
malusArmureValue = rollData.malusArmureValue;
|
|
|
|
} else {
|
|
|
|
$("#addon-message").text("" );
|
|
|
|
}
|
|
|
|
|
2020-11-27 10:21:20 +01:00
|
|
|
let diffCompetence = 0;
|
2020-11-11 22:39:36 +01:00
|
|
|
if (rollData.competence) {
|
2020-11-27 10:21:20 +01:00
|
|
|
diffCompetence = Misc.toInt(rollData.competence.data.niveau);
|
2020-11-11 22:39:36 +01:00
|
|
|
}
|
2020-11-27 10:21:20 +01:00
|
|
|
else if (rollData.draconicList) {
|
|
|
|
diffCompetence = Misc.toInt(rollData.selectedDraconic.data.niveau);
|
|
|
|
diffLibre = RdDItemSort.getDifficulte(rollData.selectedSort, diffLibre);
|
2020-11-11 22:39:36 +01:00
|
|
|
}
|
2020-12-02 14:00:54 +01:00
|
|
|
|
2020-12-05 22:21:13 +01:00
|
|
|
return etat + diffCompetence + diffLibre + diffConditions + malusEnc + malusEncNatation + malusArmureValue + chargeBonus;
|
2020-06-03 21:35:18 +02:00
|
|
|
}
|
|
|
|
|
2020-11-12 23:50:37 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-11-11 22:39:36 +01:00
|
|
|
static _getTitle(rollData) {
|
|
|
|
if (rollData.competence) {
|
|
|
|
// If a weapon is there, add it in the title
|
|
|
|
let armeTitle = (rollData.arme) ? " (" + rollData.arme.name + ") " : "";
|
2020-11-15 02:07:41 +01:00
|
|
|
let niveau = Misc.toSignedString(rollData.competence.data.niveau);
|
|
|
|
return rollData.selectedCarac.label + "/" + rollData.competence.name + armeTitle + " " + niveau
|
2020-11-11 22:39:36 +01:00
|
|
|
}
|
|
|
|
if (rollData.draconicList) {
|
|
|
|
return rollData.selectedDraconic.name + " - " + rollData.selectedSort.name;
|
|
|
|
}
|
|
|
|
return rollData.selectedCarac.label;
|
|
|
|
}
|
2020-06-03 21:35:18 +02:00
|
|
|
}
|