diff --git a/src/artigen/dice/dice.d.ts b/src/artigen/dice/dice.d.ts index 2d64a7f..644d835 100644 --- a/src/artigen/dice/dice.d.ts +++ b/src/artigen/dice/dice.d.ts @@ -74,6 +74,14 @@ interface RangeConf { on: boolean; 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 interface SortDisabled { @@ -92,18 +100,20 @@ export interface DPercentConf { critVal: number; } -// GroupConf carries the machine readable group configuration the user specified -export interface GroupConf { +interface BaseConf { drop: CountConf; keep: CountConf; dropHigh: 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 -export interface RollConf extends GroupConf { +export interface RollConf extends BaseConf { type: RollType; dieCount: number; dieSize: number; @@ -128,6 +138,8 @@ export interface RollConf extends GroupConf { returnTotal: boolean; }; sort: SortDisabled | SortEnabled; + success: RangeConf; + fail: RangeConf; } export interface SumOverride { diff --git a/src/artigen/dice/getGroupConf.ts b/src/artigen/dice/getGroupConf.ts index 2292334..710713b 100644 --- a/src/artigen/dice/getGroupConf.ts +++ b/src/artigen/dice/getGroupConf.ts @@ -2,6 +2,7 @@ import { log, LogTypes as LT } from '@Log4Deno'; import { GroupConf } from 'artigen/dice/dice.d.ts'; import { getRollConf } from 'artigen/dice/getRollConf.ts'; +import { GroupOptions } from 'artigen/dice/rollOptions.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}"`); const fakeRollConf = getRollConf(`1d${biggest}${groupStr}`); 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 { drop: fakeRollConf.drop, keep: fakeRollConf.keep, dropHigh: fakeRollConf.dropHigh, keepLow: fakeRollConf.keepLow, - success: fakeRollConf.success, - fail: fakeRollConf.fail, + success: { ...fakeRollConf.success, minValue: minSuccess, maxValue: maxSuccess }, + fail: { ...fakeRollConf.fail, minValue: minFail, maxValue: maxFail }, }; }; diff --git a/src/artigen/dice/groupHandler.ts b/src/artigen/dice/groupHandler.ts index 7a1439f..c76b72a 100644 --- a/src/artigen/dice/groupHandler.ts +++ b/src/artigen/dice/groupHandler.ts @@ -151,11 +151,21 @@ export const handleGroup = ( loopCountCheck(); 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++; 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++; resultFlags[idx].failed = true; }