1
1
mirror of https://github.com/Burn-E99/TheArtificer.git synced 2026-01-08 05:17:54 -05:00

Formatting updates, slight reorg on loop control, drop loop count to 1million, use new Log4Deno to get closeLog func, fix logging in workers

This commit is contained in:
Ean Milligan
2025-04-26 22:34:07 -04:00
parent 8f24a3bfae
commit 09e97eabc1
9 changed files with 291 additions and 232 deletions

View File

@ -16,7 +16,7 @@ import { fullSolver } from './solver.ts';
// parseRoll handles converting fullCmd into a computer readable format for processing, and finally executes the solving
export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll => {
const operators = ['^', '*', '/', '%', '+', '-', '(', ')'];
const returnmsg = <SolvedRoll> {
const returnmsg = <SolvedRoll>{
error: false,
errorCode: '',
errorMsg: '',
@ -39,23 +39,25 @@ export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll
const sepRolls = fullCmd.split(config.prefix);
const tempReturnData: ReturnData[] = [];
const tempCountDetails: CountDetails[] = [{
total: 0,
successful: 0,
failed: 0,
rerolled: 0,
dropped: 0,
exploded: 0,
}];
const tempCountDetails: CountDetails[] = [
{
total: 0,
successful: 0,
failed: 0,
rerolled: 0,
dropped: 0,
exploded: 0,
},
];
// Loop thru all roll/math ops
for (const sepRoll of sepRolls) {
loggingEnabled && log(LT.LOG, `Parsing roll ${fullCmd} | Working ${sepRoll}`);
// Split the current iteration on the command postfix to separate the operation to be parsed and the text formatting after the opertaion
// Split the current iteration on the command postfix to separate the operation to be parsed and the text formatting after the operation
const [tempConf, tempFormat] = sepRoll.split(config.postfix);
// Remove all spaces from the operation config and split it by any operator (keeping the operator in mathConf for fullSolver to do math on)
const mathConf: (string | number | SolvedStep)[] = <(string | number | SolvedStep)[]> tempConf.replace(/ /g, '').split(/([-+()*/%^])/g);
const mathConf: (string | number | SolvedStep)[] = <(string | number | SolvedStep)[]>tempConf.replace(/ /g, '').split(/([-+()*/%^])/g);
// Verify there are equal numbers of opening and closing parenthesis by adding 1 for opening parens and subtracting 1 for closing parens
let parenCnt = 0;
@ -98,7 +100,11 @@ export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll
containsCrit: false,
containsFail: false,
};
} else if (mathConf[i].toString().toLowerCase() === 'inf' || mathConf[i].toString().toLowerCase() === 'infinity' || mathConf[i].toString().toLowerCase() === '∞') {
} else if (
mathConf[i].toString().toLowerCase() === 'inf' ||
mathConf[i].toString().toLowerCase() === 'infinity' ||
mathConf[i].toString().toLowerCase() === '∞'
) {
// If the operand is the constant Infinity, create a SolvedStep for it
mathConf[i] = {
total: Infinity,
@ -122,12 +128,19 @@ export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll
containsCrit: false,
containsFail: false,
};
mathConf.splice(i + 1, 0, ...['*', {
total: Math.E,
details: '*e*',
containsCrit: false,
containsFail: false,
}]);
mathConf.splice(
i + 1,
0,
...[
'*',
{
total: Math.E,
details: '*e*',
containsCrit: false,
containsFail: false,
},
]
);
} else if (!operators.includes(mathConf[i].toString())) {
// If nothing else has handled it by now, try it as a roll
const formattedRoll = formatRoll(mathConf[i].toString(), modifiers.maxRoll, modifiers.nominalRoll);
@ -137,10 +150,10 @@ export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll
if (mathConf[i - 1] === '-' && ((!mathConf[i - 2] && mathConf[i - 2] !== 0) || mathConf[i - 2] === '(')) {
if (typeof mathConf[i] === 'number') {
mathConf[i] = <number> mathConf[i] * -1;
mathConf[i] = <number>mathConf[i] * -1;
} else {
(<SolvedStep> mathConf[i]).total = (<SolvedStep> mathConf[i]).total * -1;
(<SolvedStep> mathConf[i]).details = `-${(<SolvedStep> mathConf[i]).details}`;
(<SolvedStep>mathConf[i]).total = (<SolvedStep>mathConf[i]).total * -1;
(<SolvedStep>mathConf[i]).details = `-${(<SolvedStep>mathConf[i]).details}`;
}
mathConf.splice(i - 1, 1);
i--;
@ -221,7 +234,10 @@ export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll
line2 += `${preFormat}${e.rollTotal}${postFormat}, `;
}
line2 = line2.replace(/\*\*\*\*/g, '** **').replace(/____/g, '__ __').replace(/~~~~/g, '~~ ~~');
line2 = line2
.replace(/\*\*\*\*/g, '** **')
.replace(/____/g, '__ __')
.replace(/~~~~/g, '~~ ~~');
line3 += `\`${e.initConfig}\` = ${e.rollDetails} = ${preFormat}${e.rollTotal}${postFormat}\n`;
});
@ -245,7 +261,8 @@ export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll
dropped: acc.dropped + cnt.dropped,
exploded: acc.exploded + cnt.exploded,
}));
} catch (solverError) {
} catch (e) {
const solverError = e as Error;
// Welp, the unthinkable happened, we hit an error
// Split on _ for the error messages that have more info than just their name

View File

@ -17,6 +17,7 @@ import { ApiQueuedRoll, DDQueuedRoll, RollModifiers } from '../mod.d.ts';
import { generateCountDetailsEmbed, generateDMFailed, generateRollEmbed, infoColor2, rollingEmbed } from '../commandUtils.ts';
import stdResp from '../endpoints/stdResponses.ts';
import utils from '../utils.ts';
import { loggingEnabled } from './rollUtils.ts';
let currentWorkers = 0;
const rollQueue: Array<ApiQueuedRoll | DDQueuedRoll> = [];
@ -59,6 +60,7 @@ const handleRollWorker = (rq: ApiQueuedRoll | DDQueuedRoll) => {
rollWorker.addEventListener('message', async (workerMessage) => {
if (workerMessage.data === 'ready') {
loggingEnabled && log(LT.LOG, `Sending roll to worker: ${rq.rollCmd}, ${JSON.stringify(rq.modifiers)}`);
rollWorker.postMessage({
rollCmd: rq.rollCmd,
modifiers: rq.modifiers,
@ -70,9 +72,12 @@ const handleRollWorker = (rq: ApiQueuedRoll | DDQueuedRoll) => {
currentWorkers--;
clearTimeout(workerTimeout);
const returnmsg = workerMessage.data;
loggingEnabled && log(LT.LOG, `Roll came back from worker: ${returnmsg.line1.length} |&| ${returnmsg.line2.length} |&| ${returnmsg.line3.length} `);
loggingEnabled && log(LT.LOG, `Roll came back from worker: ${returnmsg.line1} |&| ${returnmsg.line2} |&| ${returnmsg.line3} `);
const pubEmbedDetails = await generateRollEmbed(rq.apiRoll ? rq.api.userId : rq.dd.message.authorId, returnmsg, rq.modifiers);
const gmEmbedDetails = await generateRollEmbed(rq.apiRoll ? rq.api.userId : rq.dd.message.authorId, returnmsg, gmModifiers);
const countEmbed = generateCountDetailsEmbed(returnmsg.counts);
loggingEnabled && log(LT.LOG, `Embeds are generated: ${JSON.stringify(pubEmbedDetails)} |&| ${JSON.stringify(gmEmbedDetails)}`);
// If there was an error, report it to the user in hopes that they can determine what they did wrong
if (returnmsg.error) {

View File

@ -6,7 +6,7 @@ import {
import { ReturnData, RollSet } from './solver.d.ts';
export const loggingEnabled = false;
export const loggingEnabled = true;
// genRoll(size) returns number
// genRoll rolls a die of size size and returns the result
@ -15,7 +15,7 @@ export const genRoll = (size: number, maximiseRoll: boolean, nominalRoll: boolea
return size;
} else {
// Math.random * size will return a decimal number between 0 and size (excluding size), so add 1 and floor the result to not get 0 as a result
return nominalRoll ? ((size / 2) + 0.5) : Math.floor((Math.random() * size) + 1);
return nominalRoll ? size / 2 + 0.5 : Math.floor(Math.random() * size + 1);
}
};

View File

@ -1,10 +1,15 @@
import { initLog, closeLog } from '../../deps.ts';
import { DEBUG } from '../../flags.ts';
import { parseRoll } from './parser.ts';
import { loggingEnabled } from './rollUtils.ts';
loggingEnabled && initLog('logs/worker', DEBUG);
// Alert rollQueue that this worker is ready
self.postMessage('ready');
// Handle the roll
self.onmessage = async (e: any) => {
self.onmessage = async (e) => {
const payload = e.data;
const returnmsg = parseRoll(payload.rollCmd, payload.modifiers) || {
error: true,
@ -23,5 +28,6 @@ self.onmessage = async (e: any) => {
},
};
self.postMessage(returnmsg);
loggingEnabled && (await closeLog());
self.close();
};

View File

@ -12,10 +12,10 @@ import { compareOrigidx, compareRolls, genFateRoll, genRoll, loggingEnabled } fr
// roll parses and executes the rollStr, if needed it will also make the roll the maximum or average
export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolean): RollSet[] => {
/* Roll Capabilities
* Deciphers and rolls a single dice roll set
*
* Check the README.md of this project for details on the roll options. I gave up trying to keep three places updated at once.
*/
* Deciphers and rolls a single dice roll set
*
* Check the README.md of this project for details on the roll options. I gave up trying to keep three places updated at once.
*/
// Make entire roll lowercase for ease of parsing
rollStr = rollStr.toLowerCase();
@ -47,22 +47,22 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
reroll: {
on: false,
once: false,
nums: <number[]> [],
nums: <number[]>[],
},
critScore: {
on: false,
range: <number[]> [],
range: <number[]>[],
},
critFail: {
on: false,
range: <number[]> [],
range: <number[]>[],
},
exploding: {
on: false,
once: false,
compounding: false,
penetrating: false,
nums: <number[]> [],
nums: <number[]>[],
},
};
@ -146,7 +146,7 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
// Loop until all remaining args are parsed
while (remains.length > 0) {
loggingEnabled && log(LT.LOG, `handling ${rollType} ${rollStr} | Parsing remains ${remains}`);
loggingEnabled && log(LT.LOG, `Handling ${rollType} ${rollStr} | Parsing remains ${remains}`);
// Find the next number in the remains to be able to cut out the rule name
let afterSepIdx = remains.search(/\d/);
if (afterSepIdx < 0) {
@ -190,7 +190,7 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
case 'ro':
case 'ro=':
rollConf.reroll.once = true;
// falls through as ro/ro= functions the same as r/r= in this context
// falls through as ro/ro= functions the same as r/r= in this context
case 'r':
case 'r=':
// Configure Reroll (this can happen multiple times)
@ -199,23 +199,23 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
break;
case 'ro>':
rollConf.reroll.once = true;
// falls through as ro> functions the same as r> in this context
// falls through as ro> functions the same as r> in this context
case 'r>':
// Configure reroll for all numbers greater than or equal to tNum (this could happen multiple times, but why)
rollConf.reroll.on = true;
for (let i = tNum; i <= rollConf.dieSize; i++) {
loggingEnabled && log(LT.LOG, `handling ${rollType} ${rollStr} | Parsing r> ${i}`);
loggingEnabled && log(LT.LOG, `Handling ${rollType} ${rollStr} | Parsing r> ${i}`);
rollConf.reroll.nums.push(i);
}
break;
case 'ro<':
rollConf.reroll.once = true;
// falls through as ro< functions the same as r< in this context
// falls through as ro< functions the same as r< in this context
case 'r<':
// Configure reroll for all numbers less than or equal to tNum (this could happen multiple times, but why)
rollConf.reroll.on = true;
for (let i = 1; i <= tNum; i++) {
loggingEnabled && log(LT.LOG, `handling ${rollType} ${rollStr} | Parsing r< ${i}`);
loggingEnabled && log(LT.LOG, `Handling ${rollType} ${rollStr} | Parsing r< ${i}`);
rollConf.reroll.nums.push(i);
}
break;
@ -229,7 +229,7 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
// Configure CritScore for all numbers greater than or equal to tNum (this could happen multiple times, but why)
rollConf.critScore.on = true;
for (let i = tNum; i <= rollConf.dieSize; i++) {
loggingEnabled && log(LT.LOG, `handling ${rollType} ${rollStr} | Parsing cs> ${i}`);
loggingEnabled && log(LT.LOG, `Handling ${rollType} ${rollStr} | Parsing cs> ${i}`);
rollConf.critScore.range.push(i);
}
break;
@ -237,7 +237,7 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
// Configure CritScore for all numbers less than or equal to tNum (this could happen multiple times, but why)
rollConf.critScore.on = true;
for (let i = 0; i <= tNum; i++) {
loggingEnabled && log(LT.LOG, `handling ${rollType} ${rollStr} | Parsing cs< ${i}`);
loggingEnabled && log(LT.LOG, `Handling ${rollType} ${rollStr} | Parsing cs< ${i}`);
rollConf.critScore.range.push(i);
}
break;
@ -251,7 +251,7 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
// Configure CritFail for all numbers greater than or equal to tNum (this could happen multiple times, but why)
rollConf.critFail.on = true;
for (let i = tNum; i <= rollConf.dieSize; i++) {
loggingEnabled && log(LT.LOG, `handling ${rollType} ${rollStr} | Parsing cf> ${i}`);
loggingEnabled && log(LT.LOG, `Handling ${rollType} ${rollStr} | Parsing cf> ${i}`);
rollConf.critFail.range.push(i);
}
break;
@ -259,7 +259,7 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
// Configure CritFail for all numbers less than or equal to tNum (this could happen multiple times, but why)
rollConf.critFail.on = true;
for (let i = 0; i <= tNum; i++) {
loggingEnabled && log(LT.LOG, `handling ${rollType} ${rollStr} | Parsing cf< ${i}`);
loggingEnabled && log(LT.LOG, `Handling ${rollType} ${rollStr} | Parsing cf< ${i}`);
rollConf.critFail.range.push(i);
}
break;
@ -292,7 +292,7 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
// Configure Exploding for all numbers greater than or equal to tNum (this could happen multiple times, but why)
rollConf.exploding.on = true;
for (let i = tNum; i <= rollConf.dieSize; i++) {
loggingEnabled && log(LT.LOG, `handling ${rollType} ${rollStr} | Parsing !> ${i}`);
loggingEnabled && log(LT.LOG, `Handling ${rollType} ${rollStr} | Parsing !> ${i}`);
rollConf.exploding.nums.push(i);
}
break;
@ -303,7 +303,7 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
// Configure Exploding for all numbers less than or equal to tNum (this could happen multiple times, but why)
rollConf.exploding.on = true;
for (let i = 1; i <= tNum; i++) {
loggingEnabled && log(LT.LOG, `handling ${rollType} ${rollStr} | Parsing !< ${i}`);
loggingEnabled && log(LT.LOG, `Handling ${rollType} ${rollStr} | Parsing !< ${i}`);
rollConf.exploding.nums.push(i);
}
break;
@ -349,7 +349,7 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
// Since only one drop or keep option can be active, count how many are active to throw the right error
let dkdkCnt = 0;
[rollConf.drop.on, rollConf.keep.on, rollConf.dropHigh.on, rollConf.keepLow.on].forEach((e) => {
loggingEnabled && log(LT.LOG, `handling ${rollType} ${rollStr} | Checking if drop/keep is on ${e}`);
loggingEnabled && log(LT.LOG, `Handling ${rollType} ${rollStr} | Checking if drop/keep is on ${e}`);
if (e) {
dkdkCnt++;
}
@ -376,27 +376,27 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
// Roll the roll
const rollSet = [];
/* Roll will contain objects of the following format:
* {
* origidx: 0,
* roll: 0,
* dropped: false,
* rerolled: false,
* exploding: false,
* critHit: false,
* critFail: false
* }
*
* Each of these is defined as following:
* {
* origidx: The original index of the roll
* roll: The resulting roll on this die in the set
* dropped: This die is to be dropped as it was one of the dy lowest dice
* rerolled: This die has been rerolled as it matched rz, it is replaced by the very next die in the set
* exploding: This die was rolled as the previous die exploded (was a crit hit)
* critHit: This die matched csq[-u], max die value used if cs not used
* critFail: This die rolled a nat 1, a critical failure
* }
*/
* {
* origidx: 0,
* roll: 0,
* dropped: false,
* rerolled: false,
* exploding: false,
* critHit: false,
* critFail: false
* }
*
* Each of these is defined as following:
* {
* origidx: The original index of the roll
* roll: The resulting roll on this die in the set
* dropped: This die is to be dropped as it was one of the dy lowest dice
* rerolled: This die has been rerolled as it matched rz, it is replaced by the very next die in the set
* exploding: This die was rolled as the previous die exploded (was a crit hit)
* critHit: This die matched csq[-u], max die value used if cs not used
* critFail: This die rolled a nat 1, a critical failure
* }
*/
// Initialize a templet rollSet to copy multiple times
const templateRoll: RollSet = {
@ -415,8 +415,9 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
// Initial rolling, not handling reroll or exploding here
for (let i = 0; i < rollConf.dieCount; i++) {
loggingEnabled && log(LT.LOG, `handling ${rollType} ${rollStr} | Initial rolling ${i} of ${JSON.stringify(rollConf)}`);
loggingEnabled && log(LT.LOG, `${loopCount} Handling ${rollType} ${rollStr} | Initial rolling ${i} of ${JSON.stringify(rollConf)}`);
// If loopCount gets too high, stop trying to calculate infinity
loopCount++;
if (loopCount > config.limits.maxLoops) {
throw new Error('MaxLoopsExceeded');
}
@ -447,21 +448,21 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
// Push the newly created roll and loop again
rollSet.push(rolling);
loopCount++;
}
// If needed, handle rerolling and exploding dice now
if (rollConf.reroll.on || rollConf.exploding.on) {
for (let i = 0; i < rollSet.length; i++) {
loggingEnabled && log(LT.LOG, `handling ${rollType} ${rollStr} | Handling rerolling and exploding ${JSON.stringify(rollSet[i])}`);
loggingEnabled && log(LT.LOG, `${loopCount} Handling ${rollType} ${rollStr} | Handling rerolling and exploding ${JSON.stringify(rollSet[i])}`);
// If loopCount gets too high, stop trying to calculate infinity
loopCount++;
if (loopCount > config.limits.maxLoops) {
throw new Error('MaxLoopsExceeded');
}
// If we need to reroll this roll, flag its been replaced and...
// This big boolean statement first checks if reroll is on, if the roll is within the reroll range, and finally if ro is ON, make sure we haven't already rerolled the roll
if (rollConf.reroll.on && rollConf.reroll.nums.indexOf(rollSet[i].roll) >= 0 && (!rollConf.reroll.once || !rollSet[i ? (i - 1) : i].rerolled)) {
if (rollConf.reroll.on && rollConf.reroll.nums.indexOf(rollSet[i].roll) >= 0 && (!rollConf.reroll.once || !rollSet[i ? i - 1 : i].rerolled)) {
rollSet[i].rerolled = true;
// Copy the template to fill out for this iteration
@ -485,7 +486,9 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
// Slot this new roll in after the current iteration so it can be processed in the next loop
rollSet.splice(i + 1, 0, newReroll);
} else if (
rollConf.exploding.on && !rollSet[i].rerolled && (rollConf.exploding.nums.length ? rollConf.exploding.nums.indexOf(rollSet[i].roll) >= 0 : rollSet[i].critHit) &&
rollConf.exploding.on &&
!rollSet[i].rerolled &&
(rollConf.exploding.nums.length ? rollConf.exploding.nums.indexOf(rollSet[i].roll) >= 0 : rollSet[i].critHit) &&
(!rollConf.exploding.once || !rollSet[i].exploding)
) {
// If we have exploding.nums set, use those to determine the exploding range, and make sure if !o is on, make sure we don't repeatedly explode
@ -514,16 +517,15 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
// Slot this new roll in after the current iteration so it can be processed in the next loop
rollSet.splice(i + 1, 0, newExplodingRoll);
}
loopCount++;
}
}
// If penetrating is on, do the decrements
if (rollConf.exploding.penetrating) {
for (const penRoll of rollSet) {
loggingEnabled && log(LT.LOG, `handling ${rollType} ${rollStr} | Handling penetrating explosions ${JSON.stringify(penRoll)}`);
loggingEnabled && log(LT.LOG, `${loopCount} Handling ${rollType} ${rollStr} | Handling penetrating explosions ${JSON.stringify(penRoll)}`);
// If loopCount gets too high, stop trying to calculate infinity
loopCount++;
if (loopCount > config.limits.maxLoops) {
throw new Error('MaxLoopsExceeded');
}
@ -532,16 +534,15 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
if (penRoll.exploding) {
penRoll.roll--;
}
loopCount++;
}
}
// Handle compounding explosions
if (rollConf.exploding.compounding) {
for (let i = 0; i < rollSet.length; i++) {
loggingEnabled && log(LT.LOG, `handling ${rollType} ${rollStr} | Handling compounding explosions ${JSON.stringify(rollSet[i])}`);
loggingEnabled && log(LT.LOG, `${loopCount} Handling ${rollType} ${rollStr} | Handling compounding explosions ${JSON.stringify(rollSet[i])}`);
// If loopCount gets too high, stop trying to calculate infinity
loopCount++;
if (loopCount > config.limits.maxLoops) {
throw new Error('MaxLoopsExceeded');
}
@ -555,8 +556,6 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
rollSet.splice(i, 1);
i--;
}
loopCount++;
}
}
@ -567,18 +566,17 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
if (rollConf.reroll.on) {
for (let j = 0; j < rollSet.length; j++) {
// If loopCount gets too high, stop trying to calculate infinity
loopCount++;
if (loopCount > config.limits.maxLoops) {
throw new Error('MaxLoopsExceeded');
}
loggingEnabled && log(LT.LOG, `handling ${rollType} ${rollStr} | Setting originalIdx on ${JSON.stringify(rollSet[j])}`);
loggingEnabled && log(LT.LOG, `${loopCount} Handling ${rollType} ${rollStr} | Setting originalIdx on ${JSON.stringify(rollSet[j])}`);
rollSet[j].origidx = j;
if (rollSet[j].rerolled) {
rerollCount++;
}
loopCount++;
}
}
@ -621,18 +619,18 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
let i = 0;
while (dropCount > 0 && i < rollSet.length) {
// If loopCount gets too high, stop trying to calculate infinity
loopCount++;
if (loopCount > config.limits.maxLoops) {
throw new Error('MaxLoopsExceeded');
}
loggingEnabled && log(LT.LOG, `handling ${rollType} ${rollStr} | Dropping dice ${dropCount} ${JSON.stringify(rollSet[i])}`);
loggingEnabled && log(LT.LOG, `${loopCount} Handling ${rollType} ${rollStr} | Dropping dice ${dropCount} ${JSON.stringify(rollSet[i])}`);
// Skip all rolls that were rerolled
if (!rollSet[i].rerolled) {
rollSet[i].dropped = true;
dropCount--;
}
i++;
loopCount++;
}
// Finally, return the rollSet to its original order
@ -646,7 +644,7 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
// Sum up all rolls
for (const ovaRoll of rollSet) {
loggingEnabled && log(LT.LOG, `handling ${rollType} ${rollStr} | incrementing rollVals for ${ovaRoll}`);
loggingEnabled && log(LT.LOG, `Handling ${rollType} ${rollStr} | incrementing rollVals for ${ovaRoll}`);
rollVals[ovaRoll.roll - 1] += ovaRoll.roll;
}
@ -655,7 +653,7 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
// Drop all dice that are not a part of the max
for (const ovaRoll of rollSet) {
loggingEnabled && log(LT.LOG, `handling ${rollType} ${rollStr} | checking if this roll should be dropped ${ovaRoll.roll} | to keep: ${maxRoll}`);
loggingEnabled && log(LT.LOG, `Handling ${rollType} ${rollStr} | checking if this roll should be dropped ${ovaRoll.roll} | to keep: ${maxRoll}`);
if (ovaRoll.roll !== maxRoll) {
ovaRoll.dropped = true;
ovaRoll.critFail = false;