Support de difficultés aléatoires
Par exemple: `@roll[vue/vigil/-1d6]` pour "VUE / Vigilance à -1d6"
This commit is contained in:
parent
8406c8434a
commit
efdffd171c
@ -7,7 +7,8 @@ import { TextRollManager } from "./text-roll-formatter.js";
|
|||||||
|
|
||||||
const REGECP_CARAC = "(?<carac>[A-Za-zÀ-ÖØ-öø-ÿ\\s\\-]+)"
|
const REGECP_CARAC = "(?<carac>[A-Za-zÀ-ÖØ-öø-ÿ\\s\\-]+)"
|
||||||
const REGEXP_COMP = "(\\/(?<competence>[A-Za-zÀ-ÖØ-öø-ÿ\\s\\-]+))?"
|
const REGEXP_COMP = "(\\/(?<competence>[A-Za-zÀ-ÖØ-öø-ÿ\\s\\-]+))?"
|
||||||
const REGEXP_DIFF = "(/(?<diff>[\\+\\-]?\\d+))?"
|
const REGEXP_DIFF = "(/(?<diff>[\\+\\-]?\\d+(d\\d+)?))?"
|
||||||
|
const REGEX_DICE_DIFF = /[\+\-]?\d+d\d+/;
|
||||||
const REGEXP_ROLL_CARAC_COMP = REGECP_CARAC + REGEXP_COMP + REGEXP_DIFF
|
const REGEXP_ROLL_CARAC_COMP = REGECP_CARAC + REGEXP_COMP + REGEXP_DIFF
|
||||||
const XREGEXP_ROLL_CARAC_COMP = XRegExp("@roll\\[" + REGEXP_ROLL_CARAC_COMP + "\\]", 'giu')
|
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')
|
const caracCode = node.data('carac-code')
|
||||||
if (caracCode) {
|
if (caracCode) {
|
||||||
const competence = node.data('competence')
|
const competence = node.data('competence')
|
||||||
const diff = node.data('diff')
|
const diff = await this.calculDiff(node)
|
||||||
const actors = this.getSelectedActors(actor)
|
const actors = this.getSelectedActors(actor)
|
||||||
actors.forEach(async it => await this.doRoll(it, caracCode, competence, diff))
|
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) {
|
async doRoll(actor, caracCode, competence, diff) {
|
||||||
caracCode = actor.mapCarac(caracCode)
|
caracCode = actor.mapCarac(caracCode)
|
||||||
if (competence) {
|
if (competence) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user