1
1
mirror of https://github.com/Burn-E99/TheArtificer.git synced 2026-01-08 05:17:54 -05:00
This commit is contained in:
Ean Milligan
2025-04-26 22:38:11 -04:00
parent 09e97eabc1
commit 103ad8a8f5
8 changed files with 29 additions and 45 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: '',
@ -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;
@ -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--;

View File

@ -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,
],
@ -175,14 +175,14 @@ const handleRollWorker = (rq: ApiQueuedRoll | DDQueuedRoll) => {
JSON.stringify(
rq.modifiers.count
? {
counts: countEmbed,
details: pubEmbedDetails,
}
counts: countEmbed,
details: pubEmbedDetails,
}
: {
details: pubEmbedDetails,
}
)
)
details: pubEmbedDetails,
},
),
),
);
}
}
@ -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();

View File

@ -1,4 +1,4 @@
import { initLog, closeLog } from '../../deps.ts';
import { closeLog, initLog } from '../../deps.ts';
import { DEBUG } from '../../flags.ts';
import { parseRoll } from './parser.ts';
import { loggingEnabled } from './rollUtils.ts';

View File

@ -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[]> [],
},
};