add internal flag of if a roll is complex to add warning message to nominal
This commit is contained in:
parent
6162339942
commit
5b7ceb9f88
|
@ -11,6 +11,7 @@ export interface ReturnData {
|
||||||
containsCrit: boolean;
|
containsCrit: boolean;
|
||||||
containsFail: boolean;
|
containsFail: boolean;
|
||||||
initConfig: string;
|
initConfig: string;
|
||||||
|
isComplex: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SolvedRoll is the complete solved and formatted roll, or the error said roll created
|
// SolvedRoll is the complete solved and formatted roll, or the error said roll created
|
||||||
|
|
|
@ -83,8 +83,18 @@ export const runCmd = (rollRequest: QueuedRoll): SolvedRoll => {
|
||||||
line1 = ` rolled:\n\`${rawCmd}\``;
|
line1 = ` rolled:\n\`${rawCmd}\``;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// List number of iterations on simulated nominals
|
||||||
if (rollRequest.modifiers.simulatedNominal) line2 += `Iterations performed per roll: \`${rollRequest.modifiers.simulatedNominal}\`\n`;
|
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
|
// Fill out all of the details and results now
|
||||||
tempReturnData.forEach((e) => {
|
tempReturnData.forEach((e) => {
|
||||||
loopCountCheck();
|
loopCountCheck();
|
||||||
|
@ -129,9 +139,6 @@ export const runCmd = (rollRequest: QueuedRoll): SolvedRoll => {
|
||||||
returnMsg.line2 = line2;
|
returnMsg.line2 = line2;
|
||||||
returnMsg.line3 = line3;
|
returnMsg.line3 = line3;
|
||||||
|
|
||||||
// Reduce counts to a single object
|
|
||||||
returnMsg.counts = reduceCountDetails(tempCountDetails);
|
|
||||||
|
|
||||||
// Reduce rollDist maps into a single map
|
// Reduce rollDist maps into a single map
|
||||||
returnMsg.rollDistributions = reduceRollDistMaps(tempRollDists);
|
returnMsg.rollDistributions = reduceRollDistMaps(tempRollDists);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -113,6 +113,7 @@ export const tokenizeCmd = (
|
||||||
containsCrit: simulatedData.some((data) => data.containsCrit),
|
containsCrit: simulatedData.some((data) => data.containsCrit),
|
||||||
containsFail: simulatedData.some((data) => data.containsFail),
|
containsFail: simulatedData.some((data) => data.containsFail),
|
||||||
initConfig: simulatedData[0].initConfig,
|
initConfig: simulatedData[0].initConfig,
|
||||||
|
isComplex: simulatedData[0].isComplex,
|
||||||
});
|
});
|
||||||
loggingEnabled && log(LT.LOG, `SN on, returnData updated ${JSON.stringify(returnData)}`);
|
loggingEnabled && log(LT.LOG, `SN on, returnData updated ${JSON.stringify(returnData)}`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ export interface RollSet {
|
||||||
exploding: boolean;
|
exploding: boolean;
|
||||||
critHit: boolean;
|
critHit: boolean;
|
||||||
critFail: boolean;
|
critFail: boolean;
|
||||||
|
isComplex: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// CountDetails is the object holding the count data for creating the Count Embed
|
// CountDetails is the object holding the count data for creating the Count Embed
|
||||||
|
|
|
@ -60,6 +60,13 @@ export const executeRoll = (rollStr: string, modifiers: RollModifiers): RollSet[
|
||||||
exploding: false,
|
exploding: false,
|
||||||
critHit: false,
|
critHit: false,
|
||||||
critFail: 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
|
// Initial rolling, not handling reroll or exploding here
|
||||||
|
|
|
@ -16,6 +16,7 @@ export const generateFormattedRoll = (rollConf: string, modifiers: RollModifiers
|
||||||
let tempDetails = '[';
|
let tempDetails = '[';
|
||||||
let tempCrit = false;
|
let tempCrit = false;
|
||||||
let tempFail = false;
|
let tempFail = false;
|
||||||
|
let tempComplex = false;
|
||||||
|
|
||||||
// Generate the roll, passing flags thru
|
// Generate the roll, passing flags thru
|
||||||
const tempRollSet = executeRoll(rollConf, modifiers);
|
const tempRollSet = executeRoll(rollConf, modifiers);
|
||||||
|
@ -46,6 +47,9 @@ export const generateFormattedRoll = (rollConf: string, modifiers: RollModifiers
|
||||||
if (e.critFail) {
|
if (e.critFail) {
|
||||||
tempFail = true;
|
tempFail = true;
|
||||||
}
|
}
|
||||||
|
if (e.isComplex) {
|
||||||
|
tempComplex = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// If the roll was a crit hit or fail, or dropped/rerolled, add the formatting needed
|
// If the roll was a crit hit or fail, or dropped/rerolled, add the formatting needed
|
||||||
if (e.critHit) {
|
if (e.critHit) {
|
||||||
|
@ -84,6 +88,7 @@ export const generateFormattedRoll = (rollConf: string, modifiers: RollModifiers
|
||||||
details: tempDetails,
|
details: tempDetails,
|
||||||
containsCrit: tempCrit,
|
containsCrit: tempCrit,
|
||||||
containsFail: tempFail,
|
containsFail: tempFail,
|
||||||
|
isComplex: tempComplex,
|
||||||
},
|
},
|
||||||
countDetails: modifiers.count || modifiers.confirmCrit ? rollCounter(tempRollSet) : rollCounter([]),
|
countDetails: modifiers.count || modifiers.confirmCrit ? rollCounter(tempRollSet) : rollCounter([]),
|
||||||
rollDistributions: modifiers.rollDist ? createRollDistMap(tempRollSet) : new Map<string, number[]>(),
|
rollDistributions: modifiers.rollDist ? createRollDistMap(tempRollSet) : new Map<string, number[]>(),
|
||||||
|
|
|
@ -4,6 +4,7 @@ export interface SolvedStep {
|
||||||
details: string;
|
details: string;
|
||||||
containsCrit: boolean;
|
containsCrit: boolean;
|
||||||
containsFail: boolean;
|
containsFail: boolean;
|
||||||
|
isComplex: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Joined type for mathConf as its a "WIP" variable and moved everything from string->number->SolvedStep
|
// Joined type for mathConf as its a "WIP" variable and moved everything from string->number->SolvedStep
|
||||||
|
|
|
@ -23,6 +23,7 @@ export const mathSolver = (conf: MathConf[], wrapDetails = false): SolvedStep =>
|
||||||
details: '',
|
details: '',
|
||||||
containsCrit: false,
|
containsCrit: false,
|
||||||
containsFail: false,
|
containsFail: false,
|
||||||
|
isComplex: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
// If entering with a single number, note it now
|
// 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
|
// Init temp math to NaN to catch bad parsing
|
||||||
let oper1 = NaN;
|
let oper1 = NaN;
|
||||||
let oper2 = NaN;
|
let oper2 = NaN;
|
||||||
const subStepSolve = {
|
const subStepSolve: SolvedStep = {
|
||||||
total: NaN,
|
total: NaN,
|
||||||
details: '',
|
details: '',
|
||||||
containsCrit: false,
|
containsCrit: false,
|
||||||
containsFail: false,
|
containsFail: false,
|
||||||
|
isComplex: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
// If operand1 is a SolvedStep, populate our subStepSolve with its details and crit/fail flags
|
// 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.details = `${operand1.details}\\${conf[i]}`;
|
||||||
subStepSolve.containsCrit = operand1.containsCrit;
|
subStepSolve.containsCrit = operand1.containsCrit;
|
||||||
subStepSolve.containsFail = operand1.containsFail;
|
subStepSolve.containsFail = operand1.containsFail;
|
||||||
|
subStepSolve.isComplex = operand1.isComplex;
|
||||||
} else {
|
} else {
|
||||||
// else parse it as a number and add it to the subStep details
|
// else parse it as a number and add it to the subStep details
|
||||||
if (operand1 || operand1 == 0) {
|
if (operand1 || operand1 == 0) {
|
||||||
|
@ -130,6 +133,7 @@ export const mathSolver = (conf: MathConf[], wrapDetails = false): SolvedStep =>
|
||||||
subStepSolve.details += operand2.details;
|
subStepSolve.details += operand2.details;
|
||||||
subStepSolve.containsCrit = subStepSolve.containsCrit || operand2.containsCrit;
|
subStepSolve.containsCrit = subStepSolve.containsCrit || operand2.containsCrit;
|
||||||
subStepSolve.containsFail = subStepSolve.containsFail || operand2.containsFail;
|
subStepSolve.containsFail = subStepSolve.containsFail || operand2.containsFail;
|
||||||
|
subStepSolve.isComplex = subStepSolve.isComplex || operand2.isComplex;
|
||||||
} else {
|
} else {
|
||||||
// else parse it as a number and add it to the subStep details
|
// else parse it as a number and add it to the subStep details
|
||||||
oper2 = parseFloat(operand2.toString());
|
oper2 = parseFloat(operand2.toString());
|
||||||
|
@ -193,6 +197,7 @@ export const mathSolver = (conf: MathConf[], wrapDetails = false): SolvedStep =>
|
||||||
stepSolve.details = tempConf.details;
|
stepSolve.details = tempConf.details;
|
||||||
stepSolve.containsCrit = tempConf.containsCrit;
|
stepSolve.containsCrit = tempConf.containsCrit;
|
||||||
stepSolve.containsFail = tempConf.containsFail;
|
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
|
// If this was a nested call, add on parens around the details to show what math we've done
|
||||||
|
|
|
@ -60,6 +60,7 @@ export const tokenizeMath = (cmd: string, modifiers: RollModifiers, previousResu
|
||||||
details: '*e*',
|
details: '*e*',
|
||||||
containsCrit: false,
|
containsCrit: false,
|
||||||
containsFail: false,
|
containsFail: false,
|
||||||
|
isComplex: false,
|
||||||
};
|
};
|
||||||
} else if (curMathConfStr.toLowerCase() === 'lemon' || curMathConfStr.toLowerCase() === '🍋') {
|
} else if (curMathConfStr.toLowerCase() === 'lemon' || curMathConfStr.toLowerCase() === '🍋') {
|
||||||
mathConf[i] = {
|
mathConf[i] = {
|
||||||
|
@ -67,6 +68,7 @@ export const tokenizeMath = (cmd: string, modifiers: RollModifiers, previousResu
|
||||||
details: '🍋',
|
details: '🍋',
|
||||||
containsCrit: false,
|
containsCrit: false,
|
||||||
containsFail: false,
|
containsFail: false,
|
||||||
|
isComplex: false,
|
||||||
};
|
};
|
||||||
} else if (curMathConfStr.toLowerCase() === 'fart' || curMathConfStr.toLowerCase() === '💩') {
|
} else if (curMathConfStr.toLowerCase() === 'fart' || curMathConfStr.toLowerCase() === '💩') {
|
||||||
mathConf[i] = {
|
mathConf[i] = {
|
||||||
|
@ -74,6 +76,7 @@ export const tokenizeMath = (cmd: string, modifiers: RollModifiers, previousResu
|
||||||
details: '💩',
|
details: '💩',
|
||||||
containsCrit: false,
|
containsCrit: false,
|
||||||
containsFail: false,
|
containsFail: false,
|
||||||
|
isComplex: false,
|
||||||
};
|
};
|
||||||
} else if (curMathConfStr.toLowerCase() === 'sex' || curMathConfStr.toLowerCase() === '🍆🍑' || curMathConfStr.toLowerCase() === '🍑🍆') {
|
} else if (curMathConfStr.toLowerCase() === 'sex' || curMathConfStr.toLowerCase() === '🍆🍑' || curMathConfStr.toLowerCase() === '🍑🍆') {
|
||||||
mathConf[i] = {
|
mathConf[i] = {
|
||||||
|
@ -81,6 +84,7 @@ export const tokenizeMath = (cmd: string, modifiers: RollModifiers, previousResu
|
||||||
details: '( ͡° ͜ʖ ͡°)',
|
details: '( ͡° ͜ʖ ͡°)',
|
||||||
containsCrit: false,
|
containsCrit: false,
|
||||||
containsFail: false,
|
containsFail: false,
|
||||||
|
isComplex: false,
|
||||||
};
|
};
|
||||||
} else if (curMathConfStr.toLowerCase() === 'inf' || curMathConfStr.toLowerCase() === 'infinity' || curMathConfStr.toLowerCase() === '∞') {
|
} else if (curMathConfStr.toLowerCase() === 'inf' || curMathConfStr.toLowerCase() === 'infinity' || curMathConfStr.toLowerCase() === '∞') {
|
||||||
// If the operand is the constant Infinity, create a SolvedStep for it
|
// 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: '∞',
|
details: '∞',
|
||||||
containsCrit: false,
|
containsCrit: false,
|
||||||
containsFail: false,
|
containsFail: false,
|
||||||
|
isComplex: false,
|
||||||
};
|
};
|
||||||
} else if (curMathConfStr.toLowerCase() === 'pi' || curMathConfStr.toLowerCase() === '𝜋') {
|
} else if (curMathConfStr.toLowerCase() === 'pi' || curMathConfStr.toLowerCase() === '𝜋') {
|
||||||
// If the operand is the constant pi, create a SolvedStep for it
|
// 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: '𝜋',
|
details: '𝜋',
|
||||||
containsCrit: false,
|
containsCrit: false,
|
||||||
containsFail: false,
|
containsFail: false,
|
||||||
|
isComplex: false,
|
||||||
};
|
};
|
||||||
} else if (curMathConfStr.toLowerCase() === 'pie' || curMathConfStr.toLowerCase() === '🥧') {
|
} 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)
|
// 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: '𝜋',
|
details: '𝜋',
|
||||||
containsCrit: false,
|
containsCrit: false,
|
||||||
containsFail: false,
|
containsFail: false,
|
||||||
|
isComplex: false,
|
||||||
};
|
};
|
||||||
mathConf.splice(
|
mathConf.splice(
|
||||||
i + 1,
|
i + 1,
|
||||||
|
@ -116,6 +123,7 @@ export const tokenizeMath = (cmd: string, modifiers: RollModifiers, previousResu
|
||||||
details: '*e*',
|
details: '*e*',
|
||||||
containsCrit: false,
|
containsCrit: false,
|
||||||
containsFail: false,
|
containsFail: false,
|
||||||
|
isComplex: false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
@ -184,6 +192,7 @@ export const tokenizeMath = (cmd: string, modifiers: RollModifiers, previousResu
|
||||||
containsCrit: tempSolved.containsCrit,
|
containsCrit: tempSolved.containsCrit,
|
||||||
containsFail: tempSolved.containsFail,
|
containsFail: tempSolved.containsFail,
|
||||||
initConfig: cmd,
|
initConfig: cmd,
|
||||||
|
isComplex: tempSolved.isComplex,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
countDetails,
|
countDetails,
|
||||||
|
|
Loading…
Reference in New Issue