From 7116851139ee44ca1ee4a7f9a8fdd4e8045d51d4 Mon Sep 17 00:00:00 2001 From: Ean Milligan Date: Thu, 26 Jun 2025 04:32:39 -0400 Subject: [PATCH] Add Number Variables flag --- .bruno/Authenticated/Roll Requests/Roll Dice.bru | 3 ++- README.md | 1 + src/artigen/artigen.ts | 10 ++++++++-- src/artigen/dice/dice.d.ts | 1 + src/artigen/dice/getModifiers.ts | 7 +++++++ src/commands/helpLibrary/decorators.ts | 10 ++++++++++ src/commands/helpLibrary/miscFeatures.ts | 7 ++++--- src/endpoints/gets/apiRoll.ts | 1 + 8 files changed, 34 insertions(+), 6 deletions(-) diff --git a/.bruno/Authenticated/Roll Requests/Roll Dice.bru b/.bruno/Authenticated/Roll Requests/Roll Dice.bru index d1d58d0..e5d2360 100644 --- a/.bruno/Authenticated/Roll Requests/Roll Dice.bru +++ b/.bruno/Authenticated/Roll Requests/Roll Dice.bru @@ -5,7 +5,7 @@ meta { } get { - url: http://localhost:8166/api/roll?user=[discord-user-id]&channel=[discord-channel-id]&rollstr=[artificer-roll-cmd]&documentation=All items below are optional. Flags do not need values.&nd=[no-details-flag]&snd=[super-no-details-flag]&hr=[hide-raw-roll-details-flag]&s=[spoiler-results-flag]&m-or-max=[max-roll-flag, cannot be used with n flag]&min=[min-roll-flag, cannot be used with n, sn, or max]&n=[nominal-roll-flag, cannot be used with sn, max or min flag]&sn=[simulated-nominal-flag, cannot be used with max, min, n. or cc]&gms=[csv-of-discord-user-ids-to-be-dmed-results]&o=[order-rolls, must be a or d]&c=[count-flag]&cc=[confirm-crit-flag, cannot be used with sn]&rd=[roll-dist-flag] + url: http://localhost:8166/api/roll?user=[discord-user-id]&channel=[discord-channel-id]&rollstr=[artificer-roll-cmd]&documentation=All items below are optional. Flags do not need values.&nd=[no-details-flag]&snd=[super-no-details-flag]&hr=[hide-raw-roll-details-flag]&s=[spoiler-results-flag]&m-or-max=[max-roll-flag, cannot be used with n flag]&min=[min-roll-flag, cannot be used with n, sn, or max]&n=[nominal-roll-flag, cannot be used with sn, max or min flag]&sn=[simulated-nominal-flag, can pass number with it, cannot be used with max, min, n. or cc]&gms=[csv-of-discord-user-ids-to-be-dmed-results]&o=[order-rolls, must be a or d]&c=[count-flag]&cc=[confirm-crit-flag, cannot be used with sn]&rd=[roll-dist-flag]&nv-or-vn=[number-variables-flag] body: none auth: inherit } @@ -28,4 +28,5 @@ params:query { c: [count-flag] cc: [confirm-crit-flag, cannot be used with sn] rd: [roll-dist-flag] + nv-or-vn: [number-variables-flag] } diff --git a/README.md b/README.md index 5609b37..fbc259e 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,7 @@ The Artificer comes with a few supplemental commands to the main rolling command * `-cc` - Confirm Critical Hits - Automatically rerolls whenever a crit hits, cannot be used with `-sn` * `-rd` - Roll Distribution - Shows a raw roll distribution of all dice in roll * `-hr` - Hide Raw - Hide the raw input, showing only the results/details of the roll + * `-nv` or `-vn` - Number Variables - Adds `xN` before each roll command in the details section for debug reasons * The results have some formatting applied on them to provide details on what happened during this roll. * Critical successes will be **bolded** * Critical fails will be underlined diff --git a/src/artigen/artigen.ts b/src/artigen/artigen.ts index 8fcc546..34edd36 100644 --- a/src/artigen/artigen.ts +++ b/src/artigen/artigen.ts @@ -96,7 +96,7 @@ export const runCmd = (rollRequest: QueuedRoll): SolvedRoll => { } // Fill out all of the details and results now - tempReturnData.forEach((e) => { + tempReturnData.forEach((e, i) => { loopCountCheck(); loggingEnabled && log(LT.LOG, `Parsing roll ${rollRequest.rollCmd} | Making return text ${JSON.stringify(e)}`); @@ -125,8 +125,14 @@ export const runCmd = (rollRequest: QueuedRoll): SolvedRoll => { line2 += `${preFormat}${rollRequest.modifiers.commaTotals ? e.rollTotal.toLocaleString() : e.rollTotal}${postFormat}, `; } + const varNum = `\`x${i}\`: `; const rollDetails = rollRequest.modifiers.noDetails || rollRequest.modifiers.simulatedNominal > 0 ? ' = ' : ` = ${e.rollDetails} = `; - line3 += `\`${e.initConfig.replaceAll(' ', '')}\`${rollDetails}${preFormat}${rollRequest.modifiers.commaTotals ? e.rollTotal.toLocaleString() : e.rollTotal}${postFormat}\n`; + line3 += `${rollRequest.modifiers.numberVariables && i + 1 !== tempReturnData.length ? varNum : ''}\`${ + e.initConfig.replaceAll( + ' ', + '', + ) + }\`${rollDetails}${preFormat}${rollRequest.modifiers.commaTotals ? e.rollTotal.toLocaleString() : e.rollTotal}${postFormat}\n`; }); // If order is on, remove trailing ", " diff --git a/src/artigen/dice/dice.d.ts b/src/artigen/dice/dice.d.ts index 7a1ab51..23ab9fc 100644 --- a/src/artigen/dice/dice.d.ts +++ b/src/artigen/dice/dice.d.ts @@ -55,6 +55,7 @@ export interface RollModifiers { commaTotals: boolean; confirmCrit: boolean; rollDist: boolean; + numberVariables: boolean; apiWarn: string; valid: boolean; error: Error; diff --git a/src/artigen/dice/getModifiers.ts b/src/artigen/dice/getModifiers.ts index 6c9367a..5249f5e 100644 --- a/src/artigen/dice/getModifiers.ts +++ b/src/artigen/dice/getModifiers.ts @@ -19,6 +19,8 @@ export const Modifiers = Object.freeze({ CommaTotals: '-ct', ConfirmCrit: '-cc', RollDistribution: '-rd', + NumberVariables: '-nv', + VariablesNumber: '-vn', }); export const getModifiers = (args: string[]): [RollModifiers, string[]] => { @@ -38,6 +40,7 @@ export const getModifiers = (args: string[]): [RollModifiers, string[]] => { commaTotals: false, confirmCrit: false, rollDist: false, + numberVariables: false, apiWarn: '', valid: true, error: new Error(), @@ -122,6 +125,10 @@ export const getModifiers = (args: string[]): [RollModifiers, string[]] => { case Modifiers.RollDistribution: modifiers.rollDist = true; break; + case Modifiers.NumberVariables: + case Modifiers.VariablesNumber: + modifiers.numberVariables = true; + break; default: // Default case should not mess with the array defaultCase = true; diff --git a/src/commands/helpLibrary/decorators.ts b/src/commands/helpLibrary/decorators.ts index 0b4d23d..9063c56 100644 --- a/src/commands/helpLibrary/decorators.ts +++ b/src/commands/helpLibrary/decorators.ts @@ -162,6 +162,16 @@ Shows a raw roll distribution of all dice in roll.`, example: ['`[[1000d20]] -rd`'], }, ], + [ + '-nv', + { + name: 'Number Variables', + description: `**Usage:** \`-nv\` or \`-vn\` + +Mainly a debug decorator, useful when creating complex rolls that will be reused. Will not number the final roll command in the list as it will not be available for use.`, + example: ['`[[d20]] [[d20]] [[d20]] -vn`'], + }, + ], ]); export const DecoratorsHelpPages: HelpPage = { diff --git a/src/commands/helpLibrary/miscFeatures.ts b/src/commands/helpLibrary/miscFeatures.ts index b710235..a8f9323 100644 --- a/src/commands/helpLibrary/miscFeatures.ts +++ b/src/commands/helpLibrary/miscFeatures.ts @@ -46,19 +46,20 @@ Damage: 14`, This message must contain multiple roll commands in it (such as \`[[d4]] [[d8]]\`). Nested dice rolls are not able to be used as a variable, but can use variables inside them. -Variables are numbered from \`x0\` to \`xN\`, where \`N\` equals two less than the total number of roll commands in the message. +Variables are numbered from \`x0\` to \`xN\`, where \`N\` equals two less than the total number of roll commands in the message. You can add the "Number Variables" flag (\`-nv\`) to your command to see what will be assigned to each roll command. **Notes about this example:** - The example below starts with \`[[0]]\` so that it is a valid roll command. See the \`Miscellaneous Features>User Formatting\` help page for more details. - It is recommended to use the "Super No Details" flag (\`-snd\`) in combination with the "Hide Raw" flag (\`-hr\`) to only show the formatted results. This example does not use it to show exactly what is happening. - The example makes use of Nested Roll Commands to use the "To Hit" as the number of dice to roll for the "Explosion".`, example: [ - `\`\`\`[[0]]<=(this is x0) ${config.name} attacks the dragon with their Magical Sword of Extra Strength and Explosions! + `If you send: +\`\`\`[[0]]<=(this is x0) ${config.name} attacks the dragon with their Magical Sword of Extra Strength and Explosions! Strength Check: [[d20 + 8 + 2 - 1]]<=(this is x1) To Hit: [[d20 + 4 - 1 + 8]]<=(this is x2) Damage: [[(d8 + 10) * x1]]<=(this is x3) Explosion: [[ [[x2]]d10! * x3 ]]\`\`\` -The above results in the following: +${config.name} will respond with: @$ rolled: \`[[0]] ${config.name} attacks the dragon with their Magical Sword of Extra Strength and Explosions! Strength Check: [[d20 + 8 + 2 - 1]] To Hit: [[d20 + 4 - 1 + 8]] Damage: [[(d8 + 10) * x1]] Explosion: [[ [[x2]]d10! * x3 ]]\` diff --git a/src/endpoints/gets/apiRoll.ts b/src/endpoints/gets/apiRoll.ts index 235cf73..30f5eb2 100644 --- a/src/endpoints/gets/apiRoll.ts +++ b/src/endpoints/gets/apiRoll.ts @@ -99,6 +99,7 @@ export const apiRoll = async (query: Map, apiUserid: bigint): Pr commaTotals: query.has('ct'), confirmCrit: query.has('cc'), rollDist: query.has('rd'), + numberVariables: query.has('nv') || query.has('vn'), apiWarn: hideWarn ? '' : apiWarning, valid: true, error: new Error(),