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) {