Fix success/fail gt/lt on groups to actually work correctly
This commit is contained in:
parent
6e88e96cda
commit
7a4a33f661
|
@ -74,6 +74,14 @@ interface RangeConf {
|
||||||
on: boolean;
|
on: boolean;
|
||||||
range: number[];
|
range: number[];
|
||||||
}
|
}
|
||||||
|
interface GroupRangeConf extends RangeConf {
|
||||||
|
// minValue carries the minimum number for the specified option to trigger
|
||||||
|
// ex: if set to 4, 4 and greater will trigger the option
|
||||||
|
minValue: number | null;
|
||||||
|
// maxValue carries the minimum number for the specified option to trigger
|
||||||
|
// ex: if set to 4, 4 and less will trigger the option
|
||||||
|
maxValue: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
// Sort interface
|
// Sort interface
|
||||||
interface SortDisabled {
|
interface SortDisabled {
|
||||||
|
@ -92,18 +100,20 @@ export interface DPercentConf {
|
||||||
critVal: number;
|
critVal: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// GroupConf carries the machine readable group configuration the user specified
|
interface BaseConf {
|
||||||
export interface GroupConf {
|
|
||||||
drop: CountConf;
|
drop: CountConf;
|
||||||
keep: CountConf;
|
keep: CountConf;
|
||||||
dropHigh: CountConf;
|
dropHigh: CountConf;
|
||||||
keepLow: CountConf;
|
keepLow: CountConf;
|
||||||
success: RangeConf;
|
}
|
||||||
fail: RangeConf;
|
// GroupConf carries the machine readable group configuration the user specified
|
||||||
|
export interface GroupConf extends BaseConf {
|
||||||
|
success: GroupRangeConf;
|
||||||
|
fail: GroupRangeConf;
|
||||||
}
|
}
|
||||||
|
|
||||||
// RollConf carries the machine readable roll configuration the user specified
|
// RollConf carries the machine readable roll configuration the user specified
|
||||||
export interface RollConf extends GroupConf {
|
export interface RollConf extends BaseConf {
|
||||||
type: RollType;
|
type: RollType;
|
||||||
dieCount: number;
|
dieCount: number;
|
||||||
dieSize: number;
|
dieSize: number;
|
||||||
|
@ -128,6 +138,8 @@ export interface RollConf extends GroupConf {
|
||||||
returnTotal: boolean;
|
returnTotal: boolean;
|
||||||
};
|
};
|
||||||
sort: SortDisabled | SortEnabled;
|
sort: SortDisabled | SortEnabled;
|
||||||
|
success: RangeConf;
|
||||||
|
fail: RangeConf;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SumOverride {
|
export interface SumOverride {
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { log, LogTypes as LT } from '@Log4Deno';
|
||||||
|
|
||||||
import { GroupConf } from 'artigen/dice/dice.d.ts';
|
import { GroupConf } from 'artigen/dice/dice.d.ts';
|
||||||
import { getRollConf } from 'artigen/dice/getRollConf.ts';
|
import { getRollConf } from 'artigen/dice/getRollConf.ts';
|
||||||
|
import { GroupOptions } from 'artigen/dice/rollOptions.ts';
|
||||||
|
|
||||||
import { loopCountCheck } from 'artigen/managers/loopManager.ts';
|
import { loopCountCheck } from 'artigen/managers/loopManager.ts';
|
||||||
|
|
||||||
|
@ -25,12 +26,48 @@ export const getGroupConf = (groupStr: string, rawStr: string): GroupConf => {
|
||||||
loggingEnabled && log(LT.LOG, `Abusing getRollConf with "1d${biggest} ${groupStr}"`);
|
loggingEnabled && log(LT.LOG, `Abusing getRollConf with "1d${biggest} ${groupStr}"`);
|
||||||
const fakeRollConf = getRollConf(`1d${biggest}${groupStr}`);
|
const fakeRollConf = getRollConf(`1d${biggest}${groupStr}`);
|
||||||
loggingEnabled && log(LT.LOG, `Abused rollConf back for ${groupStr}: ${JSON.stringify(fakeRollConf)}`);
|
loggingEnabled && log(LT.LOG, `Abused rollConf back for ${groupStr}: ${JSON.stringify(fakeRollConf)}`);
|
||||||
|
|
||||||
|
// Apply > to minValue and < to maxValue for success and fail
|
||||||
|
const groupSplit = groupStr.split(/(\d+)/g).filter((x) => x);
|
||||||
|
loggingEnabled && log(LT.LOG, `Handling success/fail gt/lt ${JSON.stringify(groupSplit)}`);
|
||||||
|
|
||||||
|
let minSuccess: number | null = null;
|
||||||
|
let maxSuccess: number | null = null;
|
||||||
|
let minFail: number | null = null;
|
||||||
|
let maxFail: number | null = null;
|
||||||
|
|
||||||
|
while (groupSplit.length) {
|
||||||
|
loopCountCheck();
|
||||||
|
|
||||||
|
const option = groupSplit.shift() ?? '';
|
||||||
|
const value = parseInt(groupSplit.shift() ?? '');
|
||||||
|
|
||||||
|
if (!isNaN(value)) {
|
||||||
|
switch (option) {
|
||||||
|
case GroupOptions.SuccessLt:
|
||||||
|
maxSuccess = maxSuccess && value < maxSuccess ? maxSuccess : value;
|
||||||
|
break;
|
||||||
|
case GroupOptions.SuccessGtr:
|
||||||
|
minSuccess = minSuccess && value > minSuccess ? minSuccess : value;
|
||||||
|
break;
|
||||||
|
case GroupOptions.FailLt:
|
||||||
|
maxFail = maxFail && value < maxFail ? maxFail : value;
|
||||||
|
break;
|
||||||
|
case GroupOptions.FailGtr:
|
||||||
|
minFail = minFail && value > minFail ? minFail : value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
loggingEnabled && log(LT.LOG, `Parsed GT/LT: minSuccess: ${minSuccess} maxSuccess: ${maxSuccess} minFail: ${minFail} maxFail: ${maxFail}`);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
drop: fakeRollConf.drop,
|
drop: fakeRollConf.drop,
|
||||||
keep: fakeRollConf.keep,
|
keep: fakeRollConf.keep,
|
||||||
dropHigh: fakeRollConf.dropHigh,
|
dropHigh: fakeRollConf.dropHigh,
|
||||||
keepLow: fakeRollConf.keepLow,
|
keepLow: fakeRollConf.keepLow,
|
||||||
success: fakeRollConf.success,
|
success: { ...fakeRollConf.success, minValue: minSuccess, maxValue: maxSuccess },
|
||||||
fail: fakeRollConf.fail,
|
fail: { ...fakeRollConf.fail, minValue: minFail, maxValue: maxFail },
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -151,11 +151,21 @@ export const handleGroup = (
|
||||||
loopCountCheck();
|
loopCountCheck();
|
||||||
|
|
||||||
if (!resultFlags[idx].dropped) {
|
if (!resultFlags[idx].dropped) {
|
||||||
if (groupConf.success.on && groupConf.success.range.includes(rd.rollTotal)) {
|
if (
|
||||||
|
groupConf.success.on &&
|
||||||
|
(groupConf.success.range.includes(rd.rollTotal) ||
|
||||||
|
(groupConf.success.minValue !== null && rd.rollTotal >= groupConf.success.minValue) ||
|
||||||
|
(groupConf.success.maxValue !== null && rd.rollTotal <= groupConf.success.maxValue))
|
||||||
|
) {
|
||||||
successCnt++;
|
successCnt++;
|
||||||
resultFlags[idx].success = true;
|
resultFlags[idx].success = true;
|
||||||
}
|
}
|
||||||
if (groupConf.fail.on && groupConf.fail.range.includes(rd.rollTotal)) {
|
if (
|
||||||
|
groupConf.fail.on &&
|
||||||
|
(groupConf.fail.range.includes(rd.rollTotal) ||
|
||||||
|
(groupConf.fail.minValue !== null && rd.rollTotal >= groupConf.fail.minValue) ||
|
||||||
|
(groupConf.fail.maxValue !== null && rd.rollTotal <= groupConf.fail.maxValue))
|
||||||
|
) {
|
||||||
failCnt++;
|
failCnt++;
|
||||||
resultFlags[idx].failed = true;
|
resultFlags[idx].failed = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue