From a68aa29b5353831a05ca8eec8cd953787a3bb4fb Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Mon, 26 Apr 2021 23:45:43 +0200 Subject: [PATCH] Extraction calcul chances --- module/rdd-resolution-table.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/module/rdd-resolution-table.js b/module/rdd-resolution-table.js index e1b373d7..0917997e 100644 --- a/module/rdd-resolution-table.js +++ b/module/rdd-resolution-table.js @@ -165,7 +165,8 @@ export class RdDResolutionTable { if (difficulte < -10) { return duplicate(levelDown.find(levelData => levelData.level == difficulte)); } - return duplicate(RdDResolutionTable.resolutionTable[caracValue][difficulte + 10]); + const chances = RdDResolutionTable.resolutionTable[caracValue][difficulte + 10]; + return chances ? duplicate(chances) : RdDResolutionTable._computeCell(difficulte, RdDResolutionTable.computeChances(caracValue, difficulte)); } /* -------------------------------------------- */ @@ -224,16 +225,26 @@ export class RdDResolutionTable { /* -------------------------------------------- */ static _computeRow(caracValue) { - let dataRow = [ - this._computeCell(-10, Math.max(Math.floor(caracValue / 4), 1)), - this._computeCell(-9, Math.max(Math.floor(caracValue / 2), 1)) - ] - for (var diff = -8; diff <= 22; diff++) { - dataRow[diff + 10] = this._computeCell(diff, Math.max(Math.floor(caracValue * (diff + 10) / 2), 1)); + let dataRow = []; + for (var diff = -10; diff <= 22; diff++) { + dataRow[diff + 10] = this._computeCell(diff, RdDResolutionTable._computePercentage(caracValue, diff)); } return dataRow; } + static _computePercentage(caracValue, diff) { + if (diff <-10) { + return 1; + } + if (diff == -10){ + return Math.max(Math.floor(caracValue / 4), 1); + } + if (diff == -9) { + return Math.max(Math.floor(caracValue / 2), 1) + } + return Math.max(Math.floor(caracValue * (diff + 10) / 2), 1); + } + /* -------------------------------------------- */ static _computeCell(niveau, percentage) { return {