From fd107db75753645c74221c24f7cdb993c09c8b4f Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Mon, 16 Nov 2020 03:54:43 +0100 Subject: [PATCH] =?UTF-8?q?#24=20Ajout=20du=20d=C3=A9=20draconique?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/rdd-dice.js | 44 +++++++++++++++++++++++++++ module/rdd-resolution-table.js | 55 +++++++++++++--------------------- 2 files changed, 65 insertions(+), 34 deletions(-) create mode 100644 module/rdd-dice.js diff --git a/module/rdd-dice.js b/module/rdd-dice.js new file mode 100644 index 00000000..f4557fbc --- /dev/null +++ b/module/rdd-dice.js @@ -0,0 +1,44 @@ +export class RdDDice { + static async deRencontre() { + let roll = this.show(new Roll("1d7").evaluate()); + // let roll = this.show(new Roll("1d8r8").evaluate()); + // roll.total = roll.total % 8; + return roll; + } + + static async deDraconique() { + let roll = new Roll("1d8x8").evaluate(); + await this.show(roll); + return roll.total - Math.ceil(roll.total / 8); + } + + static async show(roll, rollMode = "roll") { + await this.showDiceSoNice(roll, rollMode); + return roll; + } + + /* -------------------------------------------- */ + static async showDiceSoNice(roll, rollMode = "roll") { + if (game.modules.get("dice-so-nice") && game.modules.get("dice-so-nice").active) { + let whisper = null; + let blind = false; + switch (rollMode) { + case "blindroll": //GM only + blind = true; + case "gmroll": //GM + rolling player + let gmList = game.users.filter(user => user.isGM); + let gmIDList = []; + gmList.forEach(gm => gmIDList.push(gm.data._id)); + whisper = gmIDList; + break; + case "roll": //everybody + let userList = game.users.filter(user => user.active); + let userIDList = []; + userList.forEach(user => userIDList.push(user.data._id)); + whisper = userIDList; + break; + } + await game.dice3d.showForRoll(roll, game.user, true, whisper, blind); + } + } +} \ No newline at end of file diff --git a/module/rdd-resolution-table.js b/module/rdd-resolution-table.js index 52385881..8f2e0f4b 100644 --- a/module/rdd-resolution-table.js +++ b/module/rdd-resolution-table.js @@ -1,4 +1,5 @@ import { Misc } from "./misc.js"; +import { RdDDice } from "./rdd-dice.js"; /** * difficultés au delà de -10 @@ -67,52 +68,38 @@ export class RdDResolutionTable { } /* -------------------------------------------- */ - static getResultat(code) - { + static getResultat(code) { let resultat = reussites.filter(r => code == r.code); - if (resultat == undefined) - { + if (resultat == undefined) { resultat = reussites.find(r => r.code == "error"); } return resultat; } - /* -------------------------------------------- */ - static roll(carac, difficulte) { - const chances = this.computeChances(carac, difficulte); - let rolled = this.rollChances(chances); - return rolled; - } - - /* -------------------------------------------- */ - static async showDiceSoNice(roll, rollMode = "roll") { - if (game.modules.get("dice-so-nice") && game.modules.get("dice-so-nice").active) { - let whisper = null; - let blind = false; - switch (rollMode) { - case "blindroll": //GM only - blind = true; - case "gmroll": //GM + rolling player - let gmList = game.users.filter(user => user.isGM); - let gmIDList = []; - gmList.forEach(gm => gmIDList.push(gm.data._id)); - whisper = gmIDList; - break; - case "roll": //everybody - let userList = game.users.filter(user => user.active); - let userIDList = []; - userList.forEach(user => userIDList.push(user.data._id)); - whisper = userIDList; - break; - } - await game.dice3d.showForRoll(roll, game.user, true, whisper, blind); + static explain(rolled) { + let message = "
Jet : " + rolled.roll + " sur " + rolled.score + "%"; + if (rolled.carac != null && rolled.finalLevel!= null) { + message += " (" + rolled.carac + " à " + Misc.toSignedString(rolled.finalLevel) + ")"; } + return message; + + } + /* -------------------------------------------- */ + static async roll(carac, finalLevel, showDice=false) { + let chances = this.computeChances(carac, finalLevel); + chances.showDice = showDice; + let rolled = await this.rollChances(chances); + rolled.carac = carac; + rolled.finalLevel = finalLevel; + return rolled; } /* -------------------------------------------- */ static async rollChances(chances) { let myRoll = new Roll("d100").roll(); - await this.showDiceSoNice(myRoll ); + if (chances.showDice) { + await RdDDice.showDiceSoNice(myRoll); + } chances.roll = myRoll.total; mergeObject(chances, this._computeReussite(chances, chances.roll)); return chances;