forked from public/foundryvtt-reve-de-dragon
		
	Support de difficultés aléatoires
Par exemple: `@roll[vue/vigil/-1d6]` pour "VUE / Vigilance à -1d6"
This commit is contained in:
		| @@ -7,7 +7,8 @@ import { TextRollManager } from "./text-roll-formatter.js"; | ||||
|  | ||||
| const REGECP_CARAC = "(?<carac>[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 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) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user