mirror of
https://github.com/Burn-E99/TheArtificer.git
synced 2026-01-08 05:17:54 -05:00
Mass spelling fix
This commit is contained in:
@ -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: '',
|
||||
@ -57,7 +57,7 @@ export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll
|
||||
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;
|
||||
@ -77,7 +77,7 @@ export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll
|
||||
|
||||
// Evaluate all rolls into stepSolve format and all numbers into floats
|
||||
for (let i = 0; i < mathConf.length; i++) {
|
||||
loggingEnabled && log(LT.LOG, `Parsing roll ${fullCmd} | Evaluating rolls into mathable items ${JSON.stringify(mathConf[i])}`);
|
||||
loggingEnabled && log(LT.LOG, `Parsing roll ${fullCmd} | Evaluating rolls into math-able items ${JSON.stringify(mathConf[i])}`);
|
||||
if (mathConf[i].toString().length === 0) {
|
||||
// If its an empty string, get it out of here
|
||||
mathConf.splice(i, 1);
|
||||
@ -139,7 +139,7 @@ export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll
|
||||
containsCrit: false,
|
||||
containsFail: false,
|
||||
},
|
||||
],
|
||||
]
|
||||
);
|
||||
} else if (!operators.includes(mathConf[i].toString())) {
|
||||
// If nothing else has handled it by now, try it as a roll
|
||||
@ -150,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--;
|
||||
@ -189,7 +189,7 @@ export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll
|
||||
let line2 = '';
|
||||
let line3 = '';
|
||||
|
||||
// If maximiseRoll or nominalRoll are on, mark the output as such, else use default formatting
|
||||
// If maximizeRoll or nominalRoll are on, mark the output as such, else use default formatting
|
||||
if (modifiers.maxRoll) {
|
||||
line1 = ` requested the theoretical maximum of:\n\`${config.prefix}${fullCmd}\``;
|
||||
line2 = 'Theoretical Maximum Results: ';
|
||||
@ -216,7 +216,7 @@ export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll
|
||||
let preFormat = '';
|
||||
let postFormat = '';
|
||||
|
||||
// If the roll containted a crit success or fail, set the formatting around it
|
||||
// If the roll contained a crit success or fail, set the formatting around it
|
||||
if (e.containsCrit) {
|
||||
preFormat = `**${preFormat}`;
|
||||
postFormat = `${postFormat}**`;
|
||||
@ -248,12 +248,12 @@ export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll
|
||||
}
|
||||
|
||||
// Fill in the return block
|
||||
returnmsg.line1 = line1;
|
||||
returnmsg.line2 = line2;
|
||||
returnmsg.line3 = line3;
|
||||
returnMsg.line1 = line1;
|
||||
returnMsg.line2 = line2;
|
||||
returnMsg.line3 = line3;
|
||||
|
||||
// Reduce counts to a single object
|
||||
returnmsg.counts = tempCountDetails.reduce((acc, cnt) => ({
|
||||
returnMsg.counts = tempCountDetails.reduce((acc, cnt) => ({
|
||||
total: acc.total + cnt.total,
|
||||
successful: acc.successful + cnt.successful,
|
||||
failed: acc.failed + cnt.failed,
|
||||
@ -344,16 +344,16 @@ export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll
|
||||
errorMsg = 'Error: Roll became undefined, one or more operands are not a roll or a number, check input';
|
||||
break;
|
||||
default:
|
||||
log(LT.ERROR, `Undangled Error: ${errorName}, ${errorDetails}`);
|
||||
log(LT.ERROR, `Unhandled Parser Error: ${errorName}, ${errorDetails}`);
|
||||
errorMsg = `Unhandled Error: ${solverError.message}\nCheck input and try again, if issue persists, please use \`${config.prefix}report\` to alert the devs of the issue`;
|
||||
break;
|
||||
}
|
||||
|
||||
// Fill in the return block
|
||||
returnmsg.error = true;
|
||||
returnmsg.errorCode = solverError.message;
|
||||
returnmsg.errorMsg = errorMsg;
|
||||
returnMsg.error = true;
|
||||
returnMsg.errorCode = solverError.message;
|
||||
returnMsg.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
return returnmsg;
|
||||
return returnMsg;
|
||||
};
|
||||
|
||||
@ -9,16 +9,16 @@ import { rollCounter } from './counter.ts';
|
||||
import { RollFormat } from './solver.d.ts';
|
||||
import { loggingEnabled } from './rollUtils.ts';
|
||||
|
||||
// formatRoll(rollConf, maximiseRoll, nominalRoll) returns one SolvedStep
|
||||
// formatRoll(rollConf, maximizeRoll, nominalRoll) returns one SolvedStep
|
||||
// formatRoll handles creating and formatting the completed rolls into the SolvedStep format
|
||||
export const formatRoll = (rollConf: string, maximiseRoll: boolean, nominalRoll: boolean): RollFormat => {
|
||||
export const formatRoll = (rollConf: string, maximizeRoll: boolean, nominalRoll: boolean): RollFormat => {
|
||||
let tempTotal = 0;
|
||||
let tempDetails = '[';
|
||||
let tempCrit = false;
|
||||
let tempFail = false;
|
||||
|
||||
// Generate the roll, passing flags thru
|
||||
const tempRollSet = roll(rollConf, maximiseRoll, nominalRoll);
|
||||
const tempRollSet = roll(rollConf, maximizeRoll, nominalRoll);
|
||||
|
||||
// Loop thru all parts of the roll to document everything that was done to create the total roll
|
||||
tempRollSet.forEach((e) => {
|
||||
|
||||
@ -44,12 +44,12 @@ const handleRollWorker = (rq: ApiQueuedRoll | DDQueuedRoll) => {
|
||||
(
|
||||
await generateRollEmbed(
|
||||
rq.dd.message.authorId,
|
||||
<SolvedRoll> {
|
||||
<SolvedRoll>{
|
||||
error: true,
|
||||
errorCode: 'TooComplex',
|
||||
errorMsg: 'Error: Roll took too long to process, try breaking roll down into simpler parts',
|
||||
},
|
||||
<RollModifiers> {},
|
||||
<RollModifiers>{}
|
||||
)
|
||||
).embed,
|
||||
],
|
||||
@ -71,18 +71,18 @@ const handleRollWorker = (rq: ApiQueuedRoll | DDQueuedRoll) => {
|
||||
try {
|
||||
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);
|
||||
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) {
|
||||
if (returnMsg.error) {
|
||||
if (rq.apiRoll) {
|
||||
rq.api.resolve(stdResp.InternalServerError(returnmsg.errorMsg));
|
||||
rq.api.resolve(stdResp.InternalServerError(returnMsg.errorMsg));
|
||||
} else {
|
||||
rq.dd.m.edit({ embeds: [pubEmbedDetails.embed] });
|
||||
}
|
||||
@ -90,7 +90,7 @@ const handleRollWorker = (rq: ApiQueuedRoll | DDQueuedRoll) => {
|
||||
if (rq.apiRoll || (DEVMODE && config.logRolls)) {
|
||||
// If enabled, log rolls so we can see what went wrong
|
||||
dbClient
|
||||
.execute(queries.insertRollLogCmd(rq.apiRoll ? 1 : 0, 1), [rq.originalCommand, returnmsg.errorCode, rq.apiRoll ? null : rq.dd.m.id])
|
||||
.execute(queries.insertRollLogCmd(rq.apiRoll ? 1 : 0, 1), [rq.originalCommand, returnMsg.errorCode, rq.apiRoll ? null : rq.dd.m.id])
|
||||
.catch((e) => utils.commonLoggers.dbError('rollQueue.ts:82', 'insert into', e));
|
||||
}
|
||||
} else {
|
||||
@ -167,7 +167,7 @@ const handleRollWorker = (rq: ApiQueuedRoll | DDQueuedRoll) => {
|
||||
|
||||
if (rq.apiRoll && !apiErroredOut) {
|
||||
dbClient
|
||||
.execute(queries.insertRollLogCmd(1, 0), [rq.originalCommand, returnmsg.errorCode, n ? n.id : null])
|
||||
.execute(queries.insertRollLogCmd(1, 0), [rq.originalCommand, returnMsg.errorCode, n ? n.id : null])
|
||||
.catch((e) => utils.commonLoggers.dbError('rollQueue.ts:155', 'insert into', e));
|
||||
|
||||
rq.api.resolve(
|
||||
@ -175,19 +175,19 @@ const handleRollWorker = (rq: ApiQueuedRoll | DDQueuedRoll) => {
|
||||
JSON.stringify(
|
||||
rq.modifiers.count
|
||||
? {
|
||||
counts: countEmbed,
|
||||
details: pubEmbedDetails,
|
||||
}
|
||||
counts: countEmbed,
|
||||
details: pubEmbedDetails,
|
||||
}
|
||||
: {
|
||||
details: pubEmbedDetails,
|
||||
},
|
||||
),
|
||||
),
|
||||
details: pubEmbedDetails,
|
||||
}
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
log(LT.ERROR, `Unddandled Error: ${JSON.stringify(e)}`);
|
||||
log(LT.ERROR, `Unhandled RQ Error: ${JSON.stringify(e)}`);
|
||||
if (rq.apiRoll && !apiErroredOut) {
|
||||
rq.api.resolve(stdResp.InternalServerError(JSON.stringify(e)));
|
||||
}
|
||||
@ -223,7 +223,7 @@ The results for this roll will replace this message when it is done.`,
|
||||
setInterval(() => {
|
||||
log(
|
||||
LT.LOG,
|
||||
`Checking rollQueue for items, rollQueue length: ${rollQueue.length}, currentWorkers: ${currentWorkers}, config.limits.maxWorkers: ${config.limits.maxWorkers}`,
|
||||
`Checking rollQueue for items, rollQueue length: ${rollQueue.length}, currentWorkers: ${currentWorkers}, config.limits.maxWorkers: ${config.limits.maxWorkers}`
|
||||
);
|
||||
if (rollQueue.length && currentWorkers < config.limits.maxWorkers) {
|
||||
const temp = rollQueue.shift();
|
||||
|
||||
@ -10,8 +10,8 @@ export const loggingEnabled = true;
|
||||
|
||||
// genRoll(size) returns number
|
||||
// genRoll rolls a die of size size and returns the result
|
||||
export const genRoll = (size: number, maximiseRoll: boolean, nominalRoll: boolean): number => {
|
||||
if (maximiseRoll) {
|
||||
export const genRoll = (size: number, maximizeRoll: boolean, nominalRoll: boolean): number => {
|
||||
if (maximizeRoll) {
|
||||
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
|
||||
@ -21,12 +21,12 @@ export const genRoll = (size: number, maximiseRoll: boolean, nominalRoll: boolea
|
||||
|
||||
// genFateRoll returns -1|0|1
|
||||
// genFateRoll turns a d6 into a fate die, with sides: -1, -1, 0, 0, 1, 1
|
||||
export const genFateRoll = (maximiseRoll: boolean, nominalRoll: boolean): number => {
|
||||
export const genFateRoll = (maximizeRoll: boolean, nominalRoll: boolean): number => {
|
||||
if (nominalRoll) {
|
||||
return 0;
|
||||
} else {
|
||||
const sides = [-1, -1, 0, 0, 1, 1];
|
||||
return sides[genRoll(6, maximiseRoll, nominalRoll) - 1];
|
||||
return sides[genRoll(6, maximizeRoll, nominalRoll) - 1];
|
||||
}
|
||||
};
|
||||
|
||||
@ -55,12 +55,12 @@ export const compareTotalRolls = (a: ReturnData, b: ReturnData): number => {
|
||||
};
|
||||
|
||||
// compareRolls(a, b) returns -1|0|1
|
||||
// compareRolls is used to order an array of RollSets by RollSet.origidx
|
||||
export const compareOrigidx = (a: RollSet, b: RollSet): number => {
|
||||
if (a.origidx < b.origidx) {
|
||||
// compareRolls is used to order an array of RollSets by RollSet.origIdx
|
||||
export const compareOrigIdx = (a: RollSet, b: RollSet): number => {
|
||||
if (a.origIdx < b.origIdx) {
|
||||
return -1;
|
||||
}
|
||||
if (a.origidx > b.origidx) {
|
||||
if (a.origIdx > b.origIdx) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@ -73,8 +73,8 @@ export const escapeCharacters = (str: string, esc: string): string => {
|
||||
for (const e of esc) {
|
||||
loggingEnabled && log(LT.LOG, `Escaping character ${e} | ${str}, ${esc}`);
|
||||
// Create a new regex to look for that char that needs replaced and escape it
|
||||
const temprgx = new RegExp(`[${e}]`, 'g');
|
||||
str = str.replace(temprgx, `\\${e}`);
|
||||
const tempRgx = new RegExp(`[${e}]`, 'g');
|
||||
str = str.replace(tempRgx, `\\${e}`);
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
@ -11,7 +11,7 @@ self.postMessage('ready');
|
||||
// Handle the roll
|
||||
self.onmessage = async (e) => {
|
||||
const payload = e.data;
|
||||
const returnmsg = parseRoll(payload.rollCmd, payload.modifiers) || {
|
||||
const returnMsg = parseRoll(payload.rollCmd, payload.modifiers) || {
|
||||
error: true,
|
||||
errorCode: 'EmptyMessage',
|
||||
errorMsg: 'Error: Empty message',
|
||||
@ -27,7 +27,7 @@ self.onmessage = async (e) => {
|
||||
exploded: 0,
|
||||
},
|
||||
};
|
||||
self.postMessage(returnmsg);
|
||||
self.postMessage(returnMsg);
|
||||
loggingEnabled && (await closeLog());
|
||||
self.close();
|
||||
};
|
||||
|
||||
@ -6,11 +6,11 @@ import {
|
||||
} from '../../deps.ts';
|
||||
|
||||
import { RollConf, RollSet, RollType } from './solver.d.ts';
|
||||
import { compareOrigidx, compareRolls, genFateRoll, genRoll, loggingEnabled } from './rollUtils.ts';
|
||||
import { compareOrigIdx, compareRolls, genFateRoll, genRoll, loggingEnabled } from './rollUtils.ts';
|
||||
|
||||
// roll(rollStr, maximiseRoll, nominalRoll) returns RollSet
|
||||
// roll(rollStr, maximizeRoll, nominalRoll) returns RollSet
|
||||
// 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[] => {
|
||||
export const roll = (rollStr: string, maximizeRoll: boolean, nominalRoll: boolean): RollSet[] => {
|
||||
/* Roll Capabilities
|
||||
* Deciphers and rolls a single dice roll set
|
||||
*
|
||||
@ -21,7 +21,7 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
|
||||
rollStr = rollStr.toLowerCase();
|
||||
|
||||
// Split the roll on the die size (and the drop if its there)
|
||||
const dpts = rollStr.split('d');
|
||||
const dPts = rollStr.split('d');
|
||||
|
||||
// Initialize the configuration to store the parsed data
|
||||
let rollType: RollType = '';
|
||||
@ -47,35 +47,35 @@ 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[]>[],
|
||||
},
|
||||
};
|
||||
|
||||
// If the dpts is not long enough, throw error
|
||||
if (dpts.length < 2) {
|
||||
// If the dPts is not long enough, throw error
|
||||
if (dPts.length < 2) {
|
||||
throw new Error('YouNeedAD');
|
||||
}
|
||||
|
||||
// Fill out the die count, first item will either be an int or empty string, short circuit execution will take care of replacing the empty string with a 1
|
||||
const rawDC = dpts.shift() || '1';
|
||||
const rawDC = dPts.shift() || '1';
|
||||
const tempDC = rawDC.replace(/\D/g, '');
|
||||
// Rejoin all remaining parts
|
||||
let remains = dpts.join('d');
|
||||
let remains = dPts.join('d');
|
||||
|
||||
// Manual Parsing for custom roll types
|
||||
let manualParse = false;
|
||||
@ -119,10 +119,10 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
|
||||
rollType = 'roll20';
|
||||
rollConf.dieCount = parseInt(tempDC);
|
||||
|
||||
// Finds the end of the die size/beginnning of the additional options
|
||||
let afterDieIdx = dpts[0].search(/\D/);
|
||||
// Finds the end of the die size/beginning of the additional options
|
||||
let afterDieIdx = dPts[0].search(/\D/);
|
||||
if (afterDieIdx === -1) {
|
||||
afterDieIdx = dpts[0].length;
|
||||
afterDieIdx = dPts[0].length;
|
||||
}
|
||||
|
||||
// Get the die size out of the remains and into the rollConf
|
||||
@ -377,7 +377,7 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
|
||||
const rollSet = [];
|
||||
/* Roll will contain objects of the following format:
|
||||
* {
|
||||
* origidx: 0,
|
||||
* origIdx: 0,
|
||||
* roll: 0,
|
||||
* dropped: false,
|
||||
* rerolled: false,
|
||||
@ -388,7 +388,7 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
|
||||
*
|
||||
* Each of these is defined as following:
|
||||
* {
|
||||
* origidx: The original index of the roll
|
||||
* 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
|
||||
@ -398,10 +398,10 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
|
||||
* }
|
||||
*/
|
||||
|
||||
// Initialize a templet rollSet to copy multiple times
|
||||
// Initialize a template rollSet to copy multiple times
|
||||
const templateRoll: RollSet = {
|
||||
type: rollType,
|
||||
origidx: 0,
|
||||
origIdx: 0,
|
||||
roll: 0,
|
||||
dropped: false,
|
||||
rerolled: false,
|
||||
@ -424,10 +424,10 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
|
||||
|
||||
// Copy the template to fill out for this iteration
|
||||
const rolling = JSON.parse(JSON.stringify(templateRoll));
|
||||
// If maximiseRoll is on, set the roll to the dieSize, else if nominalRoll is on, set the roll to the average roll of dieSize, else generate a new random roll
|
||||
rolling.roll = rollType === 'fate' ? genFateRoll(maximiseRoll, nominalRoll) : genRoll(rollConf.dieSize, maximiseRoll, nominalRoll);
|
||||
// Set origidx of roll
|
||||
rolling.origidx = i;
|
||||
// If maximizeRoll is on, set the roll to the dieSize, else if nominalRoll is on, set the roll to the average roll of dieSize, else generate a new random roll
|
||||
rolling.roll = rollType === 'fate' ? genFateRoll(maximizeRoll, nominalRoll) : genRoll(rollConf.dieSize, maximizeRoll, nominalRoll);
|
||||
// Set origIdx of roll
|
||||
rolling.origIdx = i;
|
||||
|
||||
// If critScore arg is on, check if the roll should be a crit, if its off, check if the roll matches the die size
|
||||
if (rollConf.critScore.on && rollConf.critScore.range.indexOf(rolling.roll) >= 0) {
|
||||
@ -467,8 +467,8 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
|
||||
|
||||
// Copy the template to fill out for this iteration
|
||||
const newReroll = JSON.parse(JSON.stringify(templateRoll));
|
||||
// If maximiseRoll is on, set the roll to the dieSize, else if nominalRoll is on, set the roll to the average roll of dieSize, else generate a new random roll
|
||||
newReroll.roll = genRoll(rollConf.dieSize, maximiseRoll, nominalRoll);
|
||||
// If maximizeRoll is on, set the roll to the dieSize, else if nominalRoll is on, set the roll to the average roll of dieSize, else generate a new random roll
|
||||
newReroll.roll = genRoll(rollConf.dieSize, maximizeRoll, nominalRoll);
|
||||
|
||||
// If critScore arg is on, check if the roll should be a crit, if its off, check if the roll matches the die size
|
||||
if (rollConf.critScore.on && rollConf.critScore.range.indexOf(newReroll.roll) >= 0) {
|
||||
@ -496,8 +496,8 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
|
||||
|
||||
// Copy the template to fill out for this iteration
|
||||
const newExplodingRoll = JSON.parse(JSON.stringify(templateRoll));
|
||||
// If maximiseRoll is on, set the roll to the dieSize, else if nominalRoll is on, set the roll to the average roll of dieSize, else generate a new random roll
|
||||
newExplodingRoll.roll = genRoll(rollConf.dieSize, maximiseRoll, nominalRoll);
|
||||
// If maximizeRoll is on, set the roll to the dieSize, else if nominalRoll is on, set the roll to the average roll of dieSize, else generate a new random roll
|
||||
newExplodingRoll.roll = genRoll(rollConf.dieSize, maximizeRoll, nominalRoll);
|
||||
// Always mark this roll as exploding
|
||||
newExplodingRoll.exploding = true;
|
||||
|
||||
@ -572,7 +572,7 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
|
||||
}
|
||||
|
||||
loggingEnabled && log(LT.LOG, `${loopCount} Handling ${rollType} ${rollStr} | Setting originalIdx on ${JSON.stringify(rollSet[j])}`);
|
||||
rollSet[j].origidx = j;
|
||||
rollSet[j].origIdx = j;
|
||||
|
||||
if (rollSet[j].rerolled) {
|
||||
rerollCount++;
|
||||
@ -634,7 +634,7 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
|
||||
}
|
||||
|
||||
// Finally, return the rollSet to its original order
|
||||
rollSet.sort(compareOrigidx);
|
||||
rollSet.sort(compareOrigIdx);
|
||||
}
|
||||
|
||||
// Handle OVA dropping/keeping
|
||||
|
||||
2
src/solver/solver.d.ts
vendored
2
src/solver/solver.d.ts
vendored
@ -5,7 +5,7 @@ export type RollType = '' | 'roll20' | 'fate' | 'cwod' | 'ova';
|
||||
// RollSet is used to preserve all information about a calculated roll
|
||||
export type RollSet = {
|
||||
type: RollType;
|
||||
origidx: number;
|
||||
origIdx: number;
|
||||
roll: number;
|
||||
dropped: boolean;
|
||||
rerolled: boolean;
|
||||
|
||||
@ -63,34 +63,34 @@ export const fullSolver = (conf: (string | number | SolvedStep)[], wrapDetails:
|
||||
|
||||
// Call the solver on the items between openParen and closeParen (excluding the parens)
|
||||
const parenSolve = fullSolver(conf.slice(openParen + 1, closeParen), true);
|
||||
// Replace the itemes between openParen and closeParen (including the parens) with its solved equilvalent
|
||||
// Replace the items between openParen and closeParen (including the parens) with its solved equivalent
|
||||
conf.splice(openParen, closeParen - openParen + 1, parenSolve);
|
||||
|
||||
// Determing if we need to add in a multiplication sign to handle implicit multiplication (like "(4)2" = 8)
|
||||
// Determining if we need to add in a multiplication sign to handle implicit multiplication (like "(4)2" = 8)
|
||||
// insertedMult flags if there was a multiplication sign inserted before the parens
|
||||
let insertedMult = false;
|
||||
// Check if a number was directly before openParen and slip in the "*" if needed
|
||||
if (((openParen - 1) > -1) && (signs.indexOf(conf[openParen - 1].toString()) === -1)) {
|
||||
if (openParen - 1 > -1 && signs.indexOf(conf[openParen - 1].toString()) === -1) {
|
||||
insertedMult = true;
|
||||
conf.splice(openParen, 0, '*');
|
||||
}
|
||||
// Check if a number is directly after closeParen and slip in the "*" if needed
|
||||
if (!insertedMult && (((openParen + 1) < conf.length) && (signs.indexOf(conf[openParen + 1].toString()) === -1))) {
|
||||
if (!insertedMult && openParen + 1 < conf.length && signs.indexOf(conf[openParen + 1].toString()) === -1) {
|
||||
conf.splice(openParen + 1, 0, '*');
|
||||
} else if (insertedMult && (((openParen + 2) < conf.length) && (signs.indexOf(conf[openParen + 2].toString()) === -1))) {
|
||||
// insertedMult is utilized here to let us account for an additional item being inserted into the array (the "*" from before openParn)
|
||||
} else if (insertedMult && openParen + 2 < conf.length && signs.indexOf(conf[openParen + 2].toString()) === -1) {
|
||||
// insertedMult is utilized here to let us account for an additional item being inserted into the array (the "*" from before openParen)
|
||||
conf.splice(openParen + 2, 0, '*');
|
||||
}
|
||||
}
|
||||
|
||||
// Evaluate all EMMDAS by looping thru each teir of operators (exponential is the higehest teir, addition/subtraction the lowest)
|
||||
// Evaluate all EMDAS by looping thru each tier of operators (exponential is the highest tier, addition/subtraction the lowest)
|
||||
const allCurOps = [['^'], ['*', '/', '%'], ['+', '-']];
|
||||
allCurOps.forEach((curOps) => {
|
||||
loggingEnabled && log(LT.LOG, `Evaluating roll ${JSON.stringify(conf)} | Evaluating ${JSON.stringify(curOps)}`);
|
||||
// Iterate thru all operators/operands in the conf
|
||||
for (let i = 0; i < conf.length; i++) {
|
||||
loggingEnabled && log(LT.LOG, `Evaluating roll ${JSON.stringify(conf)} | Evaluating ${JSON.stringify(curOps)} | Checking ${JSON.stringify(conf[i])}`);
|
||||
// Check if the current index is in the active teir of operators
|
||||
// Check if the current index is in the active tier of operators
|
||||
if (curOps.indexOf(conf[i].toString()) > -1) {
|
||||
// Grab the operands from before and after the operator
|
||||
const operand1 = conf[i - 1];
|
||||
@ -137,7 +137,7 @@ export const fullSolver = (conf: (string | number | SolvedStep)[], wrapDetails:
|
||||
}
|
||||
|
||||
// Verify a second time that both are numbers before doing math, throwing an error if necessary
|
||||
if ((typeof oper1 === 'number') && (typeof oper2 === 'number')) {
|
||||
if (typeof oper1 === 'number' && typeof oper2 === 'number') {
|
||||
// Finally do the operator on the operands, throw an error if the operator is not found
|
||||
switch (conf[i]) {
|
||||
case '^':
|
||||
@ -177,16 +177,16 @@ export const fullSolver = (conf: (string | number | SolvedStep)[], wrapDetails:
|
||||
if (conf.length > 1) {
|
||||
loggingEnabled && log(LT.LOG, `ConfWHAT? ${JSON.stringify(conf)}`);
|
||||
throw new Error('ConfWhat');
|
||||
} else if (singleNum && (typeof (conf[0]) === 'number')) {
|
||||
} else if (singleNum && typeof conf[0] === 'number') {
|
||||
// If we are only left with a number, populate the stepSolve with it
|
||||
stepSolve.total = conf[0];
|
||||
stepSolve.details = conf[0].toString();
|
||||
} else {
|
||||
// Else fully populate the stepSolve with what was computed
|
||||
stepSolve.total = (<SolvedStep> conf[0]).total;
|
||||
stepSolve.details = (<SolvedStep> conf[0]).details;
|
||||
stepSolve.containsCrit = (<SolvedStep> conf[0]).containsCrit;
|
||||
stepSolve.containsFail = (<SolvedStep> conf[0]).containsFail;
|
||||
stepSolve.total = (<SolvedStep>conf[0]).total;
|
||||
stepSolve.details = (<SolvedStep>conf[0]).details;
|
||||
stepSolve.containsCrit = (<SolvedStep>conf[0]).containsCrit;
|
||||
stepSolve.containsFail = (<SolvedStep>conf[0]).containsFail;
|
||||
}
|
||||
|
||||
// If this was a nested call, add on parens around the details to show what math we've done
|
||||
|
||||
Reference in New Issue
Block a user