From a9d005310f9592ec275f8c733cbf148f6d88fd6e Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Thu, 12 Nov 2020 23:35:29 +0100 Subject: [PATCH 1/2] Clean rencontres --- module/rdd-tmr-dialog.js | 28 ++++++++-------------------- module/tmr-utility.js | 7 ++++--- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/module/rdd-tmr-dialog.js b/module/rdd-tmr-dialog.js index d3a24fd2..e2f27793 100644 --- a/module/rdd-tmr-dialog.js +++ b/module/rdd-tmr-dialog.js @@ -138,7 +138,7 @@ export class RdDTMRDialog extends Dialog { const roll = RdDResolutionTable.roll(carac, difficulte); - if ( roll.roll > scoreDef.score ) { + if ( !roll.isSuccess) { TMRUtility.processRencontreEchec( this.actor, this.currentRencontre); ChatMessage.create( { title: "TMR", content: "Vous avez échoué à votre maîtrise d'un " . this.currentRencontre.name + " de force " + this.currentRencontre.force + @@ -159,28 +159,16 @@ export class RdDTMRDialog extends Dialog { async manageRencontre(coordTMR, cellDescr) { // Roll until diffent than '8' - let rencontre this.currentRencontre = undefined; - for (let previousRencontre of this.rencontresExistantes ) { - if ( previousRencontre.coord == coordTMR) - rencontre = previousRencontre.rencontre; + + let rencontre = this.rencontresExistantes.find(prev => prev.coord == coordTMR); + if (rencontre == undefined && new Roll("d7").roll().total == 7) { + rencontre = TMRUtility.rencontreTMRRoll(coordTMR, cellDescr); } - if ( rencontre == undefined ) { - let val = 8; - while (val == 8) { - let myroll = new Roll("d7"); - myroll.roll(); - val = myroll.total; - if ( val == 7 ) { - rencontre = TMRUtility.rencontreTMRRoll(coordTMR, cellDescr); - rencontre.force = new Roll(rencontre.data.force).roll().total; - } - } - } - + if (rencontre) { // Manages it this.currentRencontre = duplicate(rencontre); - let diag = new Dialog( { title: "Rencontre en TMR!", + let dialog = new Dialog( { title: "Rencontre en TMR!", content: "Vous recontrez un " + rencontre.name + " de force " + rencontre.force + "
", buttons: { derober: { @@ -200,7 +188,7 @@ export class RdDTMRDialog extends Dialog { } } } ); - diag.render(true); + dialog.render(true); } } diff --git a/module/tmr-utility.js b/module/tmr-utility.js index b3df2293..7ed0a3b1 100644 --- a/module/tmr-utility.js +++ b/module/tmr-utility.js @@ -269,13 +269,14 @@ export class TMRUtility { let val = new Roll("d100").roll().total; //console.log("Rencontre !!!!", val, coordTMR, cellDescr); - for( let renc of rencontresTable) { - let scoreDef = renc.data[cellDescr.type]; + for( let rencontre of rencontresTable) { + let scoreDef = rencontre.data[cellDescr.type]; let min = scoreDef.substr(0,2); let max = scoreDef.substr(3,2); //console.log(val, scoreDef, min, max); if ( val >= min && val <= max) { - return renc; + rencontre.force = new Roll(rencontre.data.force).roll().total; + return rencontre; } } } From 1d8468c191e6715e92aaa3fdf3b8ab9c5487b310 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Thu, 12 Nov 2020 23:37:12 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Table=20r=C3=A9solution=20contextuelle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit level - 5 à level + 5 toujours la colonne -8 --- module/rdd-resolution-table.js | 33 +++++++++++++++++++++++++++------ module/rdd-roll-dialog.js | 10 +++++----- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/module/rdd-resolution-table.js b/module/rdd-resolution-table.js index f49b4748..a2427989 100644 --- a/module/rdd-resolution-table.js +++ b/module/rdd-resolution-table.js @@ -151,6 +151,10 @@ export class RdDResolutionTable { } /* -------------------------------------------- */ + static buildHTMLTableExtract(caracValue, levelValue) { + return this.buildHTMLTable(caracValue, levelValue, caracValue - 2, caracValue + 2, levelValue - 5, levelValue + 5) + } + static buildHTMLTable(caracValue, levelValue, minCarac = 1, maxCarac = 21, minLevel = -10, maxLevel = 11) { return this._buildHTMLTable(caracValue, levelValue, minCarac, maxCarac, minLevel, maxLevel) } @@ -162,7 +166,7 @@ export class RdDResolutionTable { minLevel = Math.max(minLevel, -10); maxLevel = Math.min(maxLevel, 22); - var table = $("") + let table = $("
") .append(this._buildHTMLHeader(this.resolutionTable[0], minLevel, maxLevel)); for (var carac = minCarac; carac <= maxCarac; carac++) { @@ -172,8 +176,16 @@ export class RdDResolutionTable { } static _buildHTMLHeader(dataRow, minLevel, maxLevel) { - var tr = $(""); - for (var difficulte = minLevel; difficulte <= maxLevel; difficulte++) { + let tr = $(""); + let max = maxLevel; + + if (minLevel > -8) { + tr.append($(""); - for (var difficulte = minLevel; difficulte <= maxLevel; difficulte++) { - var td = $(""); + let max = maxLevel; + + if (minLevel > -8) { + let score = dataRow[-8 + 10].score; + tr.append($("
").text("-8")) + } + if (minLevel > -7) { + tr.append($("").text("...")); + } + for (let difficulte = minLevel; difficulte <= max; difficulte++) { const niveau = dataRow[difficulte + 10].niveau; const txt = (niveau > 0 ? "+" : "") + niveau; tr.append($("").text(txt)); @@ -182,9 +194,18 @@ export class RdDResolutionTable { } static _buildHTMLRow(dataRow, rowIndex, caracValue, levelValue, minLevel, maxLevel) { - var tr = $("
"); + let tr = $("
").text(score)) + } + if (minLevel > -7) { + tr.append($("")) + } + for (let difficulte = minLevel; difficulte <= max; difficulte++) { + let td = $(""); let score = dataRow[difficulte + 10].score; if (rowIndex == caracValue && levelValue == difficulte) { td.addClass('table-resolution-target'); diff --git a/module/rdd-roll-dialog.js b/module/rdd-roll-dialog.js index d56978be..3aeb287e 100644 --- a/module/rdd-roll-dialog.js +++ b/module/rdd-roll-dialog.js @@ -71,7 +71,7 @@ export class RdDRollDialog extends Dialog { $("#roll-param").text(rollData.selectedCarac.value + " / " + rollData.finalLevelStr); $("#compdialogTitle").text(RdDRollDialog._getTitle(rollData)); $(".table-resolution").remove(); - $("#resolutionTable").append(RdDResolutionTable.buildHTMLTable(caracValue, rollLevel, caracValue - 2, caracValue + 2)); + $("#resolutionTable").append(RdDResolutionTable.buildHTMLTableExtract(caracValue, rollLevel)); } // Setup everything onload @@ -91,25 +91,25 @@ export class RdDRollDialog extends Dialog { // Update ! html.find('#bonusmalus').click((event) => { rollData.bmValue = event.currentTarget.value; // Update the selected bonus/malus - console.debug("RdDRollDialog","BM CLICKED !!!", rollData.bmValue, rollData.competence.data.niveau, parseInt(rollData.competence.data.niveau) + parseInt(rollData.bmValue) ); + console.debug("RdDRollDialog","BM CLICKED !!!", rollData); updateRollResult(rollData); }); html.find('#carac').click((event) => { let caracKey = event.currentTarget.value; rollData.selectedCarac = rollData.carac[caracKey]; // Update the selectedCarac - console.debug("RdDRollDialog","CARAC CLICKED !!!", rollData.selectedCarac, rollData.competence.data.niveau, rollData.bmValue); + console.debug("RdDRollDialog","CARAC CLICKED !!!", rollData); updateRollResult(rollData); }); html.find('#draconic').click((event) => { let draconicKey = event.currentTarget.value; rollData.selectedDraconic = rollData.draconicList[draconicKey]; // Update the selectedCarac - console.debug("RdDRollDialog","CARAC CLICKED !!!", rollData.selectedCarac, rollData.competence.data.niveau, rollData.bmValue); + console.debug("RdDRollDialog","CARAC CLICKED !!!", rollData); updateRollResult(rollData); }); html.find('#sort').click((event) => { let sortKey = event.currentTarget.value; rollData.selectedSort = rollData.sortList[sortKey]; // Update the selectedCarac - console.debug("RdDRollDialog","CARAC CLICKED !!!", rollData.selectedCarac, rollData.competence.data.niveau, rollData.bmValue); + console.debug("RdDRollDialog","CARAC CLICKED !!!", rollData); updateRollResult(rollData); });