Extrait table resolution

(cherry picked from commit a11ce394ce0d5e598da61c303c0665b1eadc8513)
This commit is contained in:
2020-11-11 22:39:36 +01:00
parent 021948bf6e
commit bfce6f59df
4 changed files with 211 additions and 183 deletions

View File

@ -1,132 +1,141 @@
import { RdDResolutionTable } from "./rdd-resolution-table.js";
import { RdDUtility } from "./rdd-utility.js";
/**
* Extend the base Dialog entity by defining a custom window to perform roll.
* @extends {Dialog}
*/
export class RdDRollDialog extends Dialog {
/* -------------------------------------------- */
/* -------------------------------------------- */
constructor(mode, html, rollData, actor) {
let myButtons = { rollButton: {
label: "Lancer",
callback: html => this.performRollSort(html, false)
} };
let myButtons
if (mode == "sort") {
myButtons['reserveButton'] = { label: "Mettre en reserve",
callback: html => this.performRollSort(html, true)
}
myButtons = {
rollButton: { label: "Lancer le sort", callback: html => this.performRollSort(html, false) },
reserveButton: { label: "Mettre en reserve", callback: html => this.performRollSort(html, true) }
}
}
else {
myButtons = {
rollButton: { label: "Lancer", callback: html => this.actor.performRoll(this.rollData) }
};
}
// Common conf
let dialogConf = {
content: html,
buttons: myButtons,
default: "rollButton"
}
let dialogOptions = { classes: [ "rdddialog"] }
let dialogConf = { content: html, title: "Test", buttons: myButtons, default: "rollButton" }
let dialogOptions = { classes: ["rdddialog"], width: 600, height: 400 }
// Select proper roll dialog template and stuff
if (mode == "competence" ) {
dialogConf.title = "Test de compétence",
dialogOptions.width = 600;
dialogOptions.height = 360;
if (mode == "competence") {
dialogConf.title = "Test de compétence"
dialogConf.height = 400
} else if (mode == "arme") {
dialogConf.title = "Test de combat/arme",
dialogOptions.width = 600;
dialogOptions.height = 360;
dialogConf.title = "Test de combat/arme"
dialogConf.height = 430
} else if (mode == "carac") {
dialogConf.title = "Test de caractéristique",
dialogOptions.width = 600;
dialogOptions.height = 320;
dialogConf.title = "Test de caractéristique"
dialogOptions.height = 350
} else if (mode == "sort") {
dialogConf.title = "Lancer un sort",
dialogOptions.width = 600;
dialogOptions.height = 380;
dialogConf.title = "Lancer un sort"
dialogConf.height = 450
}
super(dialogConf, dialogOptions);
super(dialogConf, dialogOptions)
this.mode = mode;
this.rollData = rollData;
this.actor = actor;
}
/* -------------------------------------------- */
performRollSort (html, isReserve=false) {
this.rollData.isSortReserve = isReserve;
this.actor.performRoll( this.rollData );
this.mode = mode
this.rollData = rollData
this.actor = actor
}
/* -------------------------------------------- */
activateListeners(html) {
super.activateListeners(html);
// Get the rollData stuff
var rollData = this.rollData;
function updateRollResult( rollData ) {
if ( rollData.competence )
rollData.finalLevel = parseInt(rollData.competence.data.niveau) + parseInt(rollData.bmValue) + parseInt(rollData.etat);
else if ( rollData.draconicList )
rollData.finalLevel = parseInt(rollData.selectedDraconic.data.niveau) + parseInt(rollData.selectedSort.data.difficulte) + parseInt(rollData.etat);
else
rollData.finalLevel = parseInt(rollData.bmValue) + parseInt(rollData.etat);
rollData.finalLevelStr = (rollData.finalLevel >= 0 ) ? "+" + rollData.finalLevel : rollData.finalLevel;
$("#roll-param").text( rollData.selectedCarac.value + " / " + rollData.finalLevelStr );
rollData.rollTarget = game.data.RdDUtility.getResolutionField( rollData.selectedCarac.value, rollData.finalLevel);
/* -------------------------------------------- */
performRollSort(html, isReserve = false) {
this.rollData.isSortReserve = isReserve;
this.actor.performRoll(this.rollData);
}
let armeTitle = ( rollData.arme ) ? " ("+rollData.arme.name+") " : ""; // If a weapon is there, add it in the title
let niveauStr = "";
if ( rollData.competence ) {
niveauStr = (rollData.competence.data.niveau >= 0) ? "+" + rollData.competence.data.niveau : rollData.competence.data.niveau;
$("#compdialogTitle").text( rollData.selectedCarac.label + "/" + rollData.competence.name + armeTitle + " " + niveauStr );
} else if ( rollData.draconicList) {
$("#compdialogTitle").text( rollData.selectedDraconic.name + " - " + rollData.selectedSort.name );
} else {
$("#compdialogTitle").text( rollData.selectedCarac.label );
}
/* -------------------------------------------- */
activateListeners(html) {
super.activateListeners(html);
// Get the rollData stuff
var rollData = this.rollData;
function updateRollResult(rollData) {
let caracValue = parseInt(rollData.selectedCarac.value)
let rollLevel = RdDRollDialog._computeFinalLevel(rollData);
rollData.finalLevel = rollLevel;
rollData.finalLevelStr = (rollLevel > 0 ? "+" : "") + rollLevel;
rollData.rollTarget = RdDUtility.getResolutionField(rollData.selectedCarac.value, rollData.finalLevel);
$("#roll-param").text(rollData.selectedCarac.value + " / " + rollData.finalLevelStr);
$("#compdialogTitle").text(RdDRollDialog._getTitle(rollData));
$(".table-resolution").remove();
game.data.RdDUtility.makeHTMLResolutionTable( $("#resolutionTable"), rollData.selectedCarac.value-2, parseInt(rollData.selectedCarac.value) + 2, -10, 11,
rollData.selectedCarac.value, rollData.finalLevel );
$("#resolutionTable").append(RdDResolutionTable.buildHTMLTable(caracValue, rollLevel, caracValue - 2, caracValue + 2));
}
// Setup everything onload
$(function() {
$(function () {
// Update html, according to data
if (rollData.competence) {
// Set the default carac from the competence item
console.log(rollData.competence.data.defaut_carac, rollData.carac);
rollData.selectedCarac = rollData.carac[rollData.competence.data.defaut_carac];
$("#carac").val( rollData.competence.data.defaut_carac );
$("#carac").val(rollData.competence.data.defaut_carac);
}
$("#bonusmalus").val( rollData.bmValue );
$("#bonusmalus").val(rollData.bmValue);
updateRollResult(rollData);
});
// Update !
html.find('#bonusmalus').click((event) => {
html.find('#bonusmalus').click((event) => {
rollData.bmValue = event.currentTarget.value; // Update the selected bonus/malus
//console.log("BM CLICKED !!!", rollData.bmValue, rollData.competence.data.niveau, parseInt(rollData.competence.data.niveau) + parseInt(rollData.bmValue) );
updateRollResult(rollData);
});
html.find('#carac').click((event) => {
let caracKey = event.currentTarget.value;
html.find('#carac').click((event) => {
let caracKey = event.currentTarget.value;
rollData.selectedCarac = rollData.carac[caracKey]; // Update the selectedCarac
//console.log("CARAC CLICKED !!!", rollData.selectedCarac, rollData.competence.data.niveau, rollData.bmValue);
updateRollResult(rollData);
});
html.find('#draconic').click((event) => {
let draconicKey = event.currentTarget.value;
});
html.find('#draconic').click((event) => {
let draconicKey = event.currentTarget.value;
rollData.selectedDraconic = rollData.draconicList[draconicKey]; // Update the selectedCarac
//console.log("CARAC CLICKED !!!", rollData.selectedCarac, rollData.competence.data.niveau, rollData.bmValue);
updateRollResult(rollData);
});
html.find('#sort').click((event) => {
let sortKey = event.currentTarget.value;
});
html.find('#sort').click((event) => {
let sortKey = event.currentTarget.value;
rollData.selectedSort = rollData.sortList[sortKey]; // Update the selectedCarac
//console.log("CARAC CLICKED !!!", rollData.selectedCarac, rollData.competence.data.niveau, rollData.bmValue);
updateRollResult(rollData);
});
});
}
static _computeFinalLevel(rollData) {
let etat = rollData.etat === undefined ? 0 : parseInt(rollData.etat);
if (rollData.competence) {
return etat + parseInt(rollData.competence.data.niveau) + parseInt(rollData.bmValue);
}
if (rollData.draconicList) {
return etat + parseInt(rollData.selectedDraconic.data.niveau) + parseInt(rollData.selectedSort.data.difficulte);
}
return etat + parseInt(rollData.bmValue);
}
static _getTitle(rollData) {
if (rollData.competence) {
// If a weapon is there, add it in the title
let armeTitle = (rollData.arme) ? " (" + rollData.arme.name + ") " : "";
let niveauStr = (rollData.competence.data.niveau > 0 ? "+" : "") + rollData.competence.data.niveau;
return rollData.selectedCarac.label + "/" + rollData.competence.name + armeTitle + " " + niveauStr
}
if (rollData.draconicList) {
return rollData.selectedDraconic.name + " - " + rollData.selectedSort.name;
}
return rollData.selectedCarac.label;
}
}