@dicelette/core 1.16.0 → 1.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +14 -5
- package/dist/index.d.ts +14 -5
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
@@ -92,7 +92,8 @@ type Statistic = Record<
|
|
92
92
|
* The name of the statistic
|
93
93
|
* @TJS-type string
|
94
94
|
*/
|
95
|
-
string,
|
95
|
+
string, StatEntry>;
|
96
|
+
type StatEntry = {
|
96
97
|
/**
|
97
98
|
* The value of the statistic that can take the stats
|
98
99
|
* @TJS-type integer
|
@@ -112,7 +113,7 @@ string, {
|
|
112
113
|
* Allow to exclude from roll selection in /dbroll!
|
113
114
|
*/
|
114
115
|
exclude?: boolean;
|
115
|
-
}
|
116
|
+
};
|
116
117
|
/**
|
117
118
|
* @example
|
118
119
|
* diceType: 1d20+$>=20
|
@@ -136,6 +137,10 @@ interface StatisticalTemplate {
|
|
136
137
|
* @TJS-type integer
|
137
138
|
*/
|
138
139
|
total?: number;
|
140
|
+
/**
|
141
|
+
* Force the distribition of all the points
|
142
|
+
*/
|
143
|
+
forceDistrib?: boolean;
|
139
144
|
/** A dice type in the notation supported by the bot */
|
140
145
|
diceType?: string;
|
141
146
|
/**
|
@@ -146,12 +151,13 @@ interface StatisticalTemplate {
|
|
146
151
|
* Custom critical, allow to adjust the critical on a statistic, and set multiple critical value
|
147
152
|
* @maximum 22
|
148
153
|
*/
|
149
|
-
customCritical?:
|
154
|
+
customCritical?: CustomCriticalMap;
|
150
155
|
/** Special dice for damage
|
151
156
|
* @maximum 25
|
152
157
|
* */
|
153
158
|
damage?: Record<string, string>;
|
154
159
|
}
|
160
|
+
type CustomCriticalMap = Record<string, CustomCritical>;
|
155
161
|
/**
|
156
162
|
* If the result can be considered as a critical
|
157
163
|
* Critical is compared to the "natural" dice result, so any modifier doesn't count
|
@@ -369,7 +375,8 @@ declare const templateSchema: z.ZodObject<{
|
|
369
375
|
combinaison?: string | undefined;
|
370
376
|
exclude?: boolean | undefined;
|
371
377
|
}> | undefined>;
|
372
|
-
total: z.ZodOptional<z.ZodNumber
|
378
|
+
total: z.ZodOptional<z.ZodEffects<z.ZodNumber, number | undefined, number>>;
|
379
|
+
forceDistrib: z.ZodOptional<z.ZodBoolean>;
|
373
380
|
diceType: z.ZodOptional<z.ZodString>;
|
374
381
|
critical: z.ZodOptional<z.ZodEffects<z.ZodObject<{
|
375
382
|
success: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
@@ -423,6 +430,7 @@ declare const templateSchema: z.ZodObject<{
|
|
423
430
|
combinaison?: string | undefined;
|
424
431
|
exclude?: boolean | undefined;
|
425
432
|
}> | undefined;
|
433
|
+
forceDistrib?: boolean | undefined;
|
426
434
|
diceType?: string | undefined;
|
427
435
|
critical?: {
|
428
436
|
success?: string | number | undefined;
|
@@ -444,6 +452,7 @@ declare const templateSchema: z.ZodObject<{
|
|
444
452
|
combinaison?: string | undefined;
|
445
453
|
exclude?: boolean | undefined;
|
446
454
|
}> | undefined;
|
455
|
+
forceDistrib?: boolean | undefined;
|
447
456
|
diceType?: string | undefined;
|
448
457
|
critical?: {
|
449
458
|
success?: string | number | undefined;
|
@@ -466,4 +475,4 @@ interface StatisticalSchema extends StatisticalTemplate {
|
|
466
475
|
$schema?: string;
|
467
476
|
}
|
468
477
|
|
469
|
-
export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, DiceTypeError, EmptyObjectError, FormulaError, MaxGreater, type Modifier, NoStatisticsError, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, calculator, createCriticalCustom, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, generateRandomStat, generateStatsDice, isNumber, replaceExpByRandom, replaceFormulaInDice, roll, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyTemplateValue };
|
478
|
+
export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DiceTypeError, EmptyObjectError, FormulaError, MaxGreater, type Modifier, NoStatisticsError, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, calculator, createCriticalCustom, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, generateRandomStat, generateStatsDice, isNumber, replaceExpByRandom, replaceFormulaInDice, roll, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyTemplateValue };
|
package/dist/index.d.ts
CHANGED
@@ -92,7 +92,8 @@ type Statistic = Record<
|
|
92
92
|
* The name of the statistic
|
93
93
|
* @TJS-type string
|
94
94
|
*/
|
95
|
-
string,
|
95
|
+
string, StatEntry>;
|
96
|
+
type StatEntry = {
|
96
97
|
/**
|
97
98
|
* The value of the statistic that can take the stats
|
98
99
|
* @TJS-type integer
|
@@ -112,7 +113,7 @@ string, {
|
|
112
113
|
* Allow to exclude from roll selection in /dbroll!
|
113
114
|
*/
|
114
115
|
exclude?: boolean;
|
115
|
-
}
|
116
|
+
};
|
116
117
|
/**
|
117
118
|
* @example
|
118
119
|
* diceType: 1d20+$>=20
|
@@ -136,6 +137,10 @@ interface StatisticalTemplate {
|
|
136
137
|
* @TJS-type integer
|
137
138
|
*/
|
138
139
|
total?: number;
|
140
|
+
/**
|
141
|
+
* Force the distribition of all the points
|
142
|
+
*/
|
143
|
+
forceDistrib?: boolean;
|
139
144
|
/** A dice type in the notation supported by the bot */
|
140
145
|
diceType?: string;
|
141
146
|
/**
|
@@ -146,12 +151,13 @@ interface StatisticalTemplate {
|
|
146
151
|
* Custom critical, allow to adjust the critical on a statistic, and set multiple critical value
|
147
152
|
* @maximum 22
|
148
153
|
*/
|
149
|
-
customCritical?:
|
154
|
+
customCritical?: CustomCriticalMap;
|
150
155
|
/** Special dice for damage
|
151
156
|
* @maximum 25
|
152
157
|
* */
|
153
158
|
damage?: Record<string, string>;
|
154
159
|
}
|
160
|
+
type CustomCriticalMap = Record<string, CustomCritical>;
|
155
161
|
/**
|
156
162
|
* If the result can be considered as a critical
|
157
163
|
* Critical is compared to the "natural" dice result, so any modifier doesn't count
|
@@ -369,7 +375,8 @@ declare const templateSchema: z.ZodObject<{
|
|
369
375
|
combinaison?: string | undefined;
|
370
376
|
exclude?: boolean | undefined;
|
371
377
|
}> | undefined>;
|
372
|
-
total: z.ZodOptional<z.ZodNumber
|
378
|
+
total: z.ZodOptional<z.ZodEffects<z.ZodNumber, number | undefined, number>>;
|
379
|
+
forceDistrib: z.ZodOptional<z.ZodBoolean>;
|
373
380
|
diceType: z.ZodOptional<z.ZodString>;
|
374
381
|
critical: z.ZodOptional<z.ZodEffects<z.ZodObject<{
|
375
382
|
success: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
@@ -423,6 +430,7 @@ declare const templateSchema: z.ZodObject<{
|
|
423
430
|
combinaison?: string | undefined;
|
424
431
|
exclude?: boolean | undefined;
|
425
432
|
}> | undefined;
|
433
|
+
forceDistrib?: boolean | undefined;
|
426
434
|
diceType?: string | undefined;
|
427
435
|
critical?: {
|
428
436
|
success?: string | number | undefined;
|
@@ -444,6 +452,7 @@ declare const templateSchema: z.ZodObject<{
|
|
444
452
|
combinaison?: string | undefined;
|
445
453
|
exclude?: boolean | undefined;
|
446
454
|
}> | undefined;
|
455
|
+
forceDistrib?: boolean | undefined;
|
447
456
|
diceType?: string | undefined;
|
448
457
|
critical?: {
|
449
458
|
success?: string | number | undefined;
|
@@ -466,4 +475,4 @@ interface StatisticalSchema extends StatisticalTemplate {
|
|
466
475
|
$schema?: string;
|
467
476
|
}
|
468
477
|
|
469
|
-
export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, DiceTypeError, EmptyObjectError, FormulaError, MaxGreater, type Modifier, NoStatisticsError, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, calculator, createCriticalCustom, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, generateRandomStat, generateStatsDice, isNumber, replaceExpByRandom, replaceFormulaInDice, roll, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyTemplateValue };
|
478
|
+
export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DiceTypeError, EmptyObjectError, FormulaError, MaxGreater, type Modifier, NoStatisticsError, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, calculator, createCriticalCustom, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, generateRandomStat, generateStatsDice, isNumber, replaceExpByRandom, replaceFormulaInDice, roll, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyTemplateValue };
|
package/dist/index.js
CHANGED
@@ -508,7 +508,8 @@ function verifyTemplateValue(template, verify = true) {
|
|
508
508
|
total: parsedTemplate.total,
|
509
509
|
charName: parsedTemplate.charName,
|
510
510
|
damage: parsedTemplate.damage,
|
511
|
-
customCritical: parsedTemplate.customCritical
|
511
|
+
customCritical: parsedTemplate.customCritical,
|
512
|
+
forceDistrib: parsedTemplate.forceDistrib
|
512
513
|
};
|
513
514
|
if (!verify) return statistiqueTemplate;
|
514
515
|
if (statistiqueTemplate.diceType) {
|
@@ -720,7 +721,8 @@ var customCriticalSchema = import_zod.z.record(criticalValueSchema).optional().r
|
|
720
721
|
var templateSchema = import_zod.z.object({
|
721
722
|
charName: import_zod.z.boolean().optional(),
|
722
723
|
statistics: statisticSchema,
|
723
|
-
total: import_zod.z.number().min(0).optional(),
|
724
|
+
total: import_zod.z.number().min(0).transform((val) => val === 0 ? void 0 : val).optional(),
|
725
|
+
forceDistrib: import_zod.z.boolean().optional(),
|
724
726
|
diceType: import_zod.z.string().optional(),
|
725
727
|
critical: criticalSchema.optional(),
|
726
728
|
customCritical: customCriticalSchema,
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/dice.ts","../src/utils.ts","../src/verify_template.ts","../src/errors.ts","../src/interfaces/constant.ts","../src/interfaces/zod.ts"],"sourcesContent":["export * from \"./dice\";\r\nexport * from \"./interfaces\";\r\nexport * from \"./utils\";\r\nexport * from \"./verify_template\";\r\nexport * from \"./errors\";\r\nexport * from \"./interfaces/constant\";\r\nexport * from \"./interfaces/zod\";\r\nexport * from \"./interfaces/toJsonSchema\";\r\n","import { DiceRoller } from \"@dice-roller/rpg-dice-roller\";\r\nimport { evaluate } from \"mathjs\";\r\n\r\nimport {\r\n\ttype Compare,\r\n\ttype ComparedValue,\r\n\ttype CustomCritical,\r\n\ttype Modifier,\r\n\ttype Resultat,\r\n\ttype Sign,\r\n\ttype StatisticalTemplate,\r\n\tdiceTypeRandomParse,\r\n\tstandardizeDice,\r\n\tDiceTypeError,\r\n\tCOMMENT_REGEX,\r\n\tSIGN_REGEX,\r\n\tSIGN_REGEX_SPACE,\r\n\tSYMBOL_DICE,\r\n} from \".\";\r\nimport { isNumber } from \"./utils\";\r\n\r\nfunction getCompare(\r\n\tdice: string,\r\n\tcompareRegex: RegExpMatchArray\r\n): { dice: string; compare: ComparedValue | undefined } {\r\n\t/**\r\n\t * @source: https://dice-roller.github.io/documentation/guide/notation/modifiers.html#target-success-dice-pool\r\n\t * Some system count the number of a dice that are greater than or equal to a target, and not the \"total\" of rolled dice.\r\n\t * We \"count\" the number of dice that meet a criterion, and not the total of the dice.\r\n\t * To support this, we use the group notation. It a little different than the notation of dice-roller, but it a sacrifice to not break the current notation.\r\n\t * @note:\r\n\t * - `{2d3}>=4` will be the same as `2d3>=4` and thus keep the comparaison.\r\n\t * - `{2d3>=4}` will count the total of dice that are greater than or equal to 4, and not the total of the dice.\r\n\t * - `{2d3,1d4}>=4` won't use the comparison, but will count the number of dice that are greater than or equal to 4. If the total of the dice is needed, just remove the group notation and use `2d3+1d4>=4`.\r\n\t */\r\n\tif (dice.match(/((\\{.*,(.*)+\\}|([><=!]+\\d+f))[><=!]+\\d+\\}?)|\\{(.*)([><=!]+).*\\}/)) return { dice, compare: undefined };\r\n\tdice = dice.replace(SIGN_REGEX_SPACE, \"\");\r\n\tlet compare: ComparedValue;\r\n\tconst calc = compareRegex[1];\r\n\tconst sign = calc.match(/[+-\\/*^]/)?.[0];\r\n\tconst compareSign = compareRegex[0].match(SIGN_REGEX)?.[0];\r\n\t\r\n\t\r\n\tif (sign) {\r\n\t\tconst toCalc = calc.replace(SIGN_REGEX, \"\").replace(/\\s/g, \"\").replace(/;(.*)/, \"\");\r\n\t\tconst rCompare = rollCompare(toCalc);\r\n\t\tconst total = evaluate(rCompare.value.toString());\r\n\t\tdice = dice.replace(SIGN_REGEX_SPACE, `${compareSign}${total}`);\r\n\t\tcompare = {\r\n\t\t\tsign: compareSign as \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\",\r\n\t\t\tvalue: total,\r\n\t\t\toriginalDice: rCompare.dice,\r\n\t\t\trollValue: rCompare.diceResult,\r\n\t\t};\r\n\t} else {\r\n\t\tconst rcompare = rollCompare(calc);\r\n\t\tcompare = {\r\n\t\t\tsign: compareSign as \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\",\r\n\t\t\tvalue: rcompare.value,\r\n\t\t\toriginalDice: rcompare.dice,\r\n\t\t\trollValue: rcompare.diceResult,\r\n\t\t};\r\n\t}\r\n\treturn { dice, compare };\r\n}\r\n\r\nfunction rollCompare(value: unknown) {\r\n\tif (isNumber(value)) return { value: Number.parseInt(value as string, 10) };\r\n\tconst rollComp = roll(value as string);\r\n\tif (!rollComp?.total)\r\n\t\t//not a dice throw\r\n\t\treturn { value: evaluate(value as string), diceResult: value as string };\r\n\treturn {\r\n\t\tdice: value as string,\r\n\t\tvalue: rollComp.total,\r\n\t\tdiceResult: rollComp?.result,\r\n\t};\r\n}\r\n\r\n/**\r\n * Allow to replace the compare part of a dice and use the critical customized one\r\n * @example\r\n * dice = \"1d20=20\";\r\n * custom critical {sign: \">\", value: \"$/2\"}\r\n * Random stats = 6\r\n * result = \"1d20>3\"\r\n */\r\nexport function createCriticalCustom(\r\n\tdice: string,\r\n\tcustomCritical: CustomCritical,\r\n\ttemplate: StatisticalTemplate\r\n) {\r\n\tconst compareRegex = dice.match(SIGN_REGEX_SPACE);\r\n\tlet customDice = dice;\r\n\tconst compareValue = diceTypeRandomParse(customCritical.value, template);\r\n\tif (compareValue.includes(\"$\"))\r\n\t\tthrow new DiceTypeError(compareValue, \"createCriticalCustom\");\r\n\tconst comparaison = `${customCritical.sign}${compareValue}`;\r\n\tif (compareRegex) customDice = customDice.replace(SIGN_REGEX_SPACE, comparaison);\r\n\telse customDice += comparaison;\r\n\treturn diceTypeRandomParse(customDice, template);\r\n}\r\n\r\nfunction getModifier(dice: string) {\r\n\tconst modifier = dice.matchAll(/(\\+|-|%|\\/|\\^|\\*|\\*{2})(\\d+)/gi);\r\n\tlet modificator: Modifier | undefined;\r\n\tfor (const mod of modifier) {\r\n\t\t//calculate the modifier if multiple\r\n\t\tif (modificator) {\r\n\t\t\tconst sign = modificator.sign;\r\n\t\t\tlet value = modificator.value;\r\n\t\t\tif (sign) value = calculator(sign, value, Number.parseInt(mod[2], 10));\r\n\t\t\tmodificator = {\r\n\t\t\t\tsign: mod[1] as Sign,\r\n\t\t\t\tvalue,\r\n\t\t\t};\r\n\t\t} else {\r\n\t\t\tmodificator = {\r\n\t\t\t\tsign: mod[1] as Sign,\r\n\t\t\t\tvalue: Number.parseInt(mod[2], 10),\r\n\t\t\t};\r\n\t\t}\r\n\t}\r\n\treturn modificator;\r\n}\r\n\r\n/**\r\n * Parse the string provided and turn it as a readable dice for dice parser\r\n * @param dice {string}\r\n */\r\nexport function roll(dice: string): Resultat | undefined {\r\n\t//parse dice string\r\n\tdice = standardizeDice(dice).replace(/^\\+/, \"\").trimStart();\r\n\tif (!dice.includes(\"d\")) return undefined;\r\n\tconst compareRegex = dice.match(SIGN_REGEX_SPACE);\r\n\tlet compare: ComparedValue | undefined;\r\n\tif (dice.includes(\";\")) return sharedRolls(dice);\r\n\tif (compareRegex) {\r\n\t\tconst compareResult = getCompare(dice, compareRegex);\r\n\t\tdice = compareResult.dice;\r\n\t\tcompare = compareResult.compare;\r\n\t}\r\n\tconst modificator = getModifier(dice);\r\n\r\n\tif (dice.match(/\\d+?#(.*)/)) {\r\n\t\tconst diceArray = dice.split(\"#\");\r\n\t\tconst numberOfDice = Number.parseInt(diceArray[0], 10);\r\n\t\tconst diceToRoll = diceArray[1].replace(COMMENT_REGEX, \"\");\r\n\t\tconst commentsMatch = diceArray[1].match(COMMENT_REGEX);\r\n\t\tconst comments = commentsMatch ? commentsMatch[2] : undefined;\r\n\t\tconst roller = new DiceRoller();\r\n\t\t//remove comments if any\r\n\t\tfor (let i = 0; i < numberOfDice; i++) {\r\n\t\t\ttry {\r\n\t\t\t\troller.roll(diceToRoll);\r\n\t\t\t} catch (error) {\r\n\t\t\t\tthrow new DiceTypeError(diceToRoll, \"roll\", error);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn {\r\n\t\t\tdice: diceToRoll,\r\n\t\t\tresult: roller.output,\r\n\t\t\tcomment: comments,\r\n\t\t\tcompare: compare ? compare : undefined,\r\n\t\t\tmodifier: modificator,\r\n\t\t\ttotal: roller.total,\r\n\t\t};\r\n\t}\r\n\tconst roller = new DiceRoller();\r\n\tconst diceWithoutComment = dice.replace(COMMENT_REGEX, \"\").trimEnd();\r\n\ttry {\r\n\t\troller.roll(diceWithoutComment);\r\n\t} catch (error) {\r\n\t\tthrow new DiceTypeError(diceWithoutComment, \"roll\", error);\r\n\t}\r\n\tconst commentMatch = dice.match(COMMENT_REGEX);\r\n\tconst comment = commentMatch ? commentMatch[2] : undefined;\r\n\treturn {\r\n\t\tdice,\r\n\t\tresult: roller.output,\r\n\t\tcomment,\r\n\t\tcompare: compare ? compare : undefined,\r\n\t\tmodifier: modificator,\r\n\t\ttotal: roller.total,\r\n\t};\r\n}\r\n/**\r\n * Evaluate a formula and replace \"^\" by \"**\" if any\r\n * @param {Sign} sign\r\n * @param {number} value\r\n * @param {number} total\r\n * @returns\r\n */\r\nexport function calculator(sign: Sign, value: number, total: number): number {\r\n\tif (sign === \"^\") sign = \"**\";\r\n\treturn evaluate(`${total} ${sign} ${value}`);\r\n}\r\n\r\nfunction inverseSign(\r\n\tsign: \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\"\r\n): \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\" {\r\n\tswitch (sign) {\r\n\t\tcase \"<\":\r\n\t\t\treturn \">\";\r\n\t\tcase \">\":\r\n\t\t\treturn \"<\";\r\n\t\tcase \"<=\":\r\n\t\t\treturn \">=\";\r\n\t\tcase \">=\":\r\n\t\t\treturn \"<=\";\r\n\t\tcase \"=\":\r\n\t\t\treturn \"!=\";\r\n\t\tcase \"==\":\r\n\t\t\treturn \"!=\";\r\n\t\tcase \"!=\":\r\n\t\t\treturn \"==\";\r\n\t}\r\n}\r\n\r\nfunction replaceInFormula(\r\n\telement: string,\r\n\tdiceResult: Resultat,\r\n\tcompareResult: { dice: string; compare: Compare | undefined },\r\n\tres: boolean\r\n) {\r\n\tconst { formule, diceAll } = replaceText(\r\n\t\telement,\r\n\t\tdiceResult.total ?? 0,\r\n\t\tdiceResult.dice\r\n\t);\r\n\tconst validSign = res ? \"✓\" : \"✕\";\r\n\tconst invertedSign = res\r\n\t\t? compareResult.compare!.sign\r\n\t\t: inverseSign(compareResult.compare!.sign);\r\n\tlet evaluateRoll: unknown;\r\n\ttry {\r\n\t\tevaluateRoll = evaluate(compareResult.dice);\r\n\t\treturn `${validSign} ${diceAll}: ${formule} = ${evaluateRoll}${invertedSign}${compareResult.compare?.value}`;\r\n\t} catch (error) {\r\n\t\tconst evaluateRoll = roll(compareResult.dice) as Resultat | undefined;\r\n\t\tif (evaluateRoll)\r\n\t\t\treturn `${validSign} ${diceAll}: ${evaluateRoll.result.split(\":\").splice(1).join(\":\")}`;\r\n\r\n\t\treturn `${validSign} ${diceAll}: ${formule} = ${evaluateRoll}${invertedSign}${compareResult.compare?.value}`;\r\n\t}\r\n}\r\n\r\nfunction compareSignFormule(\r\n\ttoRoll: string,\r\n\tcompareRegex: RegExpMatchArray,\r\n\telement: string,\r\n\tdiceResult: Resultat\r\n) {\r\n\tlet results = \"\";\r\n\tconst compareResult = getCompare(toRoll, compareRegex);\r\n\tconst toCompare = `${compareResult.dice}${compareResult.compare?.sign}${compareResult.compare?.value}`;\r\n\tlet res: unknown;\r\n\ttry {\r\n\t\tres = evaluate(toCompare);\r\n\t} catch (error) {\r\n\t\tres = roll(toCompare);\r\n\t}\r\n\tif (typeof res === \"boolean\") {\r\n\t\tresults = replaceInFormula(element, diceResult, compareResult, res);\r\n\t} else if (res instanceof Object) {\r\n\t\tconst diceResult = res as Resultat;\r\n\t\tif (diceResult.compare) {\r\n\t\t\tconst toEvaluate = evaluate(\r\n\t\t\t\t`${diceResult.total}${diceResult.compare.sign}${diceResult.compare.value}`\r\n\t\t\t);\r\n\t\t\tconst sign = toEvaluate ? \"✓\" : \"✕\";\r\n\t\t\tconst invertedSign = toEvaluate\r\n\t\t\t\t? diceResult.compare.sign\r\n\t\t\t\t: inverseSign(diceResult.compare.sign);\r\n\t\t\tconst dice = replaceText(element, 0, diceResult.dice).diceAll;\r\n\r\n\t\t\tresults = `${sign} ${dice}: ${diceResult.result.split(\":\").splice(1).join(\":\").trim()}${invertedSign}${diceResult.compare.value}`;\r\n\t\t}\r\n\t}\r\n\treturn { dice: compareResult.dice, results };\r\n}\r\n\r\nfunction replaceText(element: string, total: number, dice: string) {\r\n\treturn {\r\n\t\tformule: element.replace(SYMBOL_DICE, `[${total}]`).replace(/%.*%/g, \"\").trim(),\r\n\t\tdiceAll: element\r\n\t\t\t.replace(SYMBOL_DICE, `[${dice.replace(COMMENT_REGEX, \"\")}]`)\r\n\t\t\t.replace(/%.*%/g, \"\")\r\n\t\t\t.trim(),\r\n\t};\r\n}\r\n\r\nfunction formatComment(dice: string) {\r\n\tconst commentsRegex = /\\[(?<comments>.*?)\\]/;\r\n\tconst commentsMatch = commentsRegex.exec(dice);\r\n\treturn commentsMatch?.groups?.comments ? `__${commentsMatch.groups.comments}__ — ` : \"\";\r\n}\r\n\r\nfunction sharedRolls(dice: string): Resultat | undefined {\r\n\tif (dice.match(/\\d+?#(.*?)/))\r\n\t\tthrow new DiceTypeError(\r\n\t\t\tdice,\r\n\t\t\t\"noBulkRoll\",\r\n\t\t\t\"bulk roll are not allowed in shared rolls\"\r\n\t\t);\r\n\tconst results = [];\r\n\tconst mainComment =\r\n\t\t/\\s+#(?<comment>.*)/.exec(dice)?.groups?.comment?.trimEnd() ?? undefined;\r\n\tconst split = dice.split(\";\");\r\n\tlet diceMain = split[0];\r\n\tconst toHideRegex = /(?<!\\[[^\\]]*)\\((?<dice>[^)]+)\\)/;\r\n\tconst toHide = toHideRegex.exec(diceMain)?.groups;\r\n\tlet hidden = false;\r\n\tif (toHide?.dice) {\r\n\t\tdiceMain = toHide.dice;\r\n\t\thidden = true;\r\n\t} else if (toHide) {\r\n\t\tdiceMain = \"1d1\";\r\n\t\thidden = true;\r\n\t}\r\n\tconst commentsRegex = /\\[(?<comments>.*?)\\]/gi;\r\n\tconst comments = formatComment(diceMain);\r\n\tdiceMain = diceMain.replaceAll(commentsRegex, \"\").trim();\r\n\tconst diceResult = roll(diceMain);\r\n\tif (!diceResult || !diceResult.total) return undefined;\r\n\tresults.push(`※ ${comments}${diceResult.result}`);\r\n\tlet total = diceResult.total;\r\n\tdiceResult.comment = mainComment;\r\n\tif (!total) return diceResult;\r\n\tfor (let element of split.slice(1)) {\r\n\t\tconst comment = formatComment(element);\r\n\t\telement = element.replace(commentsRegex, \"\").trim();\r\n\t\tlet toRoll = element.replace(SYMBOL_DICE, `${diceResult.total}`);\r\n\t\tconst compareRegex = toRoll.match(SIGN_REGEX_SPACE);\r\n\t\tif (compareRegex) {\r\n\t\t\tconst compareResult = compareSignFormule(toRoll, compareRegex, element, diceResult);\r\n\t\t\ttoRoll = compareResult.dice;\r\n\t\t\tresults.push(compareResult.results);\r\n\t\t} else {\r\n\t\t\tconst { formule, diceAll } = replaceText(\r\n\t\t\t\telement,\r\n\t\t\t\tdiceResult.total,\r\n\t\t\t\tdiceResult.dice\r\n\t\t\t);\r\n\r\n\t\t\ttry {\r\n\t\t\t\tconst evaluated = evaluate(toRoll);\r\n\t\t\t\tresults.push(`◈ ${comment}${diceAll}: ${formule} = ${evaluated}`);\r\n\t\t\t\ttotal += Number.parseInt(evaluated, 10);\r\n\t\t\t} catch (error) {\r\n\t\t\t\tconst evaluated = roll(toRoll);\r\n\t\t\t\tif (evaluated)\r\n\t\t\t\t\tresults.push(\r\n\t\t\t\t\t\t`◈ ${comment}${diceAll}: ${evaluated.result.split(\":\").slice(1).join(\":\")}`\r\n\t\t\t\t\t);\r\n\t\t\t\telse results.push(`◈ ${comment}${diceAll}: ${formule} = ${evaluated}`);\r\n\t\t\t\ttotal += evaluated?.total ?? 0;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tif (hidden)\r\n\t\t//remove the first in result\r\n\t\tresults.shift();\r\n\treturn {\r\n\t\tdice: diceMain,\r\n\t\tresult: results.join(\";\"),\r\n\t\tcomment: mainComment,\r\n\t\tcompare: diceResult.compare,\r\n\t\tmodifier: diceResult.modifier,\r\n\t\ttotal,\r\n\t};\r\n}\r\n","import {evaluate, randomInt} from \"mathjs\";\r\nimport \"uniformize\";\r\nimport { FormulaError } from \".\";\r\n\r\n/**\r\n * Escape regex string\r\n * @param string {string}\r\n */\r\nexport function escapeRegex(string: string) {\r\n\treturn string.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\r\n}\r\n\r\n/**\r\n * Allow to keep the text as if in brackets\r\n * @param dice {string}\r\n * @return {string} the dice with the text in brackets as if, but the dice (not in brackets) is standardized\r\n */\r\nexport function standardizeDice(dice: string): string {\r\n\treturn dice.replace(\r\n\t\t/(\\[[^\\]]+\\])|([^[]+)/g,\r\n\t\t(match, insideBrackets, outsideText) =>\r\n\t\t\tinsideBrackets ? insideBrackets : outsideText.standardize(),\r\n\t);\r\n}\r\n\r\n/**\r\n * Replace the stat name by their value using stat\r\n * and after evaluate any formula using `replaceFormulaInDice`\r\n * @param {string} originalDice\r\n * @param {Record<string,number>|undefined} stats\r\n * @param {string|undefined} dollarValue\r\n */\r\nexport function generateStatsDice(\r\n\toriginalDice: string,\r\n\tstats?: Record<string, number>,\r\n\tdollarValue?: string,\r\n) {\r\n\tlet dice = originalDice.standardize();\r\n\tif (stats && Object.keys(stats).length > 0) {\r\n\t\t//damage field support adding statistic, like : 1d6 + strength\r\n\t\t//check if the value contains a statistic & calculate if it's okay\r\n\t\t//the dice will be converted before roll\r\n\t\tconst allStats = Object.keys(stats);\r\n\t\tfor (const stat of allStats) {\r\n\t\t\tconst regex = new RegExp(\r\n\t\t\t\t`(?!\\\\[)${escapeRegex(stat.standardize())}(?!\\\\])`,\r\n\t\t\t\t\"gi\",\r\n\t\t\t);\r\n\t\t\tif (dice.match(regex)) {\r\n\t\t\t\tconst statValue = stats[stat];\r\n\t\t\t\tdice = dice.replace(regex, statValue.toString());\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tif (dollarValue) dice = dice.replaceAll(\"$\", dollarValue);\r\n\treturn replaceFormulaInDice(dice);\r\n}\r\n\r\n/**\r\n * Replace the {{}} in the dice string and evaluate the interior if any\r\n * @param dice {string}\r\n */\r\nexport function replaceFormulaInDice(dice: string) {\r\n\tconst formula = /(?<formula>\\{{2}(.+?)}{2})/gim;\r\n\tlet match;\r\n\tlet modifiedDice = dice;\r\n\t// biome-ignore lint/suspicious/noAssignInExpressions: best way to regex in a loop\r\n\twhile ((match = formula.exec(dice)) !== null) {\r\n\t\tif (match.groups?.formula) {\r\n\t\t\tconst formulae = match.groups.formula\r\n\t\t\t\t.replaceAll(\"{{\", \"\")\r\n\t\t\t\t.replaceAll(\"}}\", \"\");\r\n\t\t\ttry {\r\n\t\t\t\tconst result = evaluate(formulae);\r\n\t\t\t\tmodifiedDice = modifiedDice.replace(\r\n\t\t\t\t\tmatch.groups.formula,\r\n\t\t\t\t\tresult.toString(),\r\n\t\t\t\t);\r\n\t\t\t} catch (error) {\r\n\t\t\t\tthrow new FormulaError(\r\n\t\t\t\t\tmatch.groups.formula,\r\n\t\t\t\t\t\"replaceFormulasInDice\",\r\n\t\t\t\t\terror,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn cleanedDice(modifiedDice);\r\n}\r\n\r\n/**\r\n * Replace the ++ +- -- by their proper value:\r\n * - `++` = `+`\r\n * - `+-` = `-`\r\n * - `--` = `+`\r\n * @param dice {string}\r\n */\r\nfunction cleanedDice(dice: string) {\r\n\treturn dice\r\n\t\t.replaceAll(\"+-\", \"-\")\r\n\t\t.replaceAll(\"--\", \"+\")\r\n\t\t.replaceAll(\"++\", \"+\")\r\n\t\t.trimEnd();\r\n}\r\n\r\n/**\r\n * Verify if a value is a number, even if it's a \"number\" string\r\n * @param value {unknown}\r\n * @returns {boolean}\r\n */\r\nexport function isNumber(value: unknown): boolean {\r\n\treturn (\r\n\t\tvalue !== undefined &&\r\n\t\t(typeof value === \"number\" ||\r\n\t\t\t(!Number.isNaN(Number(value)) &&\r\n\t\t\t\ttypeof value === \"string\" &&\r\n\t\t\t\tvalue.trim().length > 0))\r\n\t);\r\n}\r\n\r\n/**\r\n * Replace the `{exp}` in the dice.\r\n * If the `{exp}` has a default value in the form of `{exp || defaultValue}`, it will be replaced by the default value.\r\n * @param {string} dice\r\n * @returns {string} the dice with the {exp} replaced by a random value\r\n */\r\nexport function replaceExpByRandom(dice: string): string {\r\n\tconst diceRegex = /\\{exp( ?\\|\\| ?(?<default>\\d+))?}/gi\r\n\treturn dice.replace(diceRegex, (_match, _p1, _p2, _offset, _string, groups) => {\r\n\t\tconst defaultValue = groups?.default;\r\n\t\treturn defaultValue ?? randomInt(1, 999).toString();\r\n\t});\r\n}","import {evaluate, random, randomInt} from \"mathjs\";\r\nimport { Random } from \"random-js\";\r\nimport \"uniformize\";\r\n\r\nimport {\r\n\ttype StatisticalTemplate,\r\n\tcreateCriticalCustom,\r\n\troll,\r\n\tDiceTypeError,\r\n\tEmptyObjectError,\r\n\tFormulaError,\r\n\tNoStatisticsError,\r\n\tescapeRegex,\r\n\treplaceFormulaInDice,\r\n\ttemplateSchema,\r\n\tTooManyDice, replaceExpByRandom,\r\n} from \".\";\r\nimport { isNumber } from \"./utils\";\r\n\r\n/**\r\n * Verify if the provided dice work with random value\r\n * @param testDice {string}\r\n * @param allStats {Record<string,number>}\r\n */\r\nexport function evalStatsDice(testDice: string, allStats?: Record<string, number>) {\r\n\tlet dice = testDice.trimEnd();\r\n\tif (allStats && Object.keys(allStats).length > 0) {\r\n\t\tconst names = Object.keys(allStats);\r\n\t\tfor (const name of names) {\r\n\t\t\tconst regex = new RegExp(escapeRegex(name.standardize()), \"gi\");\r\n\t\t\tif (dice.standardize().match(regex)) {\r\n\t\t\t\tconst statValue = allStats[name];\r\n\t\t\t\tdice = dice.standardize().replace(regex, statValue.toString()).trimEnd();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\ttry {\r\n\t\tif (!roll(replaceFormulaInDice(replaceExpByRandom(dice))))\r\n\t\t\tthrow new DiceTypeError(dice, \"evalStatsDice\", \"no roll result\");\r\n\t\treturn testDice;\r\n\t} catch (error) {\r\n\t\tthrow new DiceTypeError(dice, \"evalStatsDice\", error);\r\n\t}\r\n}\r\n\r\n/**\r\n * Generate a random dice and remove the formula (+ evaluate it)\r\n * Used for diceDamage only\r\n * @param value {string}\r\n * @param template {StatisticalTemplate}\r\n * @returns\r\n */\r\nexport function diceRandomParse(value: string, template: StatisticalTemplate) {\r\n\tif (!template.statistics) return replaceFormulaInDice(value.standardize());\r\n\tvalue = value.standardize();\r\n\tconst statNames = Object.keys(template.statistics);\r\n\tlet newDice = value;\r\n\tfor (const name of statNames) {\r\n\t\tconst regex = new RegExp(escapeRegex(name.standardize()), \"gi\");\r\n\t\tif (value.match(regex)) {\r\n\t\t\tlet max: undefined | number = undefined;\r\n\t\t\tlet min: undefined | number = undefined;\r\n\t\t\tconst foundStat = template.statistics?.[name];\r\n\t\t\tif (foundStat) {\r\n\t\t\t\tmax = foundStat.max;\r\n\t\t\t\tmin = foundStat.min;\r\n\t\t\t}\r\n\t\t\tconst total = template.total || 100;\r\n\t\t\tconst randomStatValue = generateRandomStat(total, max, min);\r\n\t\t\tnewDice = value.replace(regex, randomStatValue.toString());\r\n\t\t}\r\n\t}\r\n\treturn replaceFormulaInDice(newDice);\r\n}\r\n\r\n/**\r\n * Same as damageDice but for DiceType\r\n * @param dice {string}\r\n * @param template {StatisticalTemplate}\r\n */\r\nexport function diceTypeRandomParse(dice: string, template: StatisticalTemplate) {\r\n\tdice = replaceExpByRandom(dice);\r\n\tif (!template.statistics) return dice;\r\n\tconst firstStatNotcombinaison = Object.keys(template.statistics).find(\r\n\t\t(stat) => !template.statistics?.[stat].combinaison\r\n\t);\r\n\tif (!firstStatNotcombinaison) return dice;\r\n\tconst stats = template.statistics[firstStatNotcombinaison];\r\n\tconst { min, max } = stats;\r\n\tconst total = template.total || 100;\r\n\tconst randomStatValue = generateRandomStat(total, max, min);\r\n\treturn replaceFormulaInDice(dice.replaceAll(\"$\", randomStatValue.toString()));\r\n}\r\n\r\n/**\r\n * Random the combinaison and evaluate it to check if everything is valid\r\n * @param combinaison {Record<string,string>}\r\n * @param stats {Record<string,number|number>}\r\n */\r\nexport function evalCombinaison(\r\n\tcombinaison: Record<string, string>,\r\n\tstats: Record<string, number | string>\r\n) {\r\n\tconst newStats: Record<string, number> = {};\r\n\tfor (const [stat, combin] of Object.entries(combinaison)) {\r\n\t\t//replace the stats in formula\r\n\t\tlet formula = combin.standardize();\r\n\t\tfor (const [statName, value] of Object.entries(stats)) {\r\n\t\t\tconst regex = new RegExp(statName.standardize(), \"gi\");\r\n\t\t\tformula = formula.replace(regex, value.toString());\r\n\t\t}\r\n\t\ttry {\r\n\t\t\tnewStats[stat] = evaluate(formula);\r\n\t\t} catch (error) {\r\n\t\t\tthrow new FormulaError(stat, \"evalCombinaison\", error);\r\n\t\t}\r\n\t}\r\n\treturn newStats;\r\n}\r\n\r\n/**\r\n * Evaluate one selected combinaison\r\n * @param combinaison {string}\r\n * @param stats {[name: string]: string|number}\r\n */\r\nexport function evalOneCombinaison(\r\n\tcombinaison: string,\r\n\tstats: Record<string, number | string>\r\n) {\r\n\tlet formula = combinaison.standardize();\r\n\tfor (const [statName, value] of Object.entries(stats)) {\r\n\t\tconst regex = new RegExp(statName.standardize(), \"gi\");\r\n\t\tformula = formula.replace(regex, value.toString());\r\n\t}\r\n\ttry {\r\n\t\treturn evaluate(formula);\r\n\t} catch (error) {\r\n\t\tthrow new FormulaError(combinaison, \"evalOneCombinaison\", error);\r\n\t}\r\n}\r\n\r\nfunction convertNumber(number: string | number | undefined) {\r\n\tif (!number) return undefined;\r\n\tif (number.toString().length === 0) return undefined;\r\n\tif (isNumber(number)) return Number.parseInt(number.toString(), 10);\r\n\treturn undefined;\r\n}\r\n\r\n/**\r\n * Parse the provided JSON and verify each field to check if everything could work when rolling\r\n * @param {unknown} template\r\n * @param {boolean} verify - If true, will roll the dices to check if everything is valid\r\n * @returns {StatisticalTemplate}\r\n */\r\nexport function verifyTemplateValue(template: unknown, verify: boolean=true): StatisticalTemplate {\r\n\tconst parsedTemplate = templateSchema.parse(template);\r\n\tconst { success, failure } = parsedTemplate.critical ?? {};\r\n\tconst criticicalVal = {\r\n\t\tsuccess: convertNumber(success),\r\n\t\tfailure: convertNumber(failure),\r\n\t};\r\n\tconst statistiqueTemplate: StatisticalTemplate = {\r\n\t\tdiceType: parsedTemplate.diceType,\r\n\t\tstatistics: parsedTemplate.statistics,\r\n\t\tcritical: criticicalVal,\r\n\t\ttotal: parsedTemplate.total,\r\n\t\tcharName: parsedTemplate.charName,\r\n\t\tdamage: parsedTemplate.damage,\r\n\t\tcustomCritical: parsedTemplate.customCritical,\r\n\t};\r\n\tif (!verify) return statistiqueTemplate;\r\n\tif (statistiqueTemplate.diceType) {\r\n\t\tconst cleanedDice = diceTypeRandomParse(\r\n\t\t\tstatistiqueTemplate.diceType,\r\n\t\t\tstatistiqueTemplate\r\n\t\t);\r\n\t\tconst rolled = roll(cleanedDice);\r\n\t\tif (!rolled) {\r\n\t\t\tthrow new DiceTypeError(cleanedDice, \"verifyTemplateValue\", \"no roll result\");\r\n\t\t}\r\n\t}\r\n\tif (statistiqueTemplate.customCritical) {\r\n\t\tif (!statistiqueTemplate.diceType) {\r\n\t\t\tthrow new DiceTypeError(\"no_dice_type\", \"verifyTemplateValue\", \"no dice type\");\r\n\t\t}\r\n\t\tconst customCritical = statistiqueTemplate.customCritical;\r\n\t\tfor (const [, custom] of Object.entries(customCritical)) {\r\n\t\t\tconst cleanedDice = createCriticalCustom(\r\n\t\t\t\tstatistiqueTemplate.diceType!,\r\n\t\t\t\tcustom,\r\n\t\t\t\tstatistiqueTemplate\r\n\t\t\t);\r\n\t\t\tconst rolled = roll(cleanedDice);\r\n\t\t\tif (!rolled)\r\n\t\t\t\tthrow new DiceTypeError(cleanedDice, \"verifyTemplateValue\", \"no roll result\");\r\n\t\t}\r\n\t}\r\n\ttestDiceRegistered(statistiqueTemplate);\r\n\ttestStatCombinaison(statistiqueTemplate);\r\n\treturn statistiqueTemplate;\r\n}\r\n\r\n/**\r\n * Test each damage roll from the template.damage\r\n * @param {StatisticalTemplate} template\r\n */\r\nexport function testDiceRegistered(template: StatisticalTemplate) {\r\n\tif (!template.damage) return;\r\n\tif (Object.keys(template.damage).length === 0) throw new EmptyObjectError();\r\n\tif (Object.keys(template.damage).length > 25) throw new TooManyDice();\r\n\tfor (const [name, dice] of Object.entries(template.damage)) {\r\n\t\tif (!dice) continue;\r\n\t\tconst diceReplaced = replaceExpByRandom(dice);\r\n\t\tconst randomDiceParsed = diceRandomParse(diceReplaced, template);\r\n\t\ttry {\r\n\t\t\tconst rolled = roll(randomDiceParsed);\r\n\t\t\tif (!rolled) throw new DiceTypeError(name, \"no_roll_result\", dice);\r\n\t\t} catch (error) {\r\n\t\t\tconsole.error(error);\r\n\t\t\tthrow new DiceTypeError(name, \"testDiceRegistered\", error);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n/**\r\n * Test all combinaison with generated random value\r\n * @param {StatisticalTemplate} template\r\n */\r\nexport function testStatCombinaison(template: StatisticalTemplate) {\r\n\tif (!template.statistics) return;\r\n\tconst onlycombinaisonStats = Object.fromEntries(\r\n\t\tObject.entries(template.statistics).filter(\r\n\t\t\t([_, value]) => value.combinaison !== undefined\r\n\t\t)\r\n\t);\r\n\tconst allOtherStats = Object.fromEntries(\r\n\t\tObject.entries(template.statistics).filter(([_, value]) => !value.combinaison)\r\n\t);\r\n\tif (Object.keys(onlycombinaisonStats).length === 0) return;\r\n\tconst allStats = Object.keys(template.statistics).filter(\r\n\t\t(stat) => !template.statistics![stat].combinaison\r\n\t);\r\n\tif (allStats.length === 0) throw new NoStatisticsError();\r\n\tconst error = [];\r\n\tfor (const [stat, value] of Object.entries(onlycombinaisonStats)) {\r\n\t\tlet formula = value.combinaison as string;\r\n\t\tfor (const [other, data] of Object.entries(allOtherStats)) {\r\n\t\t\tconst { max, min } = data;\r\n\t\t\tconst total = template.total || 100;\r\n\t\t\tconst randomStatValue = generateRandomStat(total, max, min);\r\n\t\t\tconst regex = new RegExp(other, \"gi\");\r\n\t\t\tformula = formula.replace(regex, randomStatValue.toString());\r\n\t\t}\r\n\t\ttry {\r\n\t\t\tevaluate(formula);\r\n\t\t} catch (e) {\r\n\t\t\terror.push(stat);\r\n\t\t}\r\n\t}\r\n\tif (error.length > 0) throw new FormulaError(error.join(\", \"), \"testStatCombinaison\");\r\n\treturn;\r\n}\r\n\r\n/**\r\n * Generate a random stat based on the template and the statistical min and max\r\n * @param {number|undefined} total\r\n * @param {number | undefined} max\r\n * @param {number | undefined} min\r\n * @returns\r\n */\r\nexport function generateRandomStat(\r\n\ttotal: number | undefined = 100,\r\n\tmax?: number,\r\n\tmin?: number\r\n) {\r\n\tlet randomStatValue = total + 1;\r\n\twhile (randomStatValue >= total || randomStatValue === 0) {\r\n\t\tconst random = new Random();\r\n\t\tif (max && min) randomStatValue = random.integer(min, max);\r\n\t\telse if (max) randomStatValue = random.integer(1, max);\r\n\t\telse if (min) randomStatValue = random.integer(min, total);\r\n\t\telse randomStatValue = random.integer(1, total);\r\n\t}\r\n\treturn randomStatValue;\r\n}\r\n","export class DiceTypeError extends Error {\n\tpublic readonly dice: string;\n\tpublic readonly cause: string | undefined;\n\tpublic readonly method: unknown;\n\n\tconstructor(dice: string, cause?: string, method?: unknown) {\n\t\tsuper(dice);\n\t\tthis.name = \"Invalid_Dice_Type\";\n\t\tthis.dice = dice;\n\t\tthis.cause = cause;\n\t\tthis.method = method;\n\t}\n}\n\nexport class FormulaError extends Error {\n\tpublic readonly formula: string;\n\tpublic readonly cause: string | undefined;\n\tpublic readonly method: unknown;\n\n\tconstructor(formula: string, cause?: string, method?: unknown) {\n\t\tsuper(formula);\n\t\tthis.name = \"Invalid_Formula\";\n\t\tthis.formula = formula;\n\t\tthis.cause = cause;\n\t\tthis.method = method;\n\t}\n}\n\nexport class MaxGreater extends Error {\n\tpublic readonly name: string;\n\tpublic readonly value: number;\n\tpublic readonly max: number;\n\n\tconstructor(value: number, max: number) {\n\t\tsuper(value.toString());\n\t\tthis.name = \"Max_Greater\";\n\t\tthis.value = value;\n\t\tthis.max = max;\n\t}\n}\n\nexport class EmptyObjectError extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Empty_Object\";\n\t}\n}\n\nexport class TooManyDice extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Too_Many_Dice\";\n\t}\n}\n\nexport class TooManyStats extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Too_Many_Stats\";\n\t}\n}\n\nexport class NoStatisticsError extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"No_Statistics\";\n\t}\n}\n","export const COMMENT_REGEX = /\\s+(#|\\/{2}|\\[|\\/\\*)(?<comment>.*)/;\r\nexport const SIGN_REGEX = /[><=!]+/;\r\nexport const SIGN_REGEX_SPACE = /[><=!]+(\\S+)/;\r\n\r\nexport const SYMBOL_DICE = \"&\";\r\n","/**\n * Definition of the Zod schema for template data\n */\nimport { z } from \"zod\";\n\nconst statisticValueSchema = z\n\t.object({\n\t\tmax: z.number().min(0).transform(val => val === 0 ? undefined : val).optional(),\n\t\tmin: z.number().min(0).transform(val => val === 0 ? undefined : val).optional(),\n\t\tcombinaison: z\n\t\t\t.string()\n\t\t\t.transform((str) => str.trim() || undefined)\n\t\t\t.optional(),\n\t\texclude: z.boolean().optional(),\n\t})\n\t.superRefine((data, ctx) => {\n\t\t\n\t\tif (data.max !== undefined && data.min !== undefined && data.max <= data.min) {\n\t\t\tctx.addIssue({\n\t\t\t\tcode: \"custom\",\n\t\t\t\tmessage: `Max_Greater; ${data.min}; ${data.max}`,\n\t\t\t\tpath: [\"max\"],\n\t\t\t});\n\t\t}\n\t});\n\nconst statisticSchema = z\n\t.record(statisticValueSchema)\n\t.optional()\n\t.refine((stats) => !stats || Object.keys(stats).length <= 25, {\n\t\tmessage: \"TooManyStats\",\n\t});\n\nconst criticalSchema = z\n\t.object({\n\t\tsuccess: z.string().or(z.number().min(0)).optional(),\n\t\tfailure: z.string().or(z.number().min(0)).optional(),\n\t})\n\t.transform((values) => {\n\t\tif (values.success === \"\") values.success = undefined;\n\t\tif (values.failure === \"\") values.failure = undefined;\n\t\tif (values.failure === 0) values.failure = undefined;\n\t\tif (values.success === 0) values.success = undefined;\n\t\tvalues.success = Number.parseInt(values.success as string, 10);\n\t\tvalues.failure = Number.parseInt(values.failure as string, 10);\n\t\treturn values;\n\t});\n\nconst criticalValueSchema = z.object({\n\tsign: z.enum([\"<\", \">\", \"<=\", \">=\", \"!=\", \"==\"]),\n\tvalue: z.string(),\n\tonNaturalDice: z.boolean().optional(),\n\taffectSkill: z.boolean().optional(),\n});\n\nconst damageSchema = z\n\t.record(z.string())\n\t.optional()\n\t.refine((stats) => !stats || Object.keys(stats).length <= 25, {\n\t\tmessage: \"TooManyDice\",\n\t});\n\nconst customCriticalSchema = z\n\t.record(criticalValueSchema)\n\t.optional()\n\t.refine((stats) => !stats || Object.keys(stats).length <= 22, {\n\t\tmessage: \"TooManyDice\",\n\t});\n\nexport const templateSchema = z.object({\n\tcharName: z.boolean().optional(),\n\tstatistics: statisticSchema,\n\ttotal: z.number().min(0).optional(),\n\tdiceType: z.string().optional(),\n\tcritical: criticalSchema.optional(),\n\tcustomCritical: customCriticalSchema,\n\tdamage: damageSchema,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,6BAA2B;AAC3B,IAAAA,iBAAyB;;;ACDzB,oBAAkC;AAClC,wBAAO;AAOA,SAAS,YAAY,QAAgB;AAC3C,SAAO,OAAO,QAAQ,uBAAuB,MAAM;AACp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,OAAO,KAAK,KAAK,EAAE,UAAU,IAAI;AAAA,EAC7D,SAAS;AACV,CAAC;AAEF,IAAM,uBAAuB,aAC3B,OAAO,mBAAmB,EAC1B,SAAS,EACT,OAAO,CAAC,UAAU,CAAC,SAAS,OAAO,KAAK,KAAK,EAAE,UAAU,IAAI;AAAA,EAC7D,SAAS;AACV,CAAC;AAEK,IAAM,iBAAiB,aAAE,OAAO;AAAA,EACtC,UAAU,aAAE,QAAQ,EAAE,SAAS;AAAA,EAC/B,YAAY;AAAA,EACZ,OAAO,aAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS;AAAA,EAClC,UAAU,aAAE,OAAO,EAAE,SAAS;AAAA,EAC9B,UAAU,eAAe,SAAS;AAAA,EAClC,gBAAgB;AAAA,EAChB,QAAQ;AACT,CAAC;","names":["import_mathjs","roller","evaluateRoll","diceResult","import_mathjs","import_uniformize","cleanedDice","random"]}
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/dice.ts","../src/utils.ts","../src/verify_template.ts","../src/errors.ts","../src/interfaces/constant.ts","../src/interfaces/zod.ts"],"sourcesContent":["export * from \"./dice\";\r\nexport * from \"./interfaces\";\r\nexport * from \"./utils\";\r\nexport * from \"./verify_template\";\r\nexport * from \"./errors\";\r\nexport * from \"./interfaces/constant\";\r\nexport * from \"./interfaces/zod\";\r\nexport * from \"./interfaces/toJsonSchema\";\r\n","import { DiceRoller } from \"@dice-roller/rpg-dice-roller\";\r\nimport { evaluate } from \"mathjs\";\r\n\r\nimport {\r\n\ttype Compare,\r\n\ttype ComparedValue,\r\n\ttype CustomCritical,\r\n\ttype Modifier,\r\n\ttype Resultat,\r\n\ttype Sign,\r\n\ttype StatisticalTemplate,\r\n\tdiceTypeRandomParse,\r\n\tstandardizeDice,\r\n\tDiceTypeError,\r\n\tCOMMENT_REGEX,\r\n\tSIGN_REGEX,\r\n\tSIGN_REGEX_SPACE,\r\n\tSYMBOL_DICE,\r\n} from \".\";\r\nimport { isNumber } from \"./utils\";\r\n\r\nfunction getCompare(\r\n\tdice: string,\r\n\tcompareRegex: RegExpMatchArray\r\n): { dice: string; compare: ComparedValue | undefined } {\r\n\t/**\r\n\t * @source: https://dice-roller.github.io/documentation/guide/notation/modifiers.html#target-success-dice-pool\r\n\t * Some system count the number of a dice that are greater than or equal to a target, and not the \"total\" of rolled dice.\r\n\t * We \"count\" the number of dice that meet a criterion, and not the total of the dice.\r\n\t * To support this, we use the group notation. It a little different than the notation of dice-roller, but it a sacrifice to not break the current notation.\r\n\t * @note:\r\n\t * - `{2d3}>=4` will be the same as `2d3>=4` and thus keep the comparaison.\r\n\t * - `{2d3>=4}` will count the total of dice that are greater than or equal to 4, and not the total of the dice.\r\n\t * - `{2d3,1d4}>=4` won't use the comparison, but will count the number of dice that are greater than or equal to 4. If the total of the dice is needed, just remove the group notation and use `2d3+1d4>=4`.\r\n\t */\r\n\tif (dice.match(/((\\{.*,(.*)+\\}|([><=!]+\\d+f))[><=!]+\\d+\\}?)|\\{(.*)([><=!]+).*\\}/)) return { dice, compare: undefined };\r\n\tdice = dice.replace(SIGN_REGEX_SPACE, \"\");\r\n\tlet compare: ComparedValue;\r\n\tconst calc = compareRegex[1];\r\n\tconst sign = calc.match(/[+-\\/*^]/)?.[0];\r\n\tconst compareSign = compareRegex[0].match(SIGN_REGEX)?.[0];\r\n\t\r\n\t\r\n\tif (sign) {\r\n\t\tconst toCalc = calc.replace(SIGN_REGEX, \"\").replace(/\\s/g, \"\").replace(/;(.*)/, \"\");\r\n\t\tconst rCompare = rollCompare(toCalc);\r\n\t\tconst total = evaluate(rCompare.value.toString());\r\n\t\tdice = dice.replace(SIGN_REGEX_SPACE, `${compareSign}${total}`);\r\n\t\tcompare = {\r\n\t\t\tsign: compareSign as \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\",\r\n\t\t\tvalue: total,\r\n\t\t\toriginalDice: rCompare.dice,\r\n\t\t\trollValue: rCompare.diceResult,\r\n\t\t};\r\n\t} else {\r\n\t\tconst rcompare = rollCompare(calc);\r\n\t\tcompare = {\r\n\t\t\tsign: compareSign as \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\",\r\n\t\t\tvalue: rcompare.value,\r\n\t\t\toriginalDice: rcompare.dice,\r\n\t\t\trollValue: rcompare.diceResult,\r\n\t\t};\r\n\t}\r\n\treturn { dice, compare };\r\n}\r\n\r\nfunction rollCompare(value: unknown) {\r\n\tif (isNumber(value)) return { value: Number.parseInt(value as string, 10) };\r\n\tconst rollComp = roll(value as string);\r\n\tif (!rollComp?.total)\r\n\t\t//not a dice throw\r\n\t\treturn { value: evaluate(value as string), diceResult: value as string };\r\n\treturn {\r\n\t\tdice: value as string,\r\n\t\tvalue: rollComp.total,\r\n\t\tdiceResult: rollComp?.result,\r\n\t};\r\n}\r\n\r\n/**\r\n * Allow to replace the compare part of a dice and use the critical customized one\r\n * @example\r\n * dice = \"1d20=20\";\r\n * custom critical {sign: \">\", value: \"$/2\"}\r\n * Random stats = 6\r\n * result = \"1d20>3\"\r\n */\r\nexport function createCriticalCustom(\r\n\tdice: string,\r\n\tcustomCritical: CustomCritical,\r\n\ttemplate: StatisticalTemplate\r\n) {\r\n\tconst compareRegex = dice.match(SIGN_REGEX_SPACE);\r\n\tlet customDice = dice;\r\n\tconst compareValue = diceTypeRandomParse(customCritical.value, template);\r\n\tif (compareValue.includes(\"$\"))\r\n\t\tthrow new DiceTypeError(compareValue, \"createCriticalCustom\");\r\n\tconst comparaison = `${customCritical.sign}${compareValue}`;\r\n\tif (compareRegex) customDice = customDice.replace(SIGN_REGEX_SPACE, comparaison);\r\n\telse customDice += comparaison;\r\n\treturn diceTypeRandomParse(customDice, template);\r\n}\r\n\r\nfunction getModifier(dice: string) {\r\n\tconst modifier = dice.matchAll(/(\\+|-|%|\\/|\\^|\\*|\\*{2})(\\d+)/gi);\r\n\tlet modificator: Modifier | undefined;\r\n\tfor (const mod of modifier) {\r\n\t\t//calculate the modifier if multiple\r\n\t\tif (modificator) {\r\n\t\t\tconst sign = modificator.sign;\r\n\t\t\tlet value = modificator.value;\r\n\t\t\tif (sign) value = calculator(sign, value, Number.parseInt(mod[2], 10));\r\n\t\t\tmodificator = {\r\n\t\t\t\tsign: mod[1] as Sign,\r\n\t\t\t\tvalue,\r\n\t\t\t};\r\n\t\t} else {\r\n\t\t\tmodificator = {\r\n\t\t\t\tsign: mod[1] as Sign,\r\n\t\t\t\tvalue: Number.parseInt(mod[2], 10),\r\n\t\t\t};\r\n\t\t}\r\n\t}\r\n\treturn modificator;\r\n}\r\n\r\n/**\r\n * Parse the string provided and turn it as a readable dice for dice parser\r\n * @param dice {string}\r\n */\r\nexport function roll(dice: string): Resultat | undefined {\r\n\t//parse dice string\r\n\tdice = standardizeDice(dice).replace(/^\\+/, \"\").trimStart();\r\n\tif (!dice.includes(\"d\")) return undefined;\r\n\tconst compareRegex = dice.match(SIGN_REGEX_SPACE);\r\n\tlet compare: ComparedValue | undefined;\r\n\tif (dice.includes(\";\")) return sharedRolls(dice);\r\n\tif (compareRegex) {\r\n\t\tconst compareResult = getCompare(dice, compareRegex);\r\n\t\tdice = compareResult.dice;\r\n\t\tcompare = compareResult.compare;\r\n\t}\r\n\tconst modificator = getModifier(dice);\r\n\r\n\tif (dice.match(/\\d+?#(.*)/)) {\r\n\t\tconst diceArray = dice.split(\"#\");\r\n\t\tconst numberOfDice = Number.parseInt(diceArray[0], 10);\r\n\t\tconst diceToRoll = diceArray[1].replace(COMMENT_REGEX, \"\");\r\n\t\tconst commentsMatch = diceArray[1].match(COMMENT_REGEX);\r\n\t\tconst comments = commentsMatch ? commentsMatch[2] : undefined;\r\n\t\tconst roller = new DiceRoller();\r\n\t\t//remove comments if any\r\n\t\tfor (let i = 0; i < numberOfDice; i++) {\r\n\t\t\ttry {\r\n\t\t\t\troller.roll(diceToRoll);\r\n\t\t\t} catch (error) {\r\n\t\t\t\tthrow new DiceTypeError(diceToRoll, \"roll\", error);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn {\r\n\t\t\tdice: diceToRoll,\r\n\t\t\tresult: roller.output,\r\n\t\t\tcomment: comments,\r\n\t\t\tcompare: compare ? compare : undefined,\r\n\t\t\tmodifier: modificator,\r\n\t\t\ttotal: roller.total,\r\n\t\t};\r\n\t}\r\n\tconst roller = new DiceRoller();\r\n\tconst diceWithoutComment = dice.replace(COMMENT_REGEX, \"\").trimEnd();\r\n\ttry {\r\n\t\troller.roll(diceWithoutComment);\r\n\t} catch (error) {\r\n\t\tthrow new DiceTypeError(diceWithoutComment, \"roll\", error);\r\n\t}\r\n\tconst commentMatch = dice.match(COMMENT_REGEX);\r\n\tconst comment = commentMatch ? commentMatch[2] : undefined;\r\n\treturn {\r\n\t\tdice,\r\n\t\tresult: roller.output,\r\n\t\tcomment,\r\n\t\tcompare: compare ? compare : undefined,\r\n\t\tmodifier: modificator,\r\n\t\ttotal: roller.total,\r\n\t};\r\n}\r\n/**\r\n * Evaluate a formula and replace \"^\" by \"**\" if any\r\n * @param {Sign} sign\r\n * @param {number} value\r\n * @param {number} total\r\n * @returns\r\n */\r\nexport function calculator(sign: Sign, value: number, total: number): number {\r\n\tif (sign === \"^\") sign = \"**\";\r\n\treturn evaluate(`${total} ${sign} ${value}`);\r\n}\r\n\r\nfunction inverseSign(\r\n\tsign: \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\"\r\n): \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\" {\r\n\tswitch (sign) {\r\n\t\tcase \"<\":\r\n\t\t\treturn \">\";\r\n\t\tcase \">\":\r\n\t\t\treturn \"<\";\r\n\t\tcase \"<=\":\r\n\t\t\treturn \">=\";\r\n\t\tcase \">=\":\r\n\t\t\treturn \"<=\";\r\n\t\tcase \"=\":\r\n\t\t\treturn \"!=\";\r\n\t\tcase \"==\":\r\n\t\t\treturn \"!=\";\r\n\t\tcase \"!=\":\r\n\t\t\treturn \"==\";\r\n\t}\r\n}\r\n\r\nfunction replaceInFormula(\r\n\telement: string,\r\n\tdiceResult: Resultat,\r\n\tcompareResult: { dice: string; compare: Compare | undefined },\r\n\tres: boolean\r\n) {\r\n\tconst { formule, diceAll } = replaceText(\r\n\t\telement,\r\n\t\tdiceResult.total ?? 0,\r\n\t\tdiceResult.dice\r\n\t);\r\n\tconst validSign = res ? \"✓\" : \"✕\";\r\n\tconst invertedSign = res\r\n\t\t? compareResult.compare!.sign\r\n\t\t: inverseSign(compareResult.compare!.sign);\r\n\tlet evaluateRoll: unknown;\r\n\ttry {\r\n\t\tevaluateRoll = evaluate(compareResult.dice);\r\n\t\treturn `${validSign} ${diceAll}: ${formule} = ${evaluateRoll}${invertedSign}${compareResult.compare?.value}`;\r\n\t} catch (error) {\r\n\t\tconst evaluateRoll = roll(compareResult.dice) as Resultat | undefined;\r\n\t\tif (evaluateRoll)\r\n\t\t\treturn `${validSign} ${diceAll}: ${evaluateRoll.result.split(\":\").splice(1).join(\":\")}`;\r\n\r\n\t\treturn `${validSign} ${diceAll}: ${formule} = ${evaluateRoll}${invertedSign}${compareResult.compare?.value}`;\r\n\t}\r\n}\r\n\r\nfunction compareSignFormule(\r\n\ttoRoll: string,\r\n\tcompareRegex: RegExpMatchArray,\r\n\telement: string,\r\n\tdiceResult: Resultat\r\n) {\r\n\tlet results = \"\";\r\n\tconst compareResult = getCompare(toRoll, compareRegex);\r\n\tconst toCompare = `${compareResult.dice}${compareResult.compare?.sign}${compareResult.compare?.value}`;\r\n\tlet res: unknown;\r\n\ttry {\r\n\t\tres = evaluate(toCompare);\r\n\t} catch (error) {\r\n\t\tres = roll(toCompare);\r\n\t}\r\n\tif (typeof res === \"boolean\") {\r\n\t\tresults = replaceInFormula(element, diceResult, compareResult, res);\r\n\t} else if (res instanceof Object) {\r\n\t\tconst diceResult = res as Resultat;\r\n\t\tif (diceResult.compare) {\r\n\t\t\tconst toEvaluate = evaluate(\r\n\t\t\t\t`${diceResult.total}${diceResult.compare.sign}${diceResult.compare.value}`\r\n\t\t\t);\r\n\t\t\tconst sign = toEvaluate ? \"✓\" : \"✕\";\r\n\t\t\tconst invertedSign = toEvaluate\r\n\t\t\t\t? diceResult.compare.sign\r\n\t\t\t\t: inverseSign(diceResult.compare.sign);\r\n\t\t\tconst dice = replaceText(element, 0, diceResult.dice).diceAll;\r\n\r\n\t\t\tresults = `${sign} ${dice}: ${diceResult.result.split(\":\").splice(1).join(\":\").trim()}${invertedSign}${diceResult.compare.value}`;\r\n\t\t}\r\n\t}\r\n\treturn { dice: compareResult.dice, results };\r\n}\r\n\r\nfunction replaceText(element: string, total: number, dice: string) {\r\n\treturn {\r\n\t\tformule: element.replace(SYMBOL_DICE, `[${total}]`).replace(/%.*%/g, \"\").trim(),\r\n\t\tdiceAll: element\r\n\t\t\t.replace(SYMBOL_DICE, `[${dice.replace(COMMENT_REGEX, \"\")}]`)\r\n\t\t\t.replace(/%.*%/g, \"\")\r\n\t\t\t.trim(),\r\n\t};\r\n}\r\n\r\nfunction formatComment(dice: string) {\r\n\tconst commentsRegex = /\\[(?<comments>.*?)\\]/;\r\n\tconst commentsMatch = commentsRegex.exec(dice);\r\n\treturn commentsMatch?.groups?.comments ? `__${commentsMatch.groups.comments}__ — ` : \"\";\r\n}\r\n\r\nfunction sharedRolls(dice: string): Resultat | undefined {\r\n\tif (dice.match(/\\d+?#(.*?)/))\r\n\t\tthrow new DiceTypeError(\r\n\t\t\tdice,\r\n\t\t\t\"noBulkRoll\",\r\n\t\t\t\"bulk roll are not allowed in shared rolls\"\r\n\t\t);\r\n\tconst results = [];\r\n\tconst mainComment =\r\n\t\t/\\s+#(?<comment>.*)/.exec(dice)?.groups?.comment?.trimEnd() ?? undefined;\r\n\tconst split = dice.split(\";\");\r\n\tlet diceMain = split[0];\r\n\tconst toHideRegex = /(?<!\\[[^\\]]*)\\((?<dice>[^)]+)\\)/;\r\n\tconst toHide = toHideRegex.exec(diceMain)?.groups;\r\n\tlet hidden = false;\r\n\tif (toHide?.dice) {\r\n\t\tdiceMain = toHide.dice;\r\n\t\thidden = true;\r\n\t} else if (toHide) {\r\n\t\tdiceMain = \"1d1\";\r\n\t\thidden = true;\r\n\t}\r\n\tconst commentsRegex = /\\[(?<comments>.*?)\\]/gi;\r\n\tconst comments = formatComment(diceMain);\r\n\tdiceMain = diceMain.replaceAll(commentsRegex, \"\").trim();\r\n\tconst diceResult = roll(diceMain);\r\n\tif (!diceResult || !diceResult.total) return undefined;\r\n\tresults.push(`※ ${comments}${diceResult.result}`);\r\n\tlet total = diceResult.total;\r\n\tdiceResult.comment = mainComment;\r\n\tif (!total) return diceResult;\r\n\tfor (let element of split.slice(1)) {\r\n\t\tconst comment = formatComment(element);\r\n\t\telement = element.replace(commentsRegex, \"\").trim();\r\n\t\tlet toRoll = element.replace(SYMBOL_DICE, `${diceResult.total}`);\r\n\t\tconst compareRegex = toRoll.match(SIGN_REGEX_SPACE);\r\n\t\tif (compareRegex) {\r\n\t\t\tconst compareResult = compareSignFormule(toRoll, compareRegex, element, diceResult);\r\n\t\t\ttoRoll = compareResult.dice;\r\n\t\t\tresults.push(compareResult.results);\r\n\t\t} else {\r\n\t\t\tconst { formule, diceAll } = replaceText(\r\n\t\t\t\telement,\r\n\t\t\t\tdiceResult.total,\r\n\t\t\t\tdiceResult.dice\r\n\t\t\t);\r\n\r\n\t\t\ttry {\r\n\t\t\t\tconst evaluated = evaluate(toRoll);\r\n\t\t\t\tresults.push(`◈ ${comment}${diceAll}: ${formule} = ${evaluated}`);\r\n\t\t\t\ttotal += Number.parseInt(evaluated, 10);\r\n\t\t\t} catch (error) {\r\n\t\t\t\tconst evaluated = roll(toRoll);\r\n\t\t\t\tif (evaluated)\r\n\t\t\t\t\tresults.push(\r\n\t\t\t\t\t\t`◈ ${comment}${diceAll}: ${evaluated.result.split(\":\").slice(1).join(\":\")}`\r\n\t\t\t\t\t);\r\n\t\t\t\telse results.push(`◈ ${comment}${diceAll}: ${formule} = ${evaluated}`);\r\n\t\t\t\ttotal += evaluated?.total ?? 0;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tif (hidden)\r\n\t\t//remove the first in result\r\n\t\tresults.shift();\r\n\treturn {\r\n\t\tdice: diceMain,\r\n\t\tresult: results.join(\";\"),\r\n\t\tcomment: mainComment,\r\n\t\tcompare: diceResult.compare,\r\n\t\tmodifier: diceResult.modifier,\r\n\t\ttotal,\r\n\t};\r\n}\r\n","import {evaluate, randomInt} from \"mathjs\";\r\nimport \"uniformize\";\r\nimport { FormulaError } from \".\";\r\n\r\n/**\r\n * Escape regex string\r\n * @param string {string}\r\n */\r\nexport function escapeRegex(string: string) {\r\n\treturn string.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\r\n}\r\n\r\n/**\r\n * Allow to keep the text as if in brackets\r\n * @param dice {string}\r\n * @return {string} the dice with the text in brackets as if, but the dice (not in brackets) is standardized\r\n */\r\nexport function standardizeDice(dice: string): string {\r\n\treturn dice.replace(\r\n\t\t/(\\[[^\\]]+\\])|([^[]+)/g,\r\n\t\t(match, insideBrackets, outsideText) =>\r\n\t\t\tinsideBrackets ? insideBrackets : outsideText.standardize(),\r\n\t);\r\n}\r\n\r\n/**\r\n * Replace the stat name by their value using stat\r\n * and after evaluate any formula using `replaceFormulaInDice`\r\n * @param {string} originalDice\r\n * @param {Record<string,number>|undefined} stats\r\n * @param {string|undefined} dollarValue\r\n */\r\nexport function generateStatsDice(\r\n\toriginalDice: string,\r\n\tstats?: Record<string, number>,\r\n\tdollarValue?: string,\r\n) {\r\n\tlet dice = originalDice.standardize();\r\n\tif (stats && Object.keys(stats).length > 0) {\r\n\t\t//damage field support adding statistic, like : 1d6 + strength\r\n\t\t//check if the value contains a statistic & calculate if it's okay\r\n\t\t//the dice will be converted before roll\r\n\t\tconst allStats = Object.keys(stats);\r\n\t\tfor (const stat of allStats) {\r\n\t\t\tconst regex = new RegExp(\r\n\t\t\t\t`(?!\\\\[)${escapeRegex(stat.standardize())}(?!\\\\])`,\r\n\t\t\t\t\"gi\",\r\n\t\t\t);\r\n\t\t\tif (dice.match(regex)) {\r\n\t\t\t\tconst statValue = stats[stat];\r\n\t\t\t\tdice = dice.replace(regex, statValue.toString());\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tif (dollarValue) dice = dice.replaceAll(\"$\", dollarValue);\r\n\treturn replaceFormulaInDice(dice);\r\n}\r\n\r\n/**\r\n * Replace the {{}} in the dice string and evaluate the interior if any\r\n * @param dice {string}\r\n */\r\nexport function replaceFormulaInDice(dice: string) {\r\n\tconst formula = /(?<formula>\\{{2}(.+?)}{2})/gim;\r\n\tlet match;\r\n\tlet modifiedDice = dice;\r\n\t// biome-ignore lint/suspicious/noAssignInExpressions: best way to regex in a loop\r\n\twhile ((match = formula.exec(dice)) !== null) {\r\n\t\tif (match.groups?.formula) {\r\n\t\t\tconst formulae = match.groups.formula\r\n\t\t\t\t.replaceAll(\"{{\", \"\")\r\n\t\t\t\t.replaceAll(\"}}\", \"\");\r\n\t\t\ttry {\r\n\t\t\t\tconst result = evaluate(formulae);\r\n\t\t\t\tmodifiedDice = modifiedDice.replace(\r\n\t\t\t\t\tmatch.groups.formula,\r\n\t\t\t\t\tresult.toString(),\r\n\t\t\t\t);\r\n\t\t\t} catch (error) {\r\n\t\t\t\tthrow new FormulaError(\r\n\t\t\t\t\tmatch.groups.formula,\r\n\t\t\t\t\t\"replaceFormulasInDice\",\r\n\t\t\t\t\terror,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn cleanedDice(modifiedDice);\r\n}\r\n\r\n/**\r\n * Replace the ++ +- -- by their proper value:\r\n * - `++` = `+`\r\n * - `+-` = `-`\r\n * - `--` = `+`\r\n * @param dice {string}\r\n */\r\nfunction cleanedDice(dice: string) {\r\n\treturn dice\r\n\t\t.replaceAll(\"+-\", \"-\")\r\n\t\t.replaceAll(\"--\", \"+\")\r\n\t\t.replaceAll(\"++\", \"+\")\r\n\t\t.trimEnd();\r\n}\r\n\r\n/**\r\n * Verify if a value is a number, even if it's a \"number\" string\r\n * @param value {unknown}\r\n * @returns {boolean}\r\n */\r\nexport function isNumber(value: unknown): boolean {\r\n\treturn (\r\n\t\tvalue !== undefined &&\r\n\t\t(typeof value === \"number\" ||\r\n\t\t\t(!Number.isNaN(Number(value)) &&\r\n\t\t\t\ttypeof value === \"string\" &&\r\n\t\t\t\tvalue.trim().length > 0))\r\n\t);\r\n}\r\n\r\n/**\r\n * Replace the `{exp}` in the dice.\r\n * If the `{exp}` has a default value in the form of `{exp || defaultValue}`, it will be replaced by the default value.\r\n * @param {string} dice\r\n * @returns {string} the dice with the {exp} replaced by a random value\r\n */\r\nexport function replaceExpByRandom(dice: string): string {\r\n\tconst diceRegex = /\\{exp( ?\\|\\| ?(?<default>\\d+))?}/gi\r\n\treturn dice.replace(diceRegex, (_match, _p1, _p2, _offset, _string, groups) => {\r\n\t\tconst defaultValue = groups?.default;\r\n\t\treturn defaultValue ?? randomInt(1, 999).toString();\r\n\t});\r\n}","import {evaluate, random, randomInt} from \"mathjs\";\r\nimport { Random } from \"random-js\";\r\nimport \"uniformize\";\r\n\r\nimport {\r\n\ttype StatisticalTemplate,\r\n\tcreateCriticalCustom,\r\n\troll,\r\n\tDiceTypeError,\r\n\tEmptyObjectError,\r\n\tFormulaError,\r\n\tNoStatisticsError,\r\n\tescapeRegex,\r\n\treplaceFormulaInDice,\r\n\ttemplateSchema,\r\n\tTooManyDice, replaceExpByRandom,\r\n} from \".\";\r\nimport { isNumber } from \"./utils\";\r\n\r\n/**\r\n * Verify if the provided dice work with random value\r\n * @param testDice {string}\r\n * @param allStats {Record<string,number>}\r\n */\r\nexport function evalStatsDice(testDice: string, allStats?: Record<string, number>) {\r\n\tlet dice = testDice.trimEnd();\r\n\tif (allStats && Object.keys(allStats).length > 0) {\r\n\t\tconst names = Object.keys(allStats);\r\n\t\tfor (const name of names) {\r\n\t\t\tconst regex = new RegExp(escapeRegex(name.standardize()), \"gi\");\r\n\t\t\tif (dice.standardize().match(regex)) {\r\n\t\t\t\tconst statValue = allStats[name];\r\n\t\t\t\tdice = dice.standardize().replace(regex, statValue.toString()).trimEnd();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\ttry {\r\n\t\tif (!roll(replaceFormulaInDice(replaceExpByRandom(dice))))\r\n\t\t\tthrow new DiceTypeError(dice, \"evalStatsDice\", \"no roll result\");\r\n\t\treturn testDice;\r\n\t} catch (error) {\r\n\t\tthrow new DiceTypeError(dice, \"evalStatsDice\", error);\r\n\t}\r\n}\r\n\r\n/**\r\n * Generate a random dice and remove the formula (+ evaluate it)\r\n * Used for diceDamage only\r\n * @param value {string}\r\n * @param template {StatisticalTemplate}\r\n * @returns\r\n */\r\nexport function diceRandomParse(value: string, template: StatisticalTemplate) {\r\n\tif (!template.statistics) return replaceFormulaInDice(value.standardize());\r\n\tvalue = value.standardize();\r\n\tconst statNames = Object.keys(template.statistics);\r\n\tlet newDice = value;\r\n\tfor (const name of statNames) {\r\n\t\tconst regex = new RegExp(escapeRegex(name.standardize()), \"gi\");\r\n\t\tif (value.match(regex)) {\r\n\t\t\tlet max: undefined | number = undefined;\r\n\t\t\tlet min: undefined | number = undefined;\r\n\t\t\tconst foundStat = template.statistics?.[name];\r\n\t\t\tif (foundStat) {\r\n\t\t\t\tmax = foundStat.max;\r\n\t\t\t\tmin = foundStat.min;\r\n\t\t\t}\r\n\t\t\tconst total = template.total || 100;\r\n\t\t\tconst randomStatValue = generateRandomStat(total, max, min);\r\n\t\t\tnewDice = value.replace(regex, randomStatValue.toString());\r\n\t\t}\r\n\t}\r\n\treturn replaceFormulaInDice(newDice);\r\n}\r\n\r\n/**\r\n * Same as damageDice but for DiceType\r\n * @param dice {string}\r\n * @param template {StatisticalTemplate}\r\n */\r\nexport function diceTypeRandomParse(dice: string, template: StatisticalTemplate) {\r\n\tdice = replaceExpByRandom(dice);\r\n\tif (!template.statistics) return dice;\r\n\tconst firstStatNotcombinaison = Object.keys(template.statistics).find(\r\n\t\t(stat) => !template.statistics?.[stat].combinaison\r\n\t);\r\n\tif (!firstStatNotcombinaison) return dice;\r\n\tconst stats = template.statistics[firstStatNotcombinaison];\r\n\tconst { min, max } = stats;\r\n\tconst total = template.total || 100;\r\n\tconst randomStatValue = generateRandomStat(total, max, min);\r\n\treturn replaceFormulaInDice(dice.replaceAll(\"$\", randomStatValue.toString()));\r\n}\r\n\r\n/**\r\n * Random the combinaison and evaluate it to check if everything is valid\r\n * @param combinaison {Record<string,string>}\r\n * @param stats {Record<string,number|number>}\r\n */\r\nexport function evalCombinaison(\r\n\tcombinaison: Record<string, string>,\r\n\tstats: Record<string, number | string>\r\n) {\r\n\tconst newStats: Record<string, number> = {};\r\n\tfor (const [stat, combin] of Object.entries(combinaison)) {\r\n\t\t//replace the stats in formula\r\n\t\tlet formula = combin.standardize();\r\n\t\tfor (const [statName, value] of Object.entries(stats)) {\r\n\t\t\tconst regex = new RegExp(statName.standardize(), \"gi\");\r\n\t\t\tformula = formula.replace(regex, value.toString());\r\n\t\t}\r\n\t\ttry {\r\n\t\t\tnewStats[stat] = evaluate(formula);\r\n\t\t} catch (error) {\r\n\t\t\tthrow new FormulaError(stat, \"evalCombinaison\", error);\r\n\t\t}\r\n\t}\r\n\treturn newStats;\r\n}\r\n\r\n/**\r\n * Evaluate one selected combinaison\r\n * @param combinaison {string}\r\n * @param stats {[name: string]: string|number}\r\n */\r\nexport function evalOneCombinaison(\r\n\tcombinaison: string,\r\n\tstats: Record<string, number | string>\r\n) {\r\n\tlet formula = combinaison.standardize();\r\n\tfor (const [statName, value] of Object.entries(stats)) {\r\n\t\tconst regex = new RegExp(statName.standardize(), \"gi\");\r\n\t\tformula = formula.replace(regex, value.toString());\r\n\t}\r\n\ttry {\r\n\t\treturn evaluate(formula);\r\n\t} catch (error) {\r\n\t\tthrow new FormulaError(combinaison, \"evalOneCombinaison\", error);\r\n\t}\r\n}\r\n\r\nfunction convertNumber(number: string | number | undefined) {\r\n\tif (!number) return undefined;\r\n\tif (number.toString().length === 0) return undefined;\r\n\tif (isNumber(number)) return Number.parseInt(number.toString(), 10);\r\n\treturn undefined;\r\n}\r\n\r\n/**\r\n * Parse the provided JSON and verify each field to check if everything could work when rolling\r\n * @param {unknown} template\r\n * @param {boolean} verify - If true, will roll the dices to check if everything is valid\r\n * @returns {StatisticalTemplate}\r\n */\r\nexport function verifyTemplateValue(template: unknown, verify: boolean=true): StatisticalTemplate {\r\n\tconst parsedTemplate = templateSchema.parse(template);\r\n\tconst { success, failure } = parsedTemplate.critical ?? {};\r\n\tconst criticicalVal = {\r\n\t\tsuccess: convertNumber(success),\r\n\t\tfailure: convertNumber(failure),\r\n\t};\r\n\tconst statistiqueTemplate: StatisticalTemplate = {\r\n\t\tdiceType: parsedTemplate.diceType,\r\n\t\tstatistics: parsedTemplate.statistics,\r\n\t\tcritical: criticicalVal,\r\n\t\ttotal: parsedTemplate.total,\r\n\t\tcharName: parsedTemplate.charName,\r\n\t\tdamage: parsedTemplate.damage,\r\n\t\tcustomCritical: parsedTemplate.customCritical,\r\n\t\tforceDistrib: parsedTemplate.forceDistrib,\r\n\t};\r\n\tif (!verify) return statistiqueTemplate;\r\n\tif (statistiqueTemplate.diceType) {\r\n\t\tconst cleanedDice = diceTypeRandomParse(\r\n\t\t\tstatistiqueTemplate.diceType,\r\n\t\t\tstatistiqueTemplate\r\n\t\t);\r\n\t\tconst rolled = roll(cleanedDice);\r\n\t\tif (!rolled) {\r\n\t\t\tthrow new DiceTypeError(cleanedDice, \"verifyTemplateValue\", \"no roll result\");\r\n\t\t}\r\n\t}\r\n\tif (statistiqueTemplate.customCritical) {\r\n\t\tif (!statistiqueTemplate.diceType) {\r\n\t\t\tthrow new DiceTypeError(\"no_dice_type\", \"verifyTemplateValue\", \"no dice type\");\r\n\t\t}\r\n\t\tconst customCritical = statistiqueTemplate.customCritical;\r\n\t\tfor (const [, custom] of Object.entries(customCritical)) {\r\n\t\t\tconst cleanedDice = createCriticalCustom(\r\n\t\t\t\tstatistiqueTemplate.diceType!,\r\n\t\t\t\tcustom,\r\n\t\t\t\tstatistiqueTemplate\r\n\t\t\t);\r\n\t\t\tconst rolled = roll(cleanedDice);\r\n\t\t\tif (!rolled)\r\n\t\t\t\tthrow new DiceTypeError(cleanedDice, \"verifyTemplateValue\", \"no roll result\");\r\n\t\t}\r\n\t}\r\n\ttestDiceRegistered(statistiqueTemplate);\r\n\ttestStatCombinaison(statistiqueTemplate);\r\n\treturn statistiqueTemplate;\r\n}\r\n\r\n/**\r\n * Test each damage roll from the template.damage\r\n * @param {StatisticalTemplate} template\r\n */\r\nexport function testDiceRegistered(template: StatisticalTemplate) {\r\n\tif (!template.damage) return;\r\n\tif (Object.keys(template.damage).length === 0) throw new EmptyObjectError();\r\n\tif (Object.keys(template.damage).length > 25) throw new TooManyDice();\r\n\tfor (const [name, dice] of Object.entries(template.damage)) {\r\n\t\tif (!dice) continue;\r\n\t\tconst diceReplaced = replaceExpByRandom(dice);\r\n\t\tconst randomDiceParsed = diceRandomParse(diceReplaced, template);\r\n\t\ttry {\r\n\t\t\tconst rolled = roll(randomDiceParsed);\r\n\t\t\tif (!rolled) throw new DiceTypeError(name, \"no_roll_result\", dice);\r\n\t\t} catch (error) {\r\n\t\t\tconsole.error(error);\r\n\t\t\tthrow new DiceTypeError(name, \"testDiceRegistered\", error);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n/**\r\n * Test all combinaison with generated random value\r\n * @param {StatisticalTemplate} template\r\n */\r\nexport function testStatCombinaison(template: StatisticalTemplate) {\r\n\tif (!template.statistics) return;\r\n\tconst onlycombinaisonStats = Object.fromEntries(\r\n\t\tObject.entries(template.statistics).filter(\r\n\t\t\t([_, value]) => value.combinaison !== undefined\r\n\t\t)\r\n\t);\r\n\tconst allOtherStats = Object.fromEntries(\r\n\t\tObject.entries(template.statistics).filter(([_, value]) => !value.combinaison)\r\n\t);\r\n\tif (Object.keys(onlycombinaisonStats).length === 0) return;\r\n\tconst allStats = Object.keys(template.statistics).filter(\r\n\t\t(stat) => !template.statistics![stat].combinaison\r\n\t);\r\n\tif (allStats.length === 0) throw new NoStatisticsError();\r\n\tconst error = [];\r\n\tfor (const [stat, value] of Object.entries(onlycombinaisonStats)) {\r\n\t\tlet formula = value.combinaison as string;\r\n\t\tfor (const [other, data] of Object.entries(allOtherStats)) {\r\n\t\t\tconst { max, min } = data;\r\n\t\t\tconst total = template.total || 100;\r\n\t\t\tconst randomStatValue = generateRandomStat(total, max, min);\r\n\t\t\tconst regex = new RegExp(other, \"gi\");\r\n\t\t\tformula = formula.replace(regex, randomStatValue.toString());\r\n\t\t}\r\n\t\ttry {\r\n\t\t\tevaluate(formula);\r\n\t\t} catch (e) {\r\n\t\t\terror.push(stat);\r\n\t\t}\r\n\t}\r\n\tif (error.length > 0) throw new FormulaError(error.join(\", \"), \"testStatCombinaison\");\r\n\treturn;\r\n}\r\n\r\n/**\r\n * Generate a random stat based on the template and the statistical min and max\r\n * @param {number|undefined} total\r\n * @param {number | undefined} max\r\n * @param {number | undefined} min\r\n * @returns\r\n */\r\nexport function generateRandomStat(\r\n\ttotal: number | undefined = 100,\r\n\tmax?: number,\r\n\tmin?: number\r\n) {\r\n\tlet randomStatValue = total + 1;\r\n\twhile (randomStatValue >= total || randomStatValue === 0) {\r\n\t\tconst random = new Random();\r\n\t\tif (max && min) randomStatValue = random.integer(min, max);\r\n\t\telse if (max) randomStatValue = random.integer(1, max);\r\n\t\telse if (min) randomStatValue = random.integer(min, total);\r\n\t\telse randomStatValue = random.integer(1, total);\r\n\t}\r\n\treturn randomStatValue;\r\n}\r\n","export class DiceTypeError extends Error {\n\tpublic readonly dice: string;\n\tpublic readonly cause: string | undefined;\n\tpublic readonly method: unknown;\n\n\tconstructor(dice: string, cause?: string, method?: unknown) {\n\t\tsuper(dice);\n\t\tthis.name = \"Invalid_Dice_Type\";\n\t\tthis.dice = dice;\n\t\tthis.cause = cause;\n\t\tthis.method = method;\n\t}\n}\n\nexport class FormulaError extends Error {\n\tpublic readonly formula: string;\n\tpublic readonly cause: string | undefined;\n\tpublic readonly method: unknown;\n\n\tconstructor(formula: string, cause?: string, method?: unknown) {\n\t\tsuper(formula);\n\t\tthis.name = \"Invalid_Formula\";\n\t\tthis.formula = formula;\n\t\tthis.cause = cause;\n\t\tthis.method = method;\n\t}\n}\n\nexport class MaxGreater extends Error {\n\tpublic readonly name: string;\n\tpublic readonly value: number;\n\tpublic readonly max: number;\n\n\tconstructor(value: number, max: number) {\n\t\tsuper(value.toString());\n\t\tthis.name = \"Max_Greater\";\n\t\tthis.value = value;\n\t\tthis.max = max;\n\t}\n}\n\nexport class EmptyObjectError extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Empty_Object\";\n\t}\n}\n\nexport class TooManyDice extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Too_Many_Dice\";\n\t}\n}\n\nexport class TooManyStats extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Too_Many_Stats\";\n\t}\n}\n\nexport class NoStatisticsError extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"No_Statistics\";\n\t}\n}\n","export const COMMENT_REGEX = /\\s+(#|\\/{2}|\\[|\\/\\*)(?<comment>.*)/;\r\nexport const SIGN_REGEX = /[><=!]+/;\r\nexport const SIGN_REGEX_SPACE = /[><=!]+(\\S+)/;\r\n\r\nexport const SYMBOL_DICE = \"&\";\r\n","/**\n * Definition of the Zod schema for template data\n */\nimport { z } from \"zod\";\n\nconst statisticValueSchema = z\n\t.object({\n\t\tmax: z.number().min(0).transform(val => val === 0 ? undefined : val).optional(),\n\t\tmin: z.number().min(0).transform(val => val === 0 ? undefined : val).optional(),\n\t\tcombinaison: z\n\t\t\t.string()\n\t\t\t.transform((str) => str.trim() || undefined)\n\t\t\t.optional(),\n\t\texclude: z.boolean().optional(),\n\t})\n\t.superRefine((data, ctx) => {\n\t\t\n\t\tif (data.max !== undefined && data.min !== undefined && data.max <= data.min) {\n\t\t\tctx.addIssue({\n\t\t\t\tcode: \"custom\",\n\t\t\t\tmessage: `Max_Greater; ${data.min}; ${data.max}`,\n\t\t\t\tpath: [\"max\"],\n\t\t\t});\n\t\t}\n\t});\n\nconst statisticSchema = z\n\t.record(statisticValueSchema)\n\t.optional()\n\t.refine((stats) => !stats || Object.keys(stats).length <= 25, {\n\t\tmessage: \"TooManyStats\",\n\t});\n\nconst criticalSchema = z\n\t.object({\n\t\tsuccess: z.string().or(z.number().min(0)).optional(),\n\t\tfailure: z.string().or(z.number().min(0)).optional(),\n\t})\n\t.transform((values) => {\n\t\tif (values.success === \"\") values.success = undefined;\n\t\tif (values.failure === \"\") values.failure = undefined;\n\t\tif (values.failure === 0) values.failure = undefined;\n\t\tif (values.success === 0) values.success = undefined;\n\t\tvalues.success = Number.parseInt(values.success as string, 10);\n\t\tvalues.failure = Number.parseInt(values.failure as string, 10);\n\t\treturn values;\n\t});\n\nconst criticalValueSchema = z.object({\n\tsign: z.enum([\"<\", \">\", \"<=\", \">=\", \"!=\", \"==\"]),\n\tvalue: z.string(),\n\tonNaturalDice: z.boolean().optional(),\n\taffectSkill: z.boolean().optional(),\n});\n\nconst damageSchema = z\n\t.record(z.string())\n\t.optional()\n\t.refine((stats) => !stats || Object.keys(stats).length <= 25, {\n\t\tmessage: \"TooManyDice\",\n\t});\n\nconst customCriticalSchema = z\n\t.record(criticalValueSchema)\n\t.optional()\n\t.refine((stats) => !stats || Object.keys(stats).length <= 22, {\n\t\tmessage: \"TooManyDice\",\n\t});\n\nexport const templateSchema = z.object({\n\tcharName: z.boolean().optional(),\n\tstatistics: statisticSchema,\n\ttotal: z.number().min(0).transform(val => val === 0 ? undefined : val).optional(),\n\tforceDistrib: z.boolean().optional(),\n\tdiceType: z.string().optional(),\n\tcritical: criticalSchema.optional(),\n\tcustomCritical: customCriticalSchema,\n\tdamage: damageSchema,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;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,SAAmB,EAAE;AAC7D,SAAO;AACR,CAAC;AAEF,IAAM,sBAAsB,aAAE,OAAO;AAAA,EACpC,MAAM,aAAE,KAAK,CAAC,KAAK,KAAK,MAAM,MAAM,MAAM,IAAI,CAAC;AAAA,EAC/C,OAAO,aAAE,OAAO;AAAA,EAChB,eAAe,aAAE,QAAQ,EAAE,SAAS;AAAA,EACpC,aAAa,aAAE,QAAQ,EAAE,SAAS;AACnC,CAAC;AAED,IAAM,eAAe,aACnB,OAAO,aAAE,OAAO,CAAC,EACjB,SAAS,EACT,OAAO,CAAC,UAAU,CAAC,SAAS,OAAO,KAAK,KAAK,EAAE,UAAU,IAAI;AAAA,EAC7D,SAAS;AACV,CAAC;AAEF,IAAM,uBAAuB,aAC3B,OAAO,mBAAmB,EAC1B,SAAS,EACT,OAAO,CAAC,UAAU,CAAC,SAAS,OAAO,KAAK,KAAK,EAAE,UAAU,IAAI;AAAA,EAC7D,SAAS;AACV,CAAC;AAEK,IAAM,iBAAiB,aAAE,OAAO;AAAA,EACtC,UAAU,aAAE,QAAQ,EAAE,SAAS;AAAA,EAC/B,YAAY;AAAA,EACZ,OAAO,aAAE,OAAO,EAAE,IAAI,CAAC,EAAE,UAAU,SAAO,QAAQ,IAAI,SAAY,GAAG,EAAE,SAAS;AAAA,EAChF,cAAc,aAAE,QAAQ,EAAE,SAAS;AAAA,EACnC,UAAU,aAAE,OAAO,EAAE,SAAS;AAAA,EAC9B,UAAU,eAAe,SAAS;AAAA,EAClC,gBAAgB;AAAA,EAChB,QAAQ;AACT,CAAC;","names":["import_mathjs","roller","evaluateRoll","diceResult","import_mathjs","import_uniformize","cleanedDice","random"]}
|
package/dist/index.mjs
CHANGED
@@ -453,7 +453,8 @@ function verifyTemplateValue(template, verify = true) {
|
|
453
453
|
total: parsedTemplate.total,
|
454
454
|
charName: parsedTemplate.charName,
|
455
455
|
damage: parsedTemplate.damage,
|
456
|
-
customCritical: parsedTemplate.customCritical
|
456
|
+
customCritical: parsedTemplate.customCritical,
|
457
|
+
forceDistrib: parsedTemplate.forceDistrib
|
457
458
|
};
|
458
459
|
if (!verify) return statistiqueTemplate;
|
459
460
|
if (statistiqueTemplate.diceType) {
|
@@ -665,7 +666,8 @@ var customCriticalSchema = z.record(criticalValueSchema).optional().refine((stat
|
|
665
666
|
var templateSchema = z.object({
|
666
667
|
charName: z.boolean().optional(),
|
667
668
|
statistics: statisticSchema,
|
668
|
-
total: z.number().min(0).optional(),
|
669
|
+
total: z.number().min(0).transform((val) => val === 0 ? void 0 : val).optional(),
|
670
|
+
forceDistrib: z.boolean().optional(),
|
669
671
|
diceType: z.string().optional(),
|
670
672
|
critical: criticalSchema.optional(),
|
671
673
|
customCritical: customCriticalSchema,
|
package/dist/index.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/dice.ts","../src/utils.ts","../src/verify_template.ts","../src/errors.ts","../src/interfaces/constant.ts","../src/interfaces/zod.ts"],"sourcesContent":["import { DiceRoller } from \"@dice-roller/rpg-dice-roller\";\r\nimport { evaluate } from \"mathjs\";\r\n\r\nimport {\r\n\ttype Compare,\r\n\ttype ComparedValue,\r\n\ttype CustomCritical,\r\n\ttype Modifier,\r\n\ttype Resultat,\r\n\ttype Sign,\r\n\ttype StatisticalTemplate,\r\n\tdiceTypeRandomParse,\r\n\tstandardizeDice,\r\n\tDiceTypeError,\r\n\tCOMMENT_REGEX,\r\n\tSIGN_REGEX,\r\n\tSIGN_REGEX_SPACE,\r\n\tSYMBOL_DICE,\r\n} from \".\";\r\nimport { isNumber } from \"./utils\";\r\n\r\nfunction getCompare(\r\n\tdice: string,\r\n\tcompareRegex: RegExpMatchArray\r\n): { dice: string; compare: ComparedValue | undefined } {\r\n\t/**\r\n\t * @source: https://dice-roller.github.io/documentation/guide/notation/modifiers.html#target-success-dice-pool\r\n\t * Some system count the number of a dice that are greater than or equal to a target, and not the \"total\" of rolled dice.\r\n\t * We \"count\" the number of dice that meet a criterion, and not the total of the dice.\r\n\t * To support this, we use the group notation. It a little different than the notation of dice-roller, but it a sacrifice to not break the current notation.\r\n\t * @note:\r\n\t * - `{2d3}>=4` will be the same as `2d3>=4` and thus keep the comparaison.\r\n\t * - `{2d3>=4}` will count the total of dice that are greater than or equal to 4, and not the total of the dice.\r\n\t * - `{2d3,1d4}>=4` won't use the comparison, but will count the number of dice that are greater than or equal to 4. If the total of the dice is needed, just remove the group notation and use `2d3+1d4>=4`.\r\n\t */\r\n\tif (dice.match(/((\\{.*,(.*)+\\}|([><=!]+\\d+f))[><=!]+\\d+\\}?)|\\{(.*)([><=!]+).*\\}/)) return { dice, compare: undefined };\r\n\tdice = dice.replace(SIGN_REGEX_SPACE, \"\");\r\n\tlet compare: ComparedValue;\r\n\tconst calc = compareRegex[1];\r\n\tconst sign = calc.match(/[+-\\/*^]/)?.[0];\r\n\tconst compareSign = compareRegex[0].match(SIGN_REGEX)?.[0];\r\n\t\r\n\t\r\n\tif (sign) {\r\n\t\tconst toCalc = calc.replace(SIGN_REGEX, \"\").replace(/\\s/g, \"\").replace(/;(.*)/, \"\");\r\n\t\tconst rCompare = rollCompare(toCalc);\r\n\t\tconst total = evaluate(rCompare.value.toString());\r\n\t\tdice = dice.replace(SIGN_REGEX_SPACE, `${compareSign}${total}`);\r\n\t\tcompare = {\r\n\t\t\tsign: compareSign as \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\",\r\n\t\t\tvalue: total,\r\n\t\t\toriginalDice: rCompare.dice,\r\n\t\t\trollValue: rCompare.diceResult,\r\n\t\t};\r\n\t} else {\r\n\t\tconst rcompare = rollCompare(calc);\r\n\t\tcompare = {\r\n\t\t\tsign: compareSign as \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\",\r\n\t\t\tvalue: rcompare.value,\r\n\t\t\toriginalDice: rcompare.dice,\r\n\t\t\trollValue: rcompare.diceResult,\r\n\t\t};\r\n\t}\r\n\treturn { dice, compare };\r\n}\r\n\r\nfunction rollCompare(value: unknown) {\r\n\tif (isNumber(value)) return { value: Number.parseInt(value as string, 10) };\r\n\tconst rollComp = roll(value as string);\r\n\tif (!rollComp?.total)\r\n\t\t//not a dice throw\r\n\t\treturn { value: evaluate(value as string), diceResult: value as string };\r\n\treturn {\r\n\t\tdice: value as string,\r\n\t\tvalue: rollComp.total,\r\n\t\tdiceResult: rollComp?.result,\r\n\t};\r\n}\r\n\r\n/**\r\n * Allow to replace the compare part of a dice and use the critical customized one\r\n * @example\r\n * dice = \"1d20=20\";\r\n * custom critical {sign: \">\", value: \"$/2\"}\r\n * Random stats = 6\r\n * result = \"1d20>3\"\r\n */\r\nexport function createCriticalCustom(\r\n\tdice: string,\r\n\tcustomCritical: CustomCritical,\r\n\ttemplate: StatisticalTemplate\r\n) {\r\n\tconst compareRegex = dice.match(SIGN_REGEX_SPACE);\r\n\tlet customDice = dice;\r\n\tconst compareValue = diceTypeRandomParse(customCritical.value, template);\r\n\tif (compareValue.includes(\"$\"))\r\n\t\tthrow new DiceTypeError(compareValue, \"createCriticalCustom\");\r\n\tconst comparaison = `${customCritical.sign}${compareValue}`;\r\n\tif (compareRegex) customDice = customDice.replace(SIGN_REGEX_SPACE, comparaison);\r\n\telse customDice += comparaison;\r\n\treturn diceTypeRandomParse(customDice, template);\r\n}\r\n\r\nfunction getModifier(dice: string) {\r\n\tconst modifier = dice.matchAll(/(\\+|-|%|\\/|\\^|\\*|\\*{2})(\\d+)/gi);\r\n\tlet modificator: Modifier | undefined;\r\n\tfor (const mod of modifier) {\r\n\t\t//calculate the modifier if multiple\r\n\t\tif (modificator) {\r\n\t\t\tconst sign = modificator.sign;\r\n\t\t\tlet value = modificator.value;\r\n\t\t\tif (sign) value = calculator(sign, value, Number.parseInt(mod[2], 10));\r\n\t\t\tmodificator = {\r\n\t\t\t\tsign: mod[1] as Sign,\r\n\t\t\t\tvalue,\r\n\t\t\t};\r\n\t\t} else {\r\n\t\t\tmodificator = {\r\n\t\t\t\tsign: mod[1] as Sign,\r\n\t\t\t\tvalue: Number.parseInt(mod[2], 10),\r\n\t\t\t};\r\n\t\t}\r\n\t}\r\n\treturn modificator;\r\n}\r\n\r\n/**\r\n * Parse the string provided and turn it as a readable dice for dice parser\r\n * @param dice {string}\r\n */\r\nexport function roll(dice: string): Resultat | undefined {\r\n\t//parse dice string\r\n\tdice = standardizeDice(dice).replace(/^\\+/, \"\").trimStart();\r\n\tif (!dice.includes(\"d\")) return undefined;\r\n\tconst compareRegex = dice.match(SIGN_REGEX_SPACE);\r\n\tlet compare: ComparedValue | undefined;\r\n\tif (dice.includes(\";\")) return sharedRolls(dice);\r\n\tif (compareRegex) {\r\n\t\tconst compareResult = getCompare(dice, compareRegex);\r\n\t\tdice = compareResult.dice;\r\n\t\tcompare = compareResult.compare;\r\n\t}\r\n\tconst modificator = getModifier(dice);\r\n\r\n\tif (dice.match(/\\d+?#(.*)/)) {\r\n\t\tconst diceArray = dice.split(\"#\");\r\n\t\tconst numberOfDice = Number.parseInt(diceArray[0], 10);\r\n\t\tconst diceToRoll = diceArray[1].replace(COMMENT_REGEX, \"\");\r\n\t\tconst commentsMatch = diceArray[1].match(COMMENT_REGEX);\r\n\t\tconst comments = commentsMatch ? commentsMatch[2] : undefined;\r\n\t\tconst roller = new DiceRoller();\r\n\t\t//remove comments if any\r\n\t\tfor (let i = 0; i < numberOfDice; i++) {\r\n\t\t\ttry {\r\n\t\t\t\troller.roll(diceToRoll);\r\n\t\t\t} catch (error) {\r\n\t\t\t\tthrow new DiceTypeError(diceToRoll, \"roll\", error);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn {\r\n\t\t\tdice: diceToRoll,\r\n\t\t\tresult: roller.output,\r\n\t\t\tcomment: comments,\r\n\t\t\tcompare: compare ? compare : undefined,\r\n\t\t\tmodifier: modificator,\r\n\t\t\ttotal: roller.total,\r\n\t\t};\r\n\t}\r\n\tconst roller = new DiceRoller();\r\n\tconst diceWithoutComment = dice.replace(COMMENT_REGEX, \"\").trimEnd();\r\n\ttry {\r\n\t\troller.roll(diceWithoutComment);\r\n\t} catch (error) {\r\n\t\tthrow new DiceTypeError(diceWithoutComment, \"roll\", error);\r\n\t}\r\n\tconst commentMatch = dice.match(COMMENT_REGEX);\r\n\tconst comment = commentMatch ? commentMatch[2] : undefined;\r\n\treturn {\r\n\t\tdice,\r\n\t\tresult: roller.output,\r\n\t\tcomment,\r\n\t\tcompare: compare ? compare : undefined,\r\n\t\tmodifier: modificator,\r\n\t\ttotal: roller.total,\r\n\t};\r\n}\r\n/**\r\n * Evaluate a formula and replace \"^\" by \"**\" if any\r\n * @param {Sign} sign\r\n * @param {number} value\r\n * @param {number} total\r\n * @returns\r\n */\r\nexport function calculator(sign: Sign, value: number, total: number): number {\r\n\tif (sign === \"^\") sign = \"**\";\r\n\treturn evaluate(`${total} ${sign} ${value}`);\r\n}\r\n\r\nfunction inverseSign(\r\n\tsign: \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\"\r\n): \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\" {\r\n\tswitch (sign) {\r\n\t\tcase \"<\":\r\n\t\t\treturn \">\";\r\n\t\tcase \">\":\r\n\t\t\treturn \"<\";\r\n\t\tcase \"<=\":\r\n\t\t\treturn \">=\";\r\n\t\tcase \">=\":\r\n\t\t\treturn \"<=\";\r\n\t\tcase \"=\":\r\n\t\t\treturn \"!=\";\r\n\t\tcase \"==\":\r\n\t\t\treturn \"!=\";\r\n\t\tcase \"!=\":\r\n\t\t\treturn \"==\";\r\n\t}\r\n}\r\n\r\nfunction replaceInFormula(\r\n\telement: string,\r\n\tdiceResult: Resultat,\r\n\tcompareResult: { dice: string; compare: Compare | undefined },\r\n\tres: boolean\r\n) {\r\n\tconst { formule, diceAll } = replaceText(\r\n\t\telement,\r\n\t\tdiceResult.total ?? 0,\r\n\t\tdiceResult.dice\r\n\t);\r\n\tconst validSign = res ? \"✓\" : \"✕\";\r\n\tconst invertedSign = res\r\n\t\t? compareResult.compare!.sign\r\n\t\t: inverseSign(compareResult.compare!.sign);\r\n\tlet evaluateRoll: unknown;\r\n\ttry {\r\n\t\tevaluateRoll = evaluate(compareResult.dice);\r\n\t\treturn `${validSign} ${diceAll}: ${formule} = ${evaluateRoll}${invertedSign}${compareResult.compare?.value}`;\r\n\t} catch (error) {\r\n\t\tconst evaluateRoll = roll(compareResult.dice) as Resultat | undefined;\r\n\t\tif (evaluateRoll)\r\n\t\t\treturn `${validSign} ${diceAll}: ${evaluateRoll.result.split(\":\").splice(1).join(\":\")}`;\r\n\r\n\t\treturn `${validSign} ${diceAll}: ${formule} = ${evaluateRoll}${invertedSign}${compareResult.compare?.value}`;\r\n\t}\r\n}\r\n\r\nfunction compareSignFormule(\r\n\ttoRoll: string,\r\n\tcompareRegex: RegExpMatchArray,\r\n\telement: string,\r\n\tdiceResult: Resultat\r\n) {\r\n\tlet results = \"\";\r\n\tconst compareResult = getCompare(toRoll, compareRegex);\r\n\tconst toCompare = `${compareResult.dice}${compareResult.compare?.sign}${compareResult.compare?.value}`;\r\n\tlet res: unknown;\r\n\ttry {\r\n\t\tres = evaluate(toCompare);\r\n\t} catch (error) {\r\n\t\tres = roll(toCompare);\r\n\t}\r\n\tif (typeof res === \"boolean\") {\r\n\t\tresults = replaceInFormula(element, diceResult, compareResult, res);\r\n\t} else if (res instanceof Object) {\r\n\t\tconst diceResult = res as Resultat;\r\n\t\tif (diceResult.compare) {\r\n\t\t\tconst toEvaluate = evaluate(\r\n\t\t\t\t`${diceResult.total}${diceResult.compare.sign}${diceResult.compare.value}`\r\n\t\t\t);\r\n\t\t\tconst sign = toEvaluate ? \"✓\" : \"✕\";\r\n\t\t\tconst invertedSign = toEvaluate\r\n\t\t\t\t? diceResult.compare.sign\r\n\t\t\t\t: inverseSign(diceResult.compare.sign);\r\n\t\t\tconst dice = replaceText(element, 0, diceResult.dice).diceAll;\r\n\r\n\t\t\tresults = `${sign} ${dice}: ${diceResult.result.split(\":\").splice(1).join(\":\").trim()}${invertedSign}${diceResult.compare.value}`;\r\n\t\t}\r\n\t}\r\n\treturn { dice: compareResult.dice, results };\r\n}\r\n\r\nfunction replaceText(element: string, total: number, dice: string) {\r\n\treturn {\r\n\t\tformule: element.replace(SYMBOL_DICE, `[${total}]`).replace(/%.*%/g, \"\").trim(),\r\n\t\tdiceAll: element\r\n\t\t\t.replace(SYMBOL_DICE, `[${dice.replace(COMMENT_REGEX, \"\")}]`)\r\n\t\t\t.replace(/%.*%/g, \"\")\r\n\t\t\t.trim(),\r\n\t};\r\n}\r\n\r\nfunction formatComment(dice: string) {\r\n\tconst commentsRegex = /\\[(?<comments>.*?)\\]/;\r\n\tconst commentsMatch = commentsRegex.exec(dice);\r\n\treturn commentsMatch?.groups?.comments ? `__${commentsMatch.groups.comments}__ — ` : \"\";\r\n}\r\n\r\nfunction sharedRolls(dice: string): Resultat | undefined {\r\n\tif (dice.match(/\\d+?#(.*?)/))\r\n\t\tthrow new DiceTypeError(\r\n\t\t\tdice,\r\n\t\t\t\"noBulkRoll\",\r\n\t\t\t\"bulk roll are not allowed in shared rolls\"\r\n\t\t);\r\n\tconst results = [];\r\n\tconst mainComment =\r\n\t\t/\\s+#(?<comment>.*)/.exec(dice)?.groups?.comment?.trimEnd() ?? undefined;\r\n\tconst split = dice.split(\";\");\r\n\tlet diceMain = split[0];\r\n\tconst toHideRegex = /(?<!\\[[^\\]]*)\\((?<dice>[^)]+)\\)/;\r\n\tconst toHide = toHideRegex.exec(diceMain)?.groups;\r\n\tlet hidden = false;\r\n\tif (toHide?.dice) {\r\n\t\tdiceMain = toHide.dice;\r\n\t\thidden = true;\r\n\t} else if (toHide) {\r\n\t\tdiceMain = \"1d1\";\r\n\t\thidden = true;\r\n\t}\r\n\tconst commentsRegex = /\\[(?<comments>.*?)\\]/gi;\r\n\tconst comments = formatComment(diceMain);\r\n\tdiceMain = diceMain.replaceAll(commentsRegex, \"\").trim();\r\n\tconst diceResult = roll(diceMain);\r\n\tif (!diceResult || !diceResult.total) return undefined;\r\n\tresults.push(`※ ${comments}${diceResult.result}`);\r\n\tlet total = diceResult.total;\r\n\tdiceResult.comment = mainComment;\r\n\tif (!total) return diceResult;\r\n\tfor (let element of split.slice(1)) {\r\n\t\tconst comment = formatComment(element);\r\n\t\telement = element.replace(commentsRegex, \"\").trim();\r\n\t\tlet toRoll = element.replace(SYMBOL_DICE, `${diceResult.total}`);\r\n\t\tconst compareRegex = toRoll.match(SIGN_REGEX_SPACE);\r\n\t\tif (compareRegex) {\r\n\t\t\tconst compareResult = compareSignFormule(toRoll, compareRegex, element, diceResult);\r\n\t\t\ttoRoll = compareResult.dice;\r\n\t\t\tresults.push(compareResult.results);\r\n\t\t} else {\r\n\t\t\tconst { formule, diceAll } = replaceText(\r\n\t\t\t\telement,\r\n\t\t\t\tdiceResult.total,\r\n\t\t\t\tdiceResult.dice\r\n\t\t\t);\r\n\r\n\t\t\ttry {\r\n\t\t\t\tconst evaluated = evaluate(toRoll);\r\n\t\t\t\tresults.push(`◈ ${comment}${diceAll}: ${formule} = ${evaluated}`);\r\n\t\t\t\ttotal += Number.parseInt(evaluated, 10);\r\n\t\t\t} catch (error) {\r\n\t\t\t\tconst evaluated = roll(toRoll);\r\n\t\t\t\tif (evaluated)\r\n\t\t\t\t\tresults.push(\r\n\t\t\t\t\t\t`◈ ${comment}${diceAll}: ${evaluated.result.split(\":\").slice(1).join(\":\")}`\r\n\t\t\t\t\t);\r\n\t\t\t\telse results.push(`◈ ${comment}${diceAll}: ${formule} = ${evaluated}`);\r\n\t\t\t\ttotal += evaluated?.total ?? 0;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tif (hidden)\r\n\t\t//remove the first in result\r\n\t\tresults.shift();\r\n\treturn {\r\n\t\tdice: diceMain,\r\n\t\tresult: results.join(\";\"),\r\n\t\tcomment: mainComment,\r\n\t\tcompare: diceResult.compare,\r\n\t\tmodifier: diceResult.modifier,\r\n\t\ttotal,\r\n\t};\r\n}\r\n","import {evaluate, randomInt} from \"mathjs\";\r\nimport \"uniformize\";\r\nimport { FormulaError } from \".\";\r\n\r\n/**\r\n * Escape regex string\r\n * @param string {string}\r\n */\r\nexport function escapeRegex(string: string) {\r\n\treturn string.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\r\n}\r\n\r\n/**\r\n * Allow to keep the text as if in brackets\r\n * @param dice {string}\r\n * @return {string} the dice with the text in brackets as if, but the dice (not in brackets) is standardized\r\n */\r\nexport function standardizeDice(dice: string): string {\r\n\treturn dice.replace(\r\n\t\t/(\\[[^\\]]+\\])|([^[]+)/g,\r\n\t\t(match, insideBrackets, outsideText) =>\r\n\t\t\tinsideBrackets ? insideBrackets : outsideText.standardize(),\r\n\t);\r\n}\r\n\r\n/**\r\n * Replace the stat name by their value using stat\r\n * and after evaluate any formula using `replaceFormulaInDice`\r\n * @param {string} originalDice\r\n * @param {Record<string,number>|undefined} stats\r\n * @param {string|undefined} dollarValue\r\n */\r\nexport function generateStatsDice(\r\n\toriginalDice: string,\r\n\tstats?: Record<string, number>,\r\n\tdollarValue?: string,\r\n) {\r\n\tlet dice = originalDice.standardize();\r\n\tif (stats && Object.keys(stats).length > 0) {\r\n\t\t//damage field support adding statistic, like : 1d6 + strength\r\n\t\t//check if the value contains a statistic & calculate if it's okay\r\n\t\t//the dice will be converted before roll\r\n\t\tconst allStats = Object.keys(stats);\r\n\t\tfor (const stat of allStats) {\r\n\t\t\tconst regex = new RegExp(\r\n\t\t\t\t`(?!\\\\[)${escapeRegex(stat.standardize())}(?!\\\\])`,\r\n\t\t\t\t\"gi\",\r\n\t\t\t);\r\n\t\t\tif (dice.match(regex)) {\r\n\t\t\t\tconst statValue = stats[stat];\r\n\t\t\t\tdice = dice.replace(regex, statValue.toString());\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tif (dollarValue) dice = dice.replaceAll(\"$\", dollarValue);\r\n\treturn replaceFormulaInDice(dice);\r\n}\r\n\r\n/**\r\n * Replace the {{}} in the dice string and evaluate the interior if any\r\n * @param dice {string}\r\n */\r\nexport function replaceFormulaInDice(dice: string) {\r\n\tconst formula = /(?<formula>\\{{2}(.+?)}{2})/gim;\r\n\tlet match;\r\n\tlet modifiedDice = dice;\r\n\t// biome-ignore lint/suspicious/noAssignInExpressions: best way to regex in a loop\r\n\twhile ((match = formula.exec(dice)) !== null) {\r\n\t\tif (match.groups?.formula) {\r\n\t\t\tconst formulae = match.groups.formula\r\n\t\t\t\t.replaceAll(\"{{\", \"\")\r\n\t\t\t\t.replaceAll(\"}}\", \"\");\r\n\t\t\ttry {\r\n\t\t\t\tconst result = evaluate(formulae);\r\n\t\t\t\tmodifiedDice = modifiedDice.replace(\r\n\t\t\t\t\tmatch.groups.formula,\r\n\t\t\t\t\tresult.toString(),\r\n\t\t\t\t);\r\n\t\t\t} catch (error) {\r\n\t\t\t\tthrow new FormulaError(\r\n\t\t\t\t\tmatch.groups.formula,\r\n\t\t\t\t\t\"replaceFormulasInDice\",\r\n\t\t\t\t\terror,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn cleanedDice(modifiedDice);\r\n}\r\n\r\n/**\r\n * Replace the ++ +- -- by their proper value:\r\n * - `++` = `+`\r\n * - `+-` = `-`\r\n * - `--` = `+`\r\n * @param dice {string}\r\n */\r\nfunction cleanedDice(dice: string) {\r\n\treturn dice\r\n\t\t.replaceAll(\"+-\", \"-\")\r\n\t\t.replaceAll(\"--\", \"+\")\r\n\t\t.replaceAll(\"++\", \"+\")\r\n\t\t.trimEnd();\r\n}\r\n\r\n/**\r\n * Verify if a value is a number, even if it's a \"number\" string\r\n * @param value {unknown}\r\n * @returns {boolean}\r\n */\r\nexport function isNumber(value: unknown): boolean {\r\n\treturn (\r\n\t\tvalue !== undefined &&\r\n\t\t(typeof value === \"number\" ||\r\n\t\t\t(!Number.isNaN(Number(value)) &&\r\n\t\t\t\ttypeof value === \"string\" &&\r\n\t\t\t\tvalue.trim().length > 0))\r\n\t);\r\n}\r\n\r\n/**\r\n * Replace the `{exp}` in the dice.\r\n * If the `{exp}` has a default value in the form of `{exp || defaultValue}`, it will be replaced by the default value.\r\n * @param {string} dice\r\n * @returns {string} the dice with the {exp} replaced by a random value\r\n */\r\nexport function replaceExpByRandom(dice: string): string {\r\n\tconst diceRegex = /\\{exp( ?\\|\\| ?(?<default>\\d+))?}/gi\r\n\treturn dice.replace(diceRegex, (_match, _p1, _p2, _offset, _string, groups) => {\r\n\t\tconst defaultValue = groups?.default;\r\n\t\treturn defaultValue ?? randomInt(1, 999).toString();\r\n\t});\r\n}","import {evaluate, random, randomInt} from \"mathjs\";\r\nimport { Random } from \"random-js\";\r\nimport \"uniformize\";\r\n\r\nimport {\r\n\ttype StatisticalTemplate,\r\n\tcreateCriticalCustom,\r\n\troll,\r\n\tDiceTypeError,\r\n\tEmptyObjectError,\r\n\tFormulaError,\r\n\tNoStatisticsError,\r\n\tescapeRegex,\r\n\treplaceFormulaInDice,\r\n\ttemplateSchema,\r\n\tTooManyDice, replaceExpByRandom,\r\n} from \".\";\r\nimport { isNumber } from \"./utils\";\r\n\r\n/**\r\n * Verify if the provided dice work with random value\r\n * @param testDice {string}\r\n * @param allStats {Record<string,number>}\r\n */\r\nexport function evalStatsDice(testDice: string, allStats?: Record<string, number>) {\r\n\tlet dice = testDice.trimEnd();\r\n\tif (allStats && Object.keys(allStats).length > 0) {\r\n\t\tconst names = Object.keys(allStats);\r\n\t\tfor (const name of names) {\r\n\t\t\tconst regex = new RegExp(escapeRegex(name.standardize()), \"gi\");\r\n\t\t\tif (dice.standardize().match(regex)) {\r\n\t\t\t\tconst statValue = allStats[name];\r\n\t\t\t\tdice = dice.standardize().replace(regex, statValue.toString()).trimEnd();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\ttry {\r\n\t\tif (!roll(replaceFormulaInDice(replaceExpByRandom(dice))))\r\n\t\t\tthrow new DiceTypeError(dice, \"evalStatsDice\", \"no roll result\");\r\n\t\treturn testDice;\r\n\t} catch (error) {\r\n\t\tthrow new DiceTypeError(dice, \"evalStatsDice\", error);\r\n\t}\r\n}\r\n\r\n/**\r\n * Generate a random dice and remove the formula (+ evaluate it)\r\n * Used for diceDamage only\r\n * @param value {string}\r\n * @param template {StatisticalTemplate}\r\n * @returns\r\n */\r\nexport function diceRandomParse(value: string, template: StatisticalTemplate) {\r\n\tif (!template.statistics) return replaceFormulaInDice(value.standardize());\r\n\tvalue = value.standardize();\r\n\tconst statNames = Object.keys(template.statistics);\r\n\tlet newDice = value;\r\n\tfor (const name of statNames) {\r\n\t\tconst regex = new RegExp(escapeRegex(name.standardize()), \"gi\");\r\n\t\tif (value.match(regex)) {\r\n\t\t\tlet max: undefined | number = undefined;\r\n\t\t\tlet min: undefined | number = undefined;\r\n\t\t\tconst foundStat = template.statistics?.[name];\r\n\t\t\tif (foundStat) {\r\n\t\t\t\tmax = foundStat.max;\r\n\t\t\t\tmin = foundStat.min;\r\n\t\t\t}\r\n\t\t\tconst total = template.total || 100;\r\n\t\t\tconst randomStatValue = generateRandomStat(total, max, min);\r\n\t\t\tnewDice = value.replace(regex, randomStatValue.toString());\r\n\t\t}\r\n\t}\r\n\treturn replaceFormulaInDice(newDice);\r\n}\r\n\r\n/**\r\n * Same as damageDice but for DiceType\r\n * @param dice {string}\r\n * @param template {StatisticalTemplate}\r\n */\r\nexport function diceTypeRandomParse(dice: string, template: StatisticalTemplate) {\r\n\tdice = replaceExpByRandom(dice);\r\n\tif (!template.statistics) return dice;\r\n\tconst firstStatNotcombinaison = Object.keys(template.statistics).find(\r\n\t\t(stat) => !template.statistics?.[stat].combinaison\r\n\t);\r\n\tif (!firstStatNotcombinaison) return dice;\r\n\tconst stats = template.statistics[firstStatNotcombinaison];\r\n\tconst { min, max } = stats;\r\n\tconst total = template.total || 100;\r\n\tconst randomStatValue = generateRandomStat(total, max, min);\r\n\treturn replaceFormulaInDice(dice.replaceAll(\"$\", randomStatValue.toString()));\r\n}\r\n\r\n/**\r\n * Random the combinaison and evaluate it to check if everything is valid\r\n * @param combinaison {Record<string,string>}\r\n * @param stats {Record<string,number|number>}\r\n */\r\nexport function evalCombinaison(\r\n\tcombinaison: Record<string, string>,\r\n\tstats: Record<string, number | string>\r\n) {\r\n\tconst newStats: Record<string, number> = {};\r\n\tfor (const [stat, combin] of Object.entries(combinaison)) {\r\n\t\t//replace the stats in formula\r\n\t\tlet formula = combin.standardize();\r\n\t\tfor (const [statName, value] of Object.entries(stats)) {\r\n\t\t\tconst regex = new RegExp(statName.standardize(), \"gi\");\r\n\t\t\tformula = formula.replace(regex, value.toString());\r\n\t\t}\r\n\t\ttry {\r\n\t\t\tnewStats[stat] = evaluate(formula);\r\n\t\t} catch (error) {\r\n\t\t\tthrow new FormulaError(stat, \"evalCombinaison\", error);\r\n\t\t}\r\n\t}\r\n\treturn newStats;\r\n}\r\n\r\n/**\r\n * Evaluate one selected combinaison\r\n * @param combinaison {string}\r\n * @param stats {[name: string]: string|number}\r\n */\r\nexport function evalOneCombinaison(\r\n\tcombinaison: string,\r\n\tstats: Record<string, number | string>\r\n) {\r\n\tlet formula = combinaison.standardize();\r\n\tfor (const [statName, value] of Object.entries(stats)) {\r\n\t\tconst regex = new RegExp(statName.standardize(), \"gi\");\r\n\t\tformula = formula.replace(regex, value.toString());\r\n\t}\r\n\ttry {\r\n\t\treturn evaluate(formula);\r\n\t} catch (error) {\r\n\t\tthrow new FormulaError(combinaison, \"evalOneCombinaison\", error);\r\n\t}\r\n}\r\n\r\nfunction convertNumber(number: string | number | undefined) {\r\n\tif (!number) return undefined;\r\n\tif (number.toString().length === 0) return undefined;\r\n\tif (isNumber(number)) return Number.parseInt(number.toString(), 10);\r\n\treturn undefined;\r\n}\r\n\r\n/**\r\n * Parse the provided JSON and verify each field to check if everything could work when rolling\r\n * @param {unknown} template\r\n * @param {boolean} verify - If true, will roll the dices to check if everything is valid\r\n * @returns {StatisticalTemplate}\r\n */\r\nexport function verifyTemplateValue(template: unknown, verify: boolean=true): StatisticalTemplate {\r\n\tconst parsedTemplate = templateSchema.parse(template);\r\n\tconst { success, failure } = parsedTemplate.critical ?? {};\r\n\tconst criticicalVal = {\r\n\t\tsuccess: convertNumber(success),\r\n\t\tfailure: convertNumber(failure),\r\n\t};\r\n\tconst statistiqueTemplate: StatisticalTemplate = {\r\n\t\tdiceType: parsedTemplate.diceType,\r\n\t\tstatistics: parsedTemplate.statistics,\r\n\t\tcritical: criticicalVal,\r\n\t\ttotal: parsedTemplate.total,\r\n\t\tcharName: parsedTemplate.charName,\r\n\t\tdamage: parsedTemplate.damage,\r\n\t\tcustomCritical: parsedTemplate.customCritical,\r\n\t};\r\n\tif (!verify) return statistiqueTemplate;\r\n\tif (statistiqueTemplate.diceType) {\r\n\t\tconst cleanedDice = diceTypeRandomParse(\r\n\t\t\tstatistiqueTemplate.diceType,\r\n\t\t\tstatistiqueTemplate\r\n\t\t);\r\n\t\tconst rolled = roll(cleanedDice);\r\n\t\tif (!rolled) {\r\n\t\t\tthrow new DiceTypeError(cleanedDice, \"verifyTemplateValue\", \"no roll result\");\r\n\t\t}\r\n\t}\r\n\tif (statistiqueTemplate.customCritical) {\r\n\t\tif (!statistiqueTemplate.diceType) {\r\n\t\t\tthrow new DiceTypeError(\"no_dice_type\", \"verifyTemplateValue\", \"no dice type\");\r\n\t\t}\r\n\t\tconst customCritical = statistiqueTemplate.customCritical;\r\n\t\tfor (const [, custom] of Object.entries(customCritical)) {\r\n\t\t\tconst cleanedDice = createCriticalCustom(\r\n\t\t\t\tstatistiqueTemplate.diceType!,\r\n\t\t\t\tcustom,\r\n\t\t\t\tstatistiqueTemplate\r\n\t\t\t);\r\n\t\t\tconst rolled = roll(cleanedDice);\r\n\t\t\tif (!rolled)\r\n\t\t\t\tthrow new DiceTypeError(cleanedDice, \"verifyTemplateValue\", \"no roll result\");\r\n\t\t}\r\n\t}\r\n\ttestDiceRegistered(statistiqueTemplate);\r\n\ttestStatCombinaison(statistiqueTemplate);\r\n\treturn statistiqueTemplate;\r\n}\r\n\r\n/**\r\n * Test each damage roll from the template.damage\r\n * @param {StatisticalTemplate} template\r\n */\r\nexport function testDiceRegistered(template: StatisticalTemplate) {\r\n\tif (!template.damage) return;\r\n\tif (Object.keys(template.damage).length === 0) throw new EmptyObjectError();\r\n\tif (Object.keys(template.damage).length > 25) throw new TooManyDice();\r\n\tfor (const [name, dice] of Object.entries(template.damage)) {\r\n\t\tif (!dice) continue;\r\n\t\tconst diceReplaced = replaceExpByRandom(dice);\r\n\t\tconst randomDiceParsed = diceRandomParse(diceReplaced, template);\r\n\t\ttry {\r\n\t\t\tconst rolled = roll(randomDiceParsed);\r\n\t\t\tif (!rolled) throw new DiceTypeError(name, \"no_roll_result\", dice);\r\n\t\t} catch (error) {\r\n\t\t\tconsole.error(error);\r\n\t\t\tthrow new DiceTypeError(name, \"testDiceRegistered\", error);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n/**\r\n * Test all combinaison with generated random value\r\n * @param {StatisticalTemplate} template\r\n */\r\nexport function testStatCombinaison(template: StatisticalTemplate) {\r\n\tif (!template.statistics) return;\r\n\tconst onlycombinaisonStats = Object.fromEntries(\r\n\t\tObject.entries(template.statistics).filter(\r\n\t\t\t([_, value]) => value.combinaison !== undefined\r\n\t\t)\r\n\t);\r\n\tconst allOtherStats = Object.fromEntries(\r\n\t\tObject.entries(template.statistics).filter(([_, value]) => !value.combinaison)\r\n\t);\r\n\tif (Object.keys(onlycombinaisonStats).length === 0) return;\r\n\tconst allStats = Object.keys(template.statistics).filter(\r\n\t\t(stat) => !template.statistics![stat].combinaison\r\n\t);\r\n\tif (allStats.length === 0) throw new NoStatisticsError();\r\n\tconst error = [];\r\n\tfor (const [stat, value] of Object.entries(onlycombinaisonStats)) {\r\n\t\tlet formula = value.combinaison as string;\r\n\t\tfor (const [other, data] of Object.entries(allOtherStats)) {\r\n\t\t\tconst { max, min } = data;\r\n\t\t\tconst total = template.total || 100;\r\n\t\t\tconst randomStatValue = generateRandomStat(total, max, min);\r\n\t\t\tconst regex = new RegExp(other, \"gi\");\r\n\t\t\tformula = formula.replace(regex, randomStatValue.toString());\r\n\t\t}\r\n\t\ttry {\r\n\t\t\tevaluate(formula);\r\n\t\t} catch (e) {\r\n\t\t\terror.push(stat);\r\n\t\t}\r\n\t}\r\n\tif (error.length > 0) throw new FormulaError(error.join(\", \"), \"testStatCombinaison\");\r\n\treturn;\r\n}\r\n\r\n/**\r\n * Generate a random stat based on the template and the statistical min and max\r\n * @param {number|undefined} total\r\n * @param {number | undefined} max\r\n * @param {number | undefined} min\r\n * @returns\r\n */\r\nexport function generateRandomStat(\r\n\ttotal: number | undefined = 100,\r\n\tmax?: number,\r\n\tmin?: number\r\n) {\r\n\tlet randomStatValue = total + 1;\r\n\twhile (randomStatValue >= total || randomStatValue === 0) {\r\n\t\tconst random = new Random();\r\n\t\tif (max && min) randomStatValue = random.integer(min, max);\r\n\t\telse if (max) randomStatValue = random.integer(1, max);\r\n\t\telse if (min) randomStatValue = random.integer(min, total);\r\n\t\telse randomStatValue = random.integer(1, total);\r\n\t}\r\n\treturn randomStatValue;\r\n}\r\n","export class DiceTypeError extends Error {\n\tpublic readonly dice: string;\n\tpublic readonly cause: string | undefined;\n\tpublic readonly method: unknown;\n\n\tconstructor(dice: string, cause?: string, method?: unknown) {\n\t\tsuper(dice);\n\t\tthis.name = \"Invalid_Dice_Type\";\n\t\tthis.dice = dice;\n\t\tthis.cause = cause;\n\t\tthis.method = method;\n\t}\n}\n\nexport class FormulaError extends Error {\n\tpublic readonly formula: string;\n\tpublic readonly cause: string | undefined;\n\tpublic readonly method: unknown;\n\n\tconstructor(formula: string, cause?: string, method?: unknown) {\n\t\tsuper(formula);\n\t\tthis.name = \"Invalid_Formula\";\n\t\tthis.formula = formula;\n\t\tthis.cause = cause;\n\t\tthis.method = method;\n\t}\n}\n\nexport class MaxGreater extends Error {\n\tpublic readonly name: string;\n\tpublic readonly value: number;\n\tpublic readonly max: number;\n\n\tconstructor(value: number, max: number) {\n\t\tsuper(value.toString());\n\t\tthis.name = \"Max_Greater\";\n\t\tthis.value = value;\n\t\tthis.max = max;\n\t}\n}\n\nexport class EmptyObjectError extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Empty_Object\";\n\t}\n}\n\nexport class TooManyDice extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Too_Many_Dice\";\n\t}\n}\n\nexport class TooManyStats extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Too_Many_Stats\";\n\t}\n}\n\nexport class NoStatisticsError extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"No_Statistics\";\n\t}\n}\n","export const COMMENT_REGEX = /\\s+(#|\\/{2}|\\[|\\/\\*)(?<comment>.*)/;\r\nexport const SIGN_REGEX = /[><=!]+/;\r\nexport const SIGN_REGEX_SPACE = /[><=!]+(\\S+)/;\r\n\r\nexport const SYMBOL_DICE = \"&\";\r\n","/**\n * Definition of the Zod schema for template data\n */\nimport { z } from \"zod\";\n\nconst statisticValueSchema = z\n\t.object({\n\t\tmax: z.number().min(0).transform(val => val === 0 ? undefined : val).optional(),\n\t\tmin: z.number().min(0).transform(val => val === 0 ? undefined : val).optional(),\n\t\tcombinaison: z\n\t\t\t.string()\n\t\t\t.transform((str) => str.trim() || undefined)\n\t\t\t.optional(),\n\t\texclude: z.boolean().optional(),\n\t})\n\t.superRefine((data, ctx) => {\n\t\t\n\t\tif (data.max !== undefined && data.min !== undefined && data.max <= data.min) {\n\t\t\tctx.addIssue({\n\t\t\t\tcode: \"custom\",\n\t\t\t\tmessage: `Max_Greater; ${data.min}; ${data.max}`,\n\t\t\t\tpath: [\"max\"],\n\t\t\t});\n\t\t}\n\t});\n\nconst statisticSchema = z\n\t.record(statisticValueSchema)\n\t.optional()\n\t.refine((stats) => !stats || Object.keys(stats).length <= 25, {\n\t\tmessage: \"TooManyStats\",\n\t});\n\nconst criticalSchema = z\n\t.object({\n\t\tsuccess: z.string().or(z.number().min(0)).optional(),\n\t\tfailure: z.string().or(z.number().min(0)).optional(),\n\t})\n\t.transform((values) => {\n\t\tif (values.success === \"\") values.success = undefined;\n\t\tif (values.failure === \"\") values.failure = undefined;\n\t\tif (values.failure === 0) values.failure = undefined;\n\t\tif (values.success === 0) values.success = undefined;\n\t\tvalues.success = Number.parseInt(values.success as string, 10);\n\t\tvalues.failure = Number.parseInt(values.failure as string, 10);\n\t\treturn values;\n\t});\n\nconst criticalValueSchema = z.object({\n\tsign: z.enum([\"<\", \">\", \"<=\", \">=\", \"!=\", \"==\"]),\n\tvalue: z.string(),\n\tonNaturalDice: z.boolean().optional(),\n\taffectSkill: z.boolean().optional(),\n});\n\nconst damageSchema = z\n\t.record(z.string())\n\t.optional()\n\t.refine((stats) => !stats || Object.keys(stats).length <= 25, {\n\t\tmessage: \"TooManyDice\",\n\t});\n\nconst customCriticalSchema = z\n\t.record(criticalValueSchema)\n\t.optional()\n\t.refine((stats) => !stats || Object.keys(stats).length <= 22, {\n\t\tmessage: \"TooManyDice\",\n\t});\n\nexport const templateSchema = z.object({\n\tcharName: z.boolean().optional(),\n\tstatistics: statisticSchema,\n\ttotal: z.number().min(0).optional(),\n\tdiceType: z.string().optional(),\n\tcritical: criticalSchema.optional(),\n\tcustomCritical: customCriticalSchema,\n\tdamage: damageSchema,\n});\n"],"mappings":";AAAA,SAAS,kBAAkB;AAC3B,SAAS,YAAAA,iBAAgB;;;ACDzB,SAAQ,UAAU,iBAAgB;AAClC,OAAO;AAOA,SAAS,YAAY,QAAgB;AAC3C,SAAO,OAAO,QAAQ,uBAAuB,MAAM;AACpD;AAOO,SAAS,gBAAgB,MAAsB;AACrD,SAAO,KAAK;AAAA,IACX;AAAA,IACA,CAAC,OAAO,gBAAgB,gBACvB,iBAAiB,iBAAiB,YAAY,YAAY;AAAA,EAC5D;AACD;AASO,SAAS,kBACf,cACA,OACA,aACC;AACD,MAAI,OAAO,aAAa,YAAY;A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D,SAAS;AACV,CAAC;AAEK,IAAM,iBAAiB,EAAE,OAAO;AAAA,EACtC,UAAU,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC/B,YAAY;AAAA,EACZ,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS;AAAA,EAClC,UAAU,EAAE,OAAO,EAAE,SAAS;AAAA,EAC9B,UAAU,eAAe,SAAS;AAAA,EAClC,gBAAgB;AAAA,EAChB,QAAQ;AACT,CAAC;","names":["evaluate","evaluate","roller","evaluateRoll","diceResult","evaluate","evaluate","cleanedDice","random"]}
|
1
|
+
{"version":3,"sources":["../src/dice.ts","../src/utils.ts","../src/verify_template.ts","../src/errors.ts","../src/interfaces/constant.ts","../src/interfaces/zod.ts"],"sourcesContent":["import { DiceRoller } from \"@dice-roller/rpg-dice-roller\";\r\nimport { evaluate } from \"mathjs\";\r\n\r\nimport {\r\n\ttype Compare,\r\n\ttype ComparedValue,\r\n\ttype CustomCritical,\r\n\ttype Modifier,\r\n\ttype Resultat,\r\n\ttype Sign,\r\n\ttype StatisticalTemplate,\r\n\tdiceTypeRandomParse,\r\n\tstandardizeDice,\r\n\tDiceTypeError,\r\n\tCOMMENT_REGEX,\r\n\tSIGN_REGEX,\r\n\tSIGN_REGEX_SPACE,\r\n\tSYMBOL_DICE,\r\n} from \".\";\r\nimport { isNumber } from \"./utils\";\r\n\r\nfunction getCompare(\r\n\tdice: string,\r\n\tcompareRegex: RegExpMatchArray\r\n): { dice: string; compare: ComparedValue | undefined } {\r\n\t/**\r\n\t * @source: https://dice-roller.github.io/documentation/guide/notation/modifiers.html#target-success-dice-pool\r\n\t * Some system count the number of a dice that are greater than or equal to a target, and not the \"total\" of rolled dice.\r\n\t * We \"count\" the number of dice that meet a criterion, and not the total of the dice.\r\n\t * To support this, we use the group notation. It a little different than the notation of dice-roller, but it a sacrifice to not break the current notation.\r\n\t * @note:\r\n\t * - `{2d3}>=4` will be the same as `2d3>=4` and thus keep the comparaison.\r\n\t * - `{2d3>=4}` will count the total of dice that are greater than or equal to 4, and not the total of the dice.\r\n\t * - `{2d3,1d4}>=4` won't use the comparison, but will count the number of dice that are greater than or equal to 4. If the total of the dice is needed, just remove the group notation and use `2d3+1d4>=4`.\r\n\t */\r\n\tif (dice.match(/((\\{.*,(.*)+\\}|([><=!]+\\d+f))[><=!]+\\d+\\}?)|\\{(.*)([><=!]+).*\\}/)) return { dice, compare: undefined };\r\n\tdice = dice.replace(SIGN_REGEX_SPACE, \"\");\r\n\tlet compare: ComparedValue;\r\n\tconst calc = compareRegex[1];\r\n\tconst sign = calc.match(/[+-\\/*^]/)?.[0];\r\n\tconst compareSign = compareRegex[0].match(SIGN_REGEX)?.[0];\r\n\t\r\n\t\r\n\tif (sign) {\r\n\t\tconst toCalc = calc.replace(SIGN_REGEX, \"\").replace(/\\s/g, \"\").replace(/;(.*)/, \"\");\r\n\t\tconst rCompare = rollCompare(toCalc);\r\n\t\tconst total = evaluate(rCompare.value.toString());\r\n\t\tdice = dice.replace(SIGN_REGEX_SPACE, `${compareSign}${total}`);\r\n\t\tcompare = {\r\n\t\t\tsign: compareSign as \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\",\r\n\t\t\tvalue: total,\r\n\t\t\toriginalDice: rCompare.dice,\r\n\t\t\trollValue: rCompare.diceResult,\r\n\t\t};\r\n\t} else {\r\n\t\tconst rcompare = rollCompare(calc);\r\n\t\tcompare = {\r\n\t\t\tsign: compareSign as \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\",\r\n\t\t\tvalue: rcompare.value,\r\n\t\t\toriginalDice: rcompare.dice,\r\n\t\t\trollValue: rcompare.diceResult,\r\n\t\t};\r\n\t}\r\n\treturn { dice, compare };\r\n}\r\n\r\nfunction rollCompare(value: unknown) {\r\n\tif (isNumber(value)) return { value: Number.parseInt(value as string, 10) };\r\n\tconst rollComp = roll(value as string);\r\n\tif (!rollComp?.total)\r\n\t\t//not a dice throw\r\n\t\treturn { value: evaluate(value as string), diceResult: value as string };\r\n\treturn {\r\n\t\tdice: value as string,\r\n\t\tvalue: rollComp.total,\r\n\t\tdiceResult: rollComp?.result,\r\n\t};\r\n}\r\n\r\n/**\r\n * Allow to replace the compare part of a dice and use the critical customized one\r\n * @example\r\n * dice = \"1d20=20\";\r\n * custom critical {sign: \">\", value: \"$/2\"}\r\n * Random stats = 6\r\n * result = \"1d20>3\"\r\n */\r\nexport function createCriticalCustom(\r\n\tdice: string,\r\n\tcustomCritical: CustomCritical,\r\n\ttemplate: StatisticalTemplate\r\n) {\r\n\tconst compareRegex = dice.match(SIGN_REGEX_SPACE);\r\n\tlet customDice = dice;\r\n\tconst compareValue = diceTypeRandomParse(customCritical.value, template);\r\n\tif (compareValue.includes(\"$\"))\r\n\t\tthrow new DiceTypeError(compareValue, \"createCriticalCustom\");\r\n\tconst comparaison = `${customCritical.sign}${compareValue}`;\r\n\tif (compareRegex) customDice = customDice.replace(SIGN_REGEX_SPACE, comparaison);\r\n\telse customDice += comparaison;\r\n\treturn diceTypeRandomParse(customDice, template);\r\n}\r\n\r\nfunction getModifier(dice: string) {\r\n\tconst modifier = dice.matchAll(/(\\+|-|%|\\/|\\^|\\*|\\*{2})(\\d+)/gi);\r\n\tlet modificator: Modifier | undefined;\r\n\tfor (const mod of modifier) {\r\n\t\t//calculate the modifier if multiple\r\n\t\tif (modificator) {\r\n\t\t\tconst sign = modificator.sign;\r\n\t\t\tlet value = modificator.value;\r\n\t\t\tif (sign) value = calculator(sign, value, Number.parseInt(mod[2], 10));\r\n\t\t\tmodificator = {\r\n\t\t\t\tsign: mod[1] as Sign,\r\n\t\t\t\tvalue,\r\n\t\t\t};\r\n\t\t} else {\r\n\t\t\tmodificator = {\r\n\t\t\t\tsign: mod[1] as Sign,\r\n\t\t\t\tvalue: Number.parseInt(mod[2], 10),\r\n\t\t\t};\r\n\t\t}\r\n\t}\r\n\treturn modificator;\r\n}\r\n\r\n/**\r\n * Parse the string provided and turn it as a readable dice for dice parser\r\n * @param dice {string}\r\n */\r\nexport function roll(dice: string): Resultat | undefined {\r\n\t//parse dice string\r\n\tdice = standardizeDice(dice).replace(/^\\+/, \"\").trimStart();\r\n\tif (!dice.includes(\"d\")) return undefined;\r\n\tconst compareRegex = dice.match(SIGN_REGEX_SPACE);\r\n\tlet compare: ComparedValue | undefined;\r\n\tif (dice.includes(\";\")) return sharedRolls(dice);\r\n\tif (compareRegex) {\r\n\t\tconst compareResult = getCompare(dice, compareRegex);\r\n\t\tdice = compareResult.dice;\r\n\t\tcompare = compareResult.compare;\r\n\t}\r\n\tconst modificator = getModifier(dice);\r\n\r\n\tif (dice.match(/\\d+?#(.*)/)) {\r\n\t\tconst diceArray = dice.split(\"#\");\r\n\t\tconst numberOfDice = Number.parseInt(diceArray[0], 10);\r\n\t\tconst diceToRoll = diceArray[1].replace(COMMENT_REGEX, \"\");\r\n\t\tconst commentsMatch = diceArray[1].match(COMMENT_REGEX);\r\n\t\tconst comments = commentsMatch ? commentsMatch[2] : undefined;\r\n\t\tconst roller = new DiceRoller();\r\n\t\t//remove comments if any\r\n\t\tfor (let i = 0; i < numberOfDice; i++) {\r\n\t\t\ttry {\r\n\t\t\t\troller.roll(diceToRoll);\r\n\t\t\t} catch (error) {\r\n\t\t\t\tthrow new DiceTypeError(diceToRoll, \"roll\", error);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn {\r\n\t\t\tdice: diceToRoll,\r\n\t\t\tresult: roller.output,\r\n\t\t\tcomment: comments,\r\n\t\t\tcompare: compare ? compare : undefined,\r\n\t\t\tmodifier: modificator,\r\n\t\t\ttotal: roller.total,\r\n\t\t};\r\n\t}\r\n\tconst roller = new DiceRoller();\r\n\tconst diceWithoutComment = dice.replace(COMMENT_REGEX, \"\").trimEnd();\r\n\ttry {\r\n\t\troller.roll(diceWithoutComment);\r\n\t} catch (error) {\r\n\t\tthrow new DiceTypeError(diceWithoutComment, \"roll\", error);\r\n\t}\r\n\tconst commentMatch = dice.match(COMMENT_REGEX);\r\n\tconst comment = commentMatch ? commentMatch[2] : undefined;\r\n\treturn {\r\n\t\tdice,\r\n\t\tresult: roller.output,\r\n\t\tcomment,\r\n\t\tcompare: compare ? compare : undefined,\r\n\t\tmodifier: modificator,\r\n\t\ttotal: roller.total,\r\n\t};\r\n}\r\n/**\r\n * Evaluate a formula and replace \"^\" by \"**\" if any\r\n * @param {Sign} sign\r\n * @param {number} value\r\n * @param {number} total\r\n * @returns\r\n */\r\nexport function calculator(sign: Sign, value: number, total: number): number {\r\n\tif (sign === \"^\") sign = \"**\";\r\n\treturn evaluate(`${total} ${sign} ${value}`);\r\n}\r\n\r\nfunction inverseSign(\r\n\tsign: \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\"\r\n): \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\" {\r\n\tswitch (sign) {\r\n\t\tcase \"<\":\r\n\t\t\treturn \">\";\r\n\t\tcase \">\":\r\n\t\t\treturn \"<\";\r\n\t\tcase \"<=\":\r\n\t\t\treturn \">=\";\r\n\t\tcase \">=\":\r\n\t\t\treturn \"<=\";\r\n\t\tcase \"=\":\r\n\t\t\treturn \"!=\";\r\n\t\tcase \"==\":\r\n\t\t\treturn \"!=\";\r\n\t\tcase \"!=\":\r\n\t\t\treturn \"==\";\r\n\t}\r\n}\r\n\r\nfunction replaceInFormula(\r\n\telement: string,\r\n\tdiceResult: Resultat,\r\n\tcompareResult: { dice: string; compare: Compare | undefined },\r\n\tres: boolean\r\n) {\r\n\tconst { formule, diceAll } = replaceText(\r\n\t\telement,\r\n\t\tdiceResult.total ?? 0,\r\n\t\tdiceResult.dice\r\n\t);\r\n\tconst validSign = res ? \"✓\" : \"✕\";\r\n\tconst invertedSign = res\r\n\t\t? compareResult.compare!.sign\r\n\t\t: inverseSign(compareResult.compare!.sign);\r\n\tlet evaluateRoll: unknown;\r\n\ttry {\r\n\t\tevaluateRoll = evaluate(compareResult.dice);\r\n\t\treturn `${validSign} ${diceAll}: ${formule} = ${evaluateRoll}${invertedSign}${compareResult.compare?.value}`;\r\n\t} catch (error) {\r\n\t\tconst evaluateRoll = roll(compareResult.dice) as Resultat | undefined;\r\n\t\tif (evaluateRoll)\r\n\t\t\treturn `${validSign} ${diceAll}: ${evaluateRoll.result.split(\":\").splice(1).join(\":\")}`;\r\n\r\n\t\treturn `${validSign} ${diceAll}: ${formule} = ${evaluateRoll}${invertedSign}${compareResult.compare?.value}`;\r\n\t}\r\n}\r\n\r\nfunction compareSignFormule(\r\n\ttoRoll: string,\r\n\tcompareRegex: RegExpMatchArray,\r\n\telement: string,\r\n\tdiceResult: Resultat\r\n) {\r\n\tlet results = \"\";\r\n\tconst compareResult = getCompare(toRoll, compareRegex);\r\n\tconst toCompare = `${compareResult.dice}${compareResult.compare?.sign}${compareResult.compare?.value}`;\r\n\tlet res: unknown;\r\n\ttry {\r\n\t\tres = evaluate(toCompare);\r\n\t} catch (error) {\r\n\t\tres = roll(toCompare);\r\n\t}\r\n\tif (typeof res === \"boolean\") {\r\n\t\tresults = replaceInFormula(element, diceResult, compareResult, res);\r\n\t} else if (res instanceof Object) {\r\n\t\tconst diceResult = res as Resultat;\r\n\t\tif (diceResult.compare) {\r\n\t\t\tconst toEvaluate = evaluate(\r\n\t\t\t\t`${diceResult.total}${diceResult.compare.sign}${diceResult.compare.value}`\r\n\t\t\t);\r\n\t\t\tconst sign = toEvaluate ? \"✓\" : \"✕\";\r\n\t\t\tconst invertedSign = toEvaluate\r\n\t\t\t\t? diceResult.compare.sign\r\n\t\t\t\t: inverseSign(diceResult.compare.sign);\r\n\t\t\tconst dice = replaceText(element, 0, diceResult.dice).diceAll;\r\n\r\n\t\t\tresults = `${sign} ${dice}: ${diceResult.result.split(\":\").splice(1).join(\":\").trim()}${invertedSign}${diceResult.compare.value}`;\r\n\t\t}\r\n\t}\r\n\treturn { dice: compareResult.dice, results };\r\n}\r\n\r\nfunction replaceText(element: string, total: number, dice: string) {\r\n\treturn {\r\n\t\tformule: element.replace(SYMBOL_DICE, `[${total}]`).replace(/%.*%/g, \"\").trim(),\r\n\t\tdiceAll: element\r\n\t\t\t.replace(SYMBOL_DICE, `[${dice.replace(COMMENT_REGEX, \"\")}]`)\r\n\t\t\t.replace(/%.*%/g, \"\")\r\n\t\t\t.trim(),\r\n\t};\r\n}\r\n\r\nfunction formatComment(dice: string) {\r\n\tconst commentsRegex = /\\[(?<comments>.*?)\\]/;\r\n\tconst commentsMatch = commentsRegex.exec(dice);\r\n\treturn commentsMatch?.groups?.comments ? `__${commentsMatch.groups.comments}__ — ` : \"\";\r\n}\r\n\r\nfunction sharedRolls(dice: string): Resultat | undefined {\r\n\tif (dice.match(/\\d+?#(.*?)/))\r\n\t\tthrow new DiceTypeError(\r\n\t\t\tdice,\r\n\t\t\t\"noBulkRoll\",\r\n\t\t\t\"bulk roll are not allowed in shared rolls\"\r\n\t\t);\r\n\tconst results = [];\r\n\tconst mainComment =\r\n\t\t/\\s+#(?<comment>.*)/.exec(dice)?.groups?.comment?.trimEnd() ?? undefined;\r\n\tconst split = dice.split(\";\");\r\n\tlet diceMain = split[0];\r\n\tconst toHideRegex = /(?<!\\[[^\\]]*)\\((?<dice>[^)]+)\\)/;\r\n\tconst toHide = toHideRegex.exec(diceMain)?.groups;\r\n\tlet hidden = false;\r\n\tif (toHide?.dice) {\r\n\t\tdiceMain = toHide.dice;\r\n\t\thidden = true;\r\n\t} else if (toHide) {\r\n\t\tdiceMain = \"1d1\";\r\n\t\thidden = true;\r\n\t}\r\n\tconst commentsRegex = /\\[(?<comments>.*?)\\]/gi;\r\n\tconst comments = formatComment(diceMain);\r\n\tdiceMain = diceMain.replaceAll(commentsRegex, \"\").trim();\r\n\tconst diceResult = roll(diceMain);\r\n\tif (!diceResult || !diceResult.total) return undefined;\r\n\tresults.push(`※ ${comments}${diceResult.result}`);\r\n\tlet total = diceResult.total;\r\n\tdiceResult.comment = mainComment;\r\n\tif (!total) return diceResult;\r\n\tfor (let element of split.slice(1)) {\r\n\t\tconst comment = formatComment(element);\r\n\t\telement = element.replace(commentsRegex, \"\").trim();\r\n\t\tlet toRoll = element.replace(SYMBOL_DICE, `${diceResult.total}`);\r\n\t\tconst compareRegex = toRoll.match(SIGN_REGEX_SPACE);\r\n\t\tif (compareRegex) {\r\n\t\t\tconst compareResult = compareSignFormule(toRoll, compareRegex, element, diceResult);\r\n\t\t\ttoRoll = compareResult.dice;\r\n\t\t\tresults.push(compareResult.results);\r\n\t\t} else {\r\n\t\t\tconst { formule, diceAll } = replaceText(\r\n\t\t\t\telement,\r\n\t\t\t\tdiceResult.total,\r\n\t\t\t\tdiceResult.dice\r\n\t\t\t);\r\n\r\n\t\t\ttry {\r\n\t\t\t\tconst evaluated = evaluate(toRoll);\r\n\t\t\t\tresults.push(`◈ ${comment}${diceAll}: ${formule} = ${evaluated}`);\r\n\t\t\t\ttotal += Number.parseInt(evaluated, 10);\r\n\t\t\t} catch (error) {\r\n\t\t\t\tconst evaluated = roll(toRoll);\r\n\t\t\t\tif (evaluated)\r\n\t\t\t\t\tresults.push(\r\n\t\t\t\t\t\t`◈ ${comment}${diceAll}: ${evaluated.result.split(\":\").slice(1).join(\":\")}`\r\n\t\t\t\t\t);\r\n\t\t\t\telse results.push(`◈ ${comment}${diceAll}: ${formule} = ${evaluated}`);\r\n\t\t\t\ttotal += evaluated?.total ?? 0;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tif (hidden)\r\n\t\t//remove the first in result\r\n\t\tresults.shift();\r\n\treturn {\r\n\t\tdice: diceMain,\r\n\t\tresult: results.join(\";\"),\r\n\t\tcomment: mainComment,\r\n\t\tcompare: diceResult.compare,\r\n\t\tmodifier: diceResult.modifier,\r\n\t\ttotal,\r\n\t};\r\n}\r\n","import {evaluate, randomInt} from \"mathjs\";\r\nimport \"uniformize\";\r\nimport { FormulaError } from \".\";\r\n\r\n/**\r\n * Escape regex string\r\n * @param string {string}\r\n */\r\nexport function escapeRegex(string: string) {\r\n\treturn string.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\r\n}\r\n\r\n/**\r\n * Allow to keep the text as if in brackets\r\n * @param dice {string}\r\n * @return {string} the dice with the text in brackets as if, but the dice (not in brackets) is standardized\r\n */\r\nexport function standardizeDice(dice: string): string {\r\n\treturn dice.replace(\r\n\t\t/(\\[[^\\]]+\\])|([^[]+)/g,\r\n\t\t(match, insideBrackets, outsideText) =>\r\n\t\t\tinsideBrackets ? insideBrackets : outsideText.standardize(),\r\n\t);\r\n}\r\n\r\n/**\r\n * Replace the stat name by their value using stat\r\n * and after evaluate any formula using `replaceFormulaInDice`\r\n * @param {string} originalDice\r\n * @param {Record<string,number>|undefined} stats\r\n * @param {string|undefined} dollarValue\r\n */\r\nexport function generateStatsDice(\r\n\toriginalDice: string,\r\n\tstats?: Record<string, number>,\r\n\tdollarValue?: string,\r\n) {\r\n\tlet dice = originalDice.standardize();\r\n\tif (stats && Object.keys(stats).length > 0) {\r\n\t\t//damage field support adding statistic, like : 1d6 + strength\r\n\t\t//check if the value contains a statistic & calculate if it's okay\r\n\t\t//the dice will be converted before roll\r\n\t\tconst allStats = Object.keys(stats);\r\n\t\tfor (const stat of allStats) {\r\n\t\t\tconst regex = new RegExp(\r\n\t\t\t\t`(?!\\\\[)${escapeRegex(stat.standardize())}(?!\\\\])`,\r\n\t\t\t\t\"gi\",\r\n\t\t\t);\r\n\t\t\tif (dice.match(regex)) {\r\n\t\t\t\tconst statValue = stats[stat];\r\n\t\t\t\tdice = dice.replace(regex, statValue.toString());\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tif (dollarValue) dice = dice.replaceAll(\"$\", dollarValue);\r\n\treturn replaceFormulaInDice(dice);\r\n}\r\n\r\n/**\r\n * Replace the {{}} in the dice string and evaluate the interior if any\r\n * @param dice {string}\r\n */\r\nexport function replaceFormulaInDice(dice: string) {\r\n\tconst formula = /(?<formula>\\{{2}(.+?)}{2})/gim;\r\n\tlet match;\r\n\tlet modifiedDice = dice;\r\n\t// biome-ignore lint/suspicious/noAssignInExpressions: best way to regex in a loop\r\n\twhile ((match = formula.exec(dice)) !== null) {\r\n\t\tif (match.groups?.formula) {\r\n\t\t\tconst formulae = match.groups.formula\r\n\t\t\t\t.replaceAll(\"{{\", \"\")\r\n\t\t\t\t.replaceAll(\"}}\", \"\");\r\n\t\t\ttry {\r\n\t\t\t\tconst result = evaluate(formulae);\r\n\t\t\t\tmodifiedDice = modifiedDice.replace(\r\n\t\t\t\t\tmatch.groups.formula,\r\n\t\t\t\t\tresult.toString(),\r\n\t\t\t\t);\r\n\t\t\t} catch (error) {\r\n\t\t\t\tthrow new FormulaError(\r\n\t\t\t\t\tmatch.groups.formula,\r\n\t\t\t\t\t\"replaceFormulasInDice\",\r\n\t\t\t\t\terror,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn cleanedDice(modifiedDice);\r\n}\r\n\r\n/**\r\n * Replace the ++ +- -- by their proper value:\r\n * - `++` = `+`\r\n * - `+-` = `-`\r\n * - `--` = `+`\r\n * @param dice {string}\r\n */\r\nfunction cleanedDice(dice: string) {\r\n\treturn dice\r\n\t\t.replaceAll(\"+-\", \"-\")\r\n\t\t.replaceAll(\"--\", \"+\")\r\n\t\t.replaceAll(\"++\", \"+\")\r\n\t\t.trimEnd();\r\n}\r\n\r\n/**\r\n * Verify if a value is a number, even if it's a \"number\" string\r\n * @param value {unknown}\r\n * @returns {boolean}\r\n */\r\nexport function isNumber(value: unknown): boolean {\r\n\treturn (\r\n\t\tvalue !== undefined &&\r\n\t\t(typeof value === \"number\" ||\r\n\t\t\t(!Number.isNaN(Number(value)) &&\r\n\t\t\t\ttypeof value === \"string\" &&\r\n\t\t\t\tvalue.trim().length > 0))\r\n\t);\r\n}\r\n\r\n/**\r\n * Replace the `{exp}` in the dice.\r\n * If the `{exp}` has a default value in the form of `{exp || defaultValue}`, it will be replaced by the default value.\r\n * @param {string} dice\r\n * @returns {string} the dice with the {exp} replaced by a random value\r\n */\r\nexport function replaceExpByRandom(dice: string): string {\r\n\tconst diceRegex = /\\{exp( ?\\|\\| ?(?<default>\\d+))?}/gi\r\n\treturn dice.replace(diceRegex, (_match, _p1, _p2, _offset, _string, groups) => {\r\n\t\tconst defaultValue = groups?.default;\r\n\t\treturn defaultValue ?? randomInt(1, 999).toString();\r\n\t});\r\n}","import {evaluate, random, randomInt} from \"mathjs\";\r\nimport { Random } from \"random-js\";\r\nimport \"uniformize\";\r\n\r\nimport {\r\n\ttype StatisticalTemplate,\r\n\tcreateCriticalCustom,\r\n\troll,\r\n\tDiceTypeError,\r\n\tEmptyObjectError,\r\n\tFormulaError,\r\n\tNoStatisticsError,\r\n\tescapeRegex,\r\n\treplaceFormulaInDice,\r\n\ttemplateSchema,\r\n\tTooManyDice, replaceExpByRandom,\r\n} from \".\";\r\nimport { isNumber } from \"./utils\";\r\n\r\n/**\r\n * Verify if the provided dice work with random value\r\n * @param testDice {string}\r\n * @param allStats {Record<string,number>}\r\n */\r\nexport function evalStatsDice(testDice: string, allStats?: Record<string, number>) {\r\n\tlet dice = testDice.trimEnd();\r\n\tif (allStats && Object.keys(allStats).length > 0) {\r\n\t\tconst names = Object.keys(allStats);\r\n\t\tfor (const name of names) {\r\n\t\t\tconst regex = new RegExp(escapeRegex(name.standardize()), \"gi\");\r\n\t\t\tif (dice.standardize().match(regex)) {\r\n\t\t\t\tconst statValue = allStats[name];\r\n\t\t\t\tdice = dice.standardize().replace(regex, statValue.toString()).trimEnd();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\ttry {\r\n\t\tif (!roll(replaceFormulaInDice(replaceExpByRandom(dice))))\r\n\t\t\tthrow new DiceTypeError(dice, \"evalStatsDice\", \"no roll result\");\r\n\t\treturn testDice;\r\n\t} catch (error) {\r\n\t\tthrow new DiceTypeError(dice, \"evalStatsDice\", error);\r\n\t}\r\n}\r\n\r\n/**\r\n * Generate a random dice and remove the formula (+ evaluate it)\r\n * Used for diceDamage only\r\n * @param value {string}\r\n * @param template {StatisticalTemplate}\r\n * @returns\r\n */\r\nexport function diceRandomParse(value: string, template: StatisticalTemplate) {\r\n\tif (!template.statistics) return replaceFormulaInDice(value.standardize());\r\n\tvalue = value.standardize();\r\n\tconst statNames = Object.keys(template.statistics);\r\n\tlet newDice = value;\r\n\tfor (const name of statNames) {\r\n\t\tconst regex = new RegExp(escapeRegex(name.standardize()), \"gi\");\r\n\t\tif (value.match(regex)) {\r\n\t\t\tlet max: undefined | number = undefined;\r\n\t\t\tlet min: undefined | number = undefined;\r\n\t\t\tconst foundStat = template.statistics?.[name];\r\n\t\t\tif (foundStat) {\r\n\t\t\t\tmax = foundStat.max;\r\n\t\t\t\tmin = foundStat.min;\r\n\t\t\t}\r\n\t\t\tconst total = template.total || 100;\r\n\t\t\tconst randomStatValue = generateRandomStat(total, max, min);\r\n\t\t\tnewDice = value.replace(regex, randomStatValue.toString());\r\n\t\t}\r\n\t}\r\n\treturn replaceFormulaInDice(newDice);\r\n}\r\n\r\n/**\r\n * Same as damageDice but for DiceType\r\n * @param dice {string}\r\n * @param template {StatisticalTemplate}\r\n */\r\nexport function diceTypeRandomParse(dice: string, template: StatisticalTemplate) {\r\n\tdice = replaceExpByRandom(dice);\r\n\tif (!template.statistics) return dice;\r\n\tconst firstStatNotcombinaison = Object.keys(template.statistics).find(\r\n\t\t(stat) => !template.statistics?.[stat].combinaison\r\n\t);\r\n\tif (!firstStatNotcombinaison) return dice;\r\n\tconst stats = template.statistics[firstStatNotcombinaison];\r\n\tconst { min, max } = stats;\r\n\tconst total = template.total || 100;\r\n\tconst randomStatValue = generateRandomStat(total, max, min);\r\n\treturn replaceFormulaInDice(dice.replaceAll(\"$\", randomStatValue.toString()));\r\n}\r\n\r\n/**\r\n * Random the combinaison and evaluate it to check if everything is valid\r\n * @param combinaison {Record<string,string>}\r\n * @param stats {Record<string,number|number>}\r\n */\r\nexport function evalCombinaison(\r\n\tcombinaison: Record<string, string>,\r\n\tstats: Record<string, number | string>\r\n) {\r\n\tconst newStats: Record<string, number> = {};\r\n\tfor (const [stat, combin] of Object.entries(combinaison)) {\r\n\t\t//replace the stats in formula\r\n\t\tlet formula = combin.standardize();\r\n\t\tfor (const [statName, value] of Object.entries(stats)) {\r\n\t\t\tconst regex = new RegExp(statName.standardize(), \"gi\");\r\n\t\t\tformula = formula.replace(regex, value.toString());\r\n\t\t}\r\n\t\ttry {\r\n\t\t\tnewStats[stat] = evaluate(formula);\r\n\t\t} catch (error) {\r\n\t\t\tthrow new FormulaError(stat, \"evalCombinaison\", error);\r\n\t\t}\r\n\t}\r\n\treturn newStats;\r\n}\r\n\r\n/**\r\n * Evaluate one selected combinaison\r\n * @param combinaison {string}\r\n * @param stats {[name: string]: string|number}\r\n */\r\nexport function evalOneCombinaison(\r\n\tcombinaison: string,\r\n\tstats: Record<string, number | string>\r\n) {\r\n\tlet formula = combinaison.standardize();\r\n\tfor (const [statName, value] of Object.entries(stats)) {\r\n\t\tconst regex = new RegExp(statName.standardize(), \"gi\");\r\n\t\tformula = formula.replace(regex, value.toString());\r\n\t}\r\n\ttry {\r\n\t\treturn evaluate(formula);\r\n\t} catch (error) {\r\n\t\tthrow new FormulaError(combinaison, \"evalOneCombinaison\", error);\r\n\t}\r\n}\r\n\r\nfunction convertNumber(number: string | number | undefined) {\r\n\tif (!number) return undefined;\r\n\tif (number.toString().length === 0) return undefined;\r\n\tif (isNumber(number)) return Number.parseInt(number.toString(), 10);\r\n\treturn undefined;\r\n}\r\n\r\n/**\r\n * Parse the provided JSON and verify each field to check if everything could work when rolling\r\n * @param {unknown} template\r\n * @param {boolean} verify - If true, will roll the dices to check if everything is valid\r\n * @returns {StatisticalTemplate}\r\n */\r\nexport function verifyTemplateValue(template: unknown, verify: boolean=true): StatisticalTemplate {\r\n\tconst parsedTemplate = templateSchema.parse(template);\r\n\tconst { success, failure } = parsedTemplate.critical ?? {};\r\n\tconst criticicalVal = {\r\n\t\tsuccess: convertNumber(success),\r\n\t\tfailure: convertNumber(failure),\r\n\t};\r\n\tconst statistiqueTemplate: StatisticalTemplate = {\r\n\t\tdiceType: parsedTemplate.diceType,\r\n\t\tstatistics: parsedTemplate.statistics,\r\n\t\tcritical: criticicalVal,\r\n\t\ttotal: parsedTemplate.total,\r\n\t\tcharName: parsedTemplate.charName,\r\n\t\tdamage: parsedTemplate.damage,\r\n\t\tcustomCritical: parsedTemplate.customCritical,\r\n\t\tforceDistrib: parsedTemplate.forceDistrib,\r\n\t};\r\n\tif (!verify) return statistiqueTemplate;\r\n\tif (statistiqueTemplate.diceType) {\r\n\t\tconst cleanedDice = diceTypeRandomParse(\r\n\t\t\tstatistiqueTemplate.diceType,\r\n\t\t\tstatistiqueTemplate\r\n\t\t);\r\n\t\tconst rolled = roll(cleanedDice);\r\n\t\tif (!rolled) {\r\n\t\t\tthrow new DiceTypeError(cleanedDice, \"verifyTemplateValue\", \"no roll result\");\r\n\t\t}\r\n\t}\r\n\tif (statistiqueTemplate.customCritical) {\r\n\t\tif (!statistiqueTemplate.diceType) {\r\n\t\t\tthrow new DiceTypeError(\"no_dice_type\", \"verifyTemplateValue\", \"no dice type\");\r\n\t\t}\r\n\t\tconst customCritical = statistiqueTemplate.customCritical;\r\n\t\tfor (const [, custom] of Object.entries(customCritical)) {\r\n\t\t\tconst cleanedDice = createCriticalCustom(\r\n\t\t\t\tstatistiqueTemplate.diceType!,\r\n\t\t\t\tcustom,\r\n\t\t\t\tstatistiqueTemplate\r\n\t\t\t);\r\n\t\t\tconst rolled = roll(cleanedDice);\r\n\t\t\tif (!rolled)\r\n\t\t\t\tthrow new DiceTypeError(cleanedDice, \"verifyTemplateValue\", \"no roll result\");\r\n\t\t}\r\n\t}\r\n\ttestDiceRegistered(statistiqueTemplate);\r\n\ttestStatCombinaison(statistiqueTemplate);\r\n\treturn statistiqueTemplate;\r\n}\r\n\r\n/**\r\n * Test each damage roll from the template.damage\r\n * @param {StatisticalTemplate} template\r\n */\r\nexport function testDiceRegistered(template: StatisticalTemplate) {\r\n\tif (!template.damage) return;\r\n\tif (Object.keys(template.damage).length === 0) throw new EmptyObjectError();\r\n\tif (Object.keys(template.damage).length > 25) throw new TooManyDice();\r\n\tfor (const [name, dice] of Object.entries(template.damage)) {\r\n\t\tif (!dice) continue;\r\n\t\tconst diceReplaced = replaceExpByRandom(dice);\r\n\t\tconst randomDiceParsed = diceRandomParse(diceReplaced, template);\r\n\t\ttry {\r\n\t\t\tconst rolled = roll(randomDiceParsed);\r\n\t\t\tif (!rolled) throw new DiceTypeError(name, \"no_roll_result\", dice);\r\n\t\t} catch (error) {\r\n\t\t\tconsole.error(error);\r\n\t\t\tthrow new DiceTypeError(name, \"testDiceRegistered\", error);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n/**\r\n * Test all combinaison with generated random value\r\n * @param {StatisticalTemplate} template\r\n */\r\nexport function testStatCombinaison(template: StatisticalTemplate) {\r\n\tif (!template.statistics) return;\r\n\tconst onlycombinaisonStats = Object.fromEntries(\r\n\t\tObject.entries(template.statistics).filter(\r\n\t\t\t([_, value]) => value.combinaison !== undefined\r\n\t\t)\r\n\t);\r\n\tconst allOtherStats = Object.fromEntries(\r\n\t\tObject.entries(template.statistics).filter(([_, value]) => !value.combinaison)\r\n\t);\r\n\tif (Object.keys(onlycombinaisonStats).length === 0) return;\r\n\tconst allStats = Object.keys(template.statistics).filter(\r\n\t\t(stat) => !template.statistics![stat].combinaison\r\n\t);\r\n\tif (allStats.length === 0) throw new NoStatisticsError();\r\n\tconst error = [];\r\n\tfor (const [stat, value] of Object.entries(onlycombinaisonStats)) {\r\n\t\tlet formula = value.combinaison as string;\r\n\t\tfor (const [other, data] of Object.entries(allOtherStats)) {\r\n\t\t\tconst { max, min } = data;\r\n\t\t\tconst total = template.total || 100;\r\n\t\t\tconst randomStatValue = generateRandomStat(total, max, min);\r\n\t\t\tconst regex = new RegExp(other, \"gi\");\r\n\t\t\tformula = formula.replace(regex, randomStatValue.toString());\r\n\t\t}\r\n\t\ttry {\r\n\t\t\tevaluate(formula);\r\n\t\t} catch (e) {\r\n\t\t\terror.push(stat);\r\n\t\t}\r\n\t}\r\n\tif (error.length > 0) throw new FormulaError(error.join(\", \"), \"testStatCombinaison\");\r\n\treturn;\r\n}\r\n\r\n/**\r\n * Generate a random stat based on the template and the statistical min and max\r\n * @param {number|undefined} total\r\n * @param {number | undefined} max\r\n * @param {number | undefined} min\r\n * @returns\r\n */\r\nexport function generateRandomStat(\r\n\ttotal: number | undefined = 100,\r\n\tmax?: number,\r\n\tmin?: number\r\n) {\r\n\tlet randomStatValue = total + 1;\r\n\twhile (randomStatValue >= total || randomStatValue === 0) {\r\n\t\tconst random = new Random();\r\n\t\tif (max && min) randomStatValue = random.integer(min, max);\r\n\t\telse if (max) randomStatValue = random.integer(1, max);\r\n\t\telse if (min) randomStatValue = random.integer(min, total);\r\n\t\telse randomStatValue = random.integer(1, total);\r\n\t}\r\n\treturn randomStatValue;\r\n}\r\n","export class DiceTypeError extends Error {\n\tpublic readonly dice: string;\n\tpublic readonly cause: string | undefined;\n\tpublic readonly method: unknown;\n\n\tconstructor(dice: string, cause?: string, method?: unknown) {\n\t\tsuper(dice);\n\t\tthis.name = \"Invalid_Dice_Type\";\n\t\tthis.dice = dice;\n\t\tthis.cause = cause;\n\t\tthis.method = method;\n\t}\n}\n\nexport class FormulaError extends Error {\n\tpublic readonly formula: string;\n\tpublic readonly cause: string | undefined;\n\tpublic readonly method: unknown;\n\n\tconstructor(formula: string, cause?: string, method?: unknown) {\n\t\tsuper(formula);\n\t\tthis.name = \"Invalid_Formula\";\n\t\tthis.formula = formula;\n\t\tthis.cause = cause;\n\t\tthis.method = method;\n\t}\n}\n\nexport class MaxGreater extends Error {\n\tpublic readonly name: string;\n\tpublic readonly value: number;\n\tpublic readonly max: number;\n\n\tconstructor(value: number, max: number) {\n\t\tsuper(value.toString());\n\t\tthis.name = \"Max_Greater\";\n\t\tthis.value = value;\n\t\tthis.max = max;\n\t}\n}\n\nexport class EmptyObjectError extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Empty_Object\";\n\t}\n}\n\nexport class TooManyDice extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Too_Many_Dice\";\n\t}\n}\n\nexport class TooManyStats extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Too_Many_Stats\";\n\t}\n}\n\nexport class NoStatisticsError extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"No_Statistics\";\n\t}\n}\n","export const COMMENT_REGEX = /\\s+(#|\\/{2}|\\[|\\/\\*)(?<comment>.*)/;\r\nexport const SIGN_REGEX = /[><=!]+/;\r\nexport const SIGN_REGEX_SPACE = /[><=!]+(\\S+)/;\r\n\r\nexport const SYMBOL_DICE = \"&\";\r\n","/**\n * Definition of the Zod schema for template data\n */\nimport { z } from \"zod\";\n\nconst statisticValueSchema = z\n\t.object({\n\t\tmax: z.number().min(0).transform(val => val === 0 ? undefined : val).optional(),\n\t\tmin: z.number().min(0).transform(val => val === 0 ? undefined : val).optional(),\n\t\tcombinaison: z\n\t\t\t.string()\n\t\t\t.transform((str) => str.trim() || undefined)\n\t\t\t.optional(),\n\t\texclude: z.boolean().optional(),\n\t})\n\t.superRefine((data, ctx) => {\n\t\t\n\t\tif (data.max !== undefined && data.min !== undefined && data.max <= data.min) {\n\t\t\tctx.addIssue({\n\t\t\t\tcode: \"custom\",\n\t\t\t\tmessage: `Max_Greater; ${data.min}; ${data.max}`,\n\t\t\t\tpath: [\"max\"],\n\t\t\t});\n\t\t}\n\t});\n\nconst statisticSchema = z\n\t.record(statisticValueSchema)\n\t.optional()\n\t.refine((stats) => !stats || Object.keys(stats).length <= 25, {\n\t\tmessage: \"TooManyStats\",\n\t});\n\nconst criticalSchema = z\n\t.object({\n\t\tsuccess: z.string().or(z.number().min(0)).optional(),\n\t\tfailure: z.string().or(z.number().min(0)).optional(),\n\t})\n\t.transform((values) => {\n\t\tif (values.success === \"\") values.success = undefined;\n\t\tif (values.failure === \"\") values.failure = undefined;\n\t\tif (values.failure === 0) values.failure = undefined;\n\t\tif (values.success === 0) values.success = undefined;\n\t\tvalues.success = Number.parseInt(values.success as string, 10);\n\t\tvalues.failure = Number.parseInt(values.failure as string, 10);\n\t\treturn values;\n\t});\n\nconst criticalValueSchema = z.object({\n\tsign: z.enum([\"<\", \">\", \"<=\", \">=\", \"!=\", \"==\"]),\n\tvalue: z.string(),\n\tonNaturalDice: z.boolean().optional(),\n\taffectSkill: z.boolean().optional(),\n});\n\nconst damageSchema = z\n\t.record(z.string())\n\t.optional()\n\t.refine((stats) => !stats || Object.keys(stats).length <= 25, {\n\t\tmessage: \"TooManyDice\",\n\t});\n\nconst customCriticalSchema = z\n\t.record(criticalValueSchema)\n\t.optional()\n\t.refine((stats) => !stats || Object.keys(stats).length <= 22, {\n\t\tmessage: \"TooManyDice\",\n\t});\n\nexport const templateSchema = z.object({\n\tcharName: z.boolean().optional(),\n\tstatistics: statisticSchema,\n\ttotal: z.number().min(0).transform(val => val === 0 ? undefined : val).optional(),\n\tforceDistrib: z.boolean().optional(),\n\tdiceType: z.string().optional(),\n\tcritical: criticalSchema.optional(),\n\tcustomCritical: customCriticalSchema,\n\tdamage: damageSchema,\n});\n"],"mappings":";AAAA,SAAS,kBAAkB;AAC3B,SAAS,YAAAA,iBAAgB;;;ACDzB,SAAQ,UAAU,iBAAgB;AAClC,OAAO;AAOA,SAAS,YAAY,QAAgB;AAC3C,SAAO,OAAO,QAAQ,uBAAuB,MAAM;AACpD;AAOO,SAAS,gBAAgB,MAAsB;AACrD,SAAO,KAAK;AAAA,IACX;AAAA,IACA,CAAC,OAAO,gBAAgB,gBACvB,iBAAiB,iBAAiB,YAAY,YAAY;AAAA,EAC5D;AACD;AASO,SAAS,kBACf,cACA,OACA,aACC;AACD,MAAI,OAAO,aAAa,YAAY;AACpC,MAAI,SAAS,OAAO,KAAK,KAAK,EAAE,SA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