diff --git a/src/artigen/artigen.d.ts b/src/artigen/artigen.d.ts index 3d3b817..bef6dd0 100644 --- a/src/artigen/artigen.d.ts +++ b/src/artigen/artigen.d.ts @@ -11,6 +11,7 @@ export interface ReturnData { containsCrit: boolean; containsFail: boolean; initConfig: string; + isComplex: boolean; } // SolvedRoll is the complete solved and formatted roll, or the error said roll created diff --git a/src/artigen/artigen.ts b/src/artigen/artigen.ts index 79b0e30..8fcc546 100644 --- a/src/artigen/artigen.ts +++ b/src/artigen/artigen.ts @@ -83,8 +83,18 @@ export const runCmd = (rollRequest: QueuedRoll): SolvedRoll => { line1 = ` rolled:\n\`${rawCmd}\``; } + // List number of iterations on simulated nominals if (rollRequest.modifiers.simulatedNominal) line2 += `Iterations performed per roll: \`${rollRequest.modifiers.simulatedNominal}\`\n`; + // Reduce counts to a single object + returnMsg.counts = reduceCountDetails(tempCountDetails); + + // If a regular nominal and roll looks somewhat complex, alert user simulatedNominal exists + if (rollRequest.modifiers.nominalRoll && tempReturnData.filter((data) => data.isComplex).length) { + line2 += + "One or more of the rolls requested appear to be more complex than what the Nominal calculator is intended for. For a better approximation of this roll's nominal value, please rerun this roll with the `-sn` flag.\n"; + } + // Fill out all of the details and results now tempReturnData.forEach((e) => { loopCountCheck(); @@ -129,9 +139,6 @@ export const runCmd = (rollRequest: QueuedRoll): SolvedRoll => { returnMsg.line2 = line2; returnMsg.line3 = line3; - // Reduce counts to a single object - returnMsg.counts = reduceCountDetails(tempCountDetails); - // Reduce rollDist maps into a single map returnMsg.rollDistributions = reduceRollDistMaps(tempRollDists); } catch (e) { diff --git a/src/artigen/cmdTokenizer.ts b/src/artigen/cmdTokenizer.ts index 133c550..a024d66 100644 --- a/src/artigen/cmdTokenizer.ts +++ b/src/artigen/cmdTokenizer.ts @@ -113,6 +113,7 @@ export const tokenizeCmd = ( containsCrit: simulatedData.some((data) => data.containsCrit), containsFail: simulatedData.some((data) => data.containsFail), initConfig: simulatedData[0].initConfig, + isComplex: simulatedData[0].isComplex, }); loggingEnabled && log(LT.LOG, `SN on, returnData updated ${JSON.stringify(returnData)}`); } diff --git a/src/artigen/dice/dice.d.ts b/src/artigen/dice/dice.d.ts index 3b57b0e..7a1ab51 100644 --- a/src/artigen/dice/dice.d.ts +++ b/src/artigen/dice/dice.d.ts @@ -14,6 +14,7 @@ export interface RollSet { exploding: boolean; critHit: boolean; critFail: boolean; + isComplex: boolean; } // CountDetails is the object holding the count data for creating the Count Embed diff --git a/src/artigen/dice/executeRoll.ts b/src/artigen/dice/executeRoll.ts index 438a25b..def162a 100644 --- a/src/artigen/dice/executeRoll.ts +++ b/src/artigen/dice/executeRoll.ts @@ -60,6 +60,13 @@ export const executeRoll = (rollStr: string, modifiers: RollModifiers): RollSet[ exploding: false, critHit: false, critFail: false, + isComplex: rollConf.drop.on || + rollConf.keep.on || + rollConf.dropHigh.on || + rollConf.keepLow.on || + rollConf.critScore.on || + rollConf.critFail.on || + rollConf.exploding.on, }); // Initial rolling, not handling reroll or exploding here diff --git a/src/artigen/dice/generateFormattedRoll.ts b/src/artigen/dice/generateFormattedRoll.ts index f00b5b6..74432fa 100644 --- a/src/artigen/dice/generateFormattedRoll.ts +++ b/src/artigen/dice/generateFormattedRoll.ts @@ -16,6 +16,7 @@ export const generateFormattedRoll = (rollConf: string, modifiers: RollModifiers let tempDetails = '['; let tempCrit = false; let tempFail = false; + let tempComplex = false; // Generate the roll, passing flags thru const tempRollSet = executeRoll(rollConf, modifiers); @@ -46,6 +47,9 @@ export const generateFormattedRoll = (rollConf: string, modifiers: RollModifiers if (e.critFail) { tempFail = true; } + if (e.isComplex) { + tempComplex = true; + } } // If the roll was a crit hit or fail, or dropped/rerolled, add the formatting needed if (e.critHit) { @@ -84,6 +88,7 @@ export const generateFormattedRoll = (rollConf: string, modifiers: RollModifiers details: tempDetails, containsCrit: tempCrit, containsFail: tempFail, + isComplex: tempComplex, }, countDetails: modifiers.count || modifiers.confirmCrit ? rollCounter(tempRollSet) : rollCounter([]), rollDistributions: modifiers.rollDist ? createRollDistMap(tempRollSet) : new Map(), diff --git a/src/artigen/math/math.d.ts b/src/artigen/math/math.d.ts index a8e948a..d018fa3 100644 --- a/src/artigen/math/math.d.ts +++ b/src/artigen/math/math.d.ts @@ -4,6 +4,7 @@ export interface SolvedStep { details: string; containsCrit: boolean; containsFail: boolean; + isComplex: boolean; } // Joined type for mathConf as its a "WIP" variable and moved everything from string->number->SolvedStep diff --git a/src/artigen/math/mathSolver.ts b/src/artigen/math/mathSolver.ts index 7b20e77..071ad6f 100644 --- a/src/artigen/math/mathSolver.ts +++ b/src/artigen/math/mathSolver.ts @@ -23,6 +23,7 @@ export const mathSolver = (conf: MathConf[], wrapDetails = false): SolvedStep => details: '', containsCrit: false, containsFail: false, + isComplex: false, }; // If entering with a single number, note it now @@ -103,11 +104,12 @@ export const mathSolver = (conf: MathConf[], wrapDetails = false): SolvedStep => // Init temp math to NaN to catch bad parsing let oper1 = NaN; let oper2 = NaN; - const subStepSolve = { + const subStepSolve: SolvedStep = { total: NaN, details: '', containsCrit: false, containsFail: false, + isComplex: false, }; // If operand1 is a SolvedStep, populate our subStepSolve with its details and crit/fail flags @@ -116,6 +118,7 @@ export const mathSolver = (conf: MathConf[], wrapDetails = false): SolvedStep => subStepSolve.details = `${operand1.details}\\${conf[i]}`; subStepSolve.containsCrit = operand1.containsCrit; subStepSolve.containsFail = operand1.containsFail; + subStepSolve.isComplex = operand1.isComplex; } else { // else parse it as a number and add it to the subStep details if (operand1 || operand1 == 0) { @@ -130,6 +133,7 @@ export const mathSolver = (conf: MathConf[], wrapDetails = false): SolvedStep => subStepSolve.details += operand2.details; subStepSolve.containsCrit = subStepSolve.containsCrit || operand2.containsCrit; subStepSolve.containsFail = subStepSolve.containsFail || operand2.containsFail; + subStepSolve.isComplex = subStepSolve.isComplex || operand2.isComplex; } else { // else parse it as a number and add it to the subStep details oper2 = parseFloat(operand2.toString()); @@ -193,6 +197,7 @@ export const mathSolver = (conf: MathConf[], wrapDetails = false): SolvedStep => stepSolve.details = tempConf.details; stepSolve.containsCrit = tempConf.containsCrit; stepSolve.containsFail = tempConf.containsFail; + stepSolve.isComplex = tempConf.isComplex; } // If this was a nested call, add on parens around the details to show what math we've done diff --git a/src/artigen/math/mathTokenizer.ts b/src/artigen/math/mathTokenizer.ts index b875c38..b56b3f7 100644 --- a/src/artigen/math/mathTokenizer.ts +++ b/src/artigen/math/mathTokenizer.ts @@ -60,6 +60,7 @@ export const tokenizeMath = (cmd: string, modifiers: RollModifiers, previousResu details: '*e*', containsCrit: false, containsFail: false, + isComplex: false, }; } else if (curMathConfStr.toLowerCase() === 'lemon' || curMathConfStr.toLowerCase() === '๐Ÿ‹') { mathConf[i] = { @@ -67,6 +68,7 @@ export const tokenizeMath = (cmd: string, modifiers: RollModifiers, previousResu details: '๐Ÿ‹', containsCrit: false, containsFail: false, + isComplex: false, }; } else if (curMathConfStr.toLowerCase() === 'fart' || curMathConfStr.toLowerCase() === '๐Ÿ’ฉ') { mathConf[i] = { @@ -74,6 +76,7 @@ export const tokenizeMath = (cmd: string, modifiers: RollModifiers, previousResu details: '๐Ÿ’ฉ', containsCrit: false, containsFail: false, + isComplex: false, }; } else if (curMathConfStr.toLowerCase() === 'sex' || curMathConfStr.toLowerCase() === '๐Ÿ†๐Ÿ‘' || curMathConfStr.toLowerCase() === '๐Ÿ‘๐Ÿ†') { mathConf[i] = { @@ -81,6 +84,7 @@ export const tokenizeMath = (cmd: string, modifiers: RollModifiers, previousResu details: '( อกยฐ อœส– อกยฐ)', containsCrit: false, containsFail: false, + isComplex: false, }; } else if (curMathConfStr.toLowerCase() === 'inf' || curMathConfStr.toLowerCase() === 'infinity' || curMathConfStr.toLowerCase() === 'โˆž') { // If the operand is the constant Infinity, create a SolvedStep for it @@ -89,6 +93,7 @@ export const tokenizeMath = (cmd: string, modifiers: RollModifiers, previousResu details: 'โˆž', containsCrit: false, containsFail: false, + isComplex: false, }; } else if (curMathConfStr.toLowerCase() === 'pi' || curMathConfStr.toLowerCase() === '๐œ‹') { // If the operand is the constant pi, create a SolvedStep for it @@ -97,6 +102,7 @@ export const tokenizeMath = (cmd: string, modifiers: RollModifiers, previousResu details: '๐œ‹', containsCrit: false, containsFail: false, + isComplex: false, }; } else if (curMathConfStr.toLowerCase() === 'pie' || curMathConfStr.toLowerCase() === '๐Ÿฅง') { // If the operand is pie, pi*e, create a SolvedStep for e and pi (and the multiplication symbol between them) @@ -105,6 +111,7 @@ export const tokenizeMath = (cmd: string, modifiers: RollModifiers, previousResu details: '๐œ‹', containsCrit: false, containsFail: false, + isComplex: false, }; mathConf.splice( i + 1, @@ -116,6 +123,7 @@ export const tokenizeMath = (cmd: string, modifiers: RollModifiers, previousResu details: '*e*', containsCrit: false, containsFail: false, + isComplex: false, }, ], ); @@ -184,6 +192,7 @@ export const tokenizeMath = (cmd: string, modifiers: RollModifiers, previousResu containsCrit: tempSolved.containsCrit, containsFail: tempSolved.containsFail, initConfig: cmd, + isComplex: tempSolved.isComplex, }, ], countDetails,