add internal flag of if a roll is complex to add warning message to nominal

This commit is contained in:
Ean Milligan 2025-06-21 21:41:56 -04:00
parent 6162339942
commit 5b7ceb9f88
9 changed files with 41 additions and 4 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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)}`);
}

View File

@ -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

View File

@ -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

View File

@ -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<string, number[]>(),

View File

@ -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

View File

@ -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

View File

@ -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,