From efdffd171c861c1ad05a422a21d041805e336b9d Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Mon, 13 Jan 2025 19:46:55 +0100 Subject: [PATCH] =?UTF-8?q?Support=20de=20difficult=C3=A9s=20al=C3=A9atoir?= =?UTF-8?q?es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Par exemple: `@roll[vue/vigil/-1d6]` pour "VUE / Vigilance à -1d6" --- .../apps/textroll/text-roll-carac-competence.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/module/apps/textroll/text-roll-carac-competence.js b/module/apps/textroll/text-roll-carac-competence.js index c7511696..6441a2a8 100644 --- a/module/apps/textroll/text-roll-carac-competence.js +++ b/module/apps/textroll/text-roll-carac-competence.js @@ -7,7 +7,8 @@ import { TextRollManager } from "./text-roll-formatter.js"; const REGECP_CARAC = "(?[A-Za-zÀ-ÖØ-öø-ÿ\\s\\-]+)" const REGEXP_COMP = "(\\/(?[A-Za-zÀ-ÖØ-öø-ÿ\\s\\-]+))?" -const REGEXP_DIFF = "(/(?[\\+\\-]?\\d+))?" +const REGEXP_DIFF = "(/(?[\\+\\-]?\\d+(d\\d+)?))?" +const REGEX_DICE_DIFF = /[\+\-]?\d+d\d+/; const REGEXP_ROLL_CARAC_COMP = REGECP_CARAC + REGEXP_COMP + REGEXP_DIFF const XREGEXP_ROLL_CARAC_COMP = XRegExp("@roll\\[" + REGEXP_ROLL_CARAC_COMP + "\\]", 'giu') @@ -29,12 +30,23 @@ export class TextRollCaracCompetence { const caracCode = node.data('carac-code') if (caracCode) { const competence = node.data('competence') - const diff = node.data('diff') + const diff = await this.calculDiff(node) const actors = this.getSelectedActors(actor) actors.forEach(async it => await this.doRoll(it, caracCode, competence, diff)) } } + async calculDiff(node) { + const diff = node.data('diff') ?? 0 + if (diff.match(REGEX_DICE_DIFF)) { + const roll = new Roll(diff) + await roll.evaluate() + await roll.toMessage({flavor: `La difficulté de ${diff} a donné ${roll.total}`}) + return roll.total + } + return diff + } + async doRoll(actor, caracCode, competence, diff) { caracCode = actor.mapCarac(caracCode) if (competence) {