From 21eb5409b4ba171eeb554ba92dbd33f6bffcbb99 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Sun, 14 Aug 2022 01:53:02 -0500 Subject: [PATCH] Added option to exponential modifiers to support low numbers --- src/game/modifiers.tsx | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/game/modifiers.tsx b/src/game/modifiers.tsx index 72108ef..e6e5f66 100644 --- a/src/game/modifiers.tsx +++ b/src/game/modifiers.tsx @@ -148,6 +148,8 @@ export interface ExponentialModifierOptions { description?: Computable | undefined; /** A computable that will be processed and passed directly into the returned modifier. */ enabled?: Computable | undefined; + /** Add 1 before calculating, then remove it afterwards. This prevents low numbers from becoming lower. */ + supportLowNumbers?: boolean; } /** @@ -158,14 +160,34 @@ export function createExponentialModifier( optionsFunc: () => T ): ModifierFromOptionalParams { return createLazyProxy(() => { - const { exponent, description, enabled } = optionsFunc(); + const { exponent, description, enabled, supportLowNumbers } = optionsFunc(); const processedExponent = convertComputable(exponent); const processedDescription = convertComputable(description); const processedEnabled = enabled == null ? undefined : convertComputable(enabled); return { - apply: (gain: DecimalSource) => Decimal.pow(gain, unref(processedExponent)), - revert: (gain: DecimalSource) => Decimal.root(gain, unref(processedExponent)), + apply: (gain: DecimalSource) => { + let result = gain; + if (supportLowNumbers) { + result = Decimal.add(result, 1); + } + result = Decimal.pow(result, unref(processedExponent)); + if (supportLowNumbers) { + result = Decimal.sub(result, 1); + } + return result; + }, + revert: (gain: DecimalSource) => { + let result = gain; + if (supportLowNumbers) { + result = Decimal.add(result, 1); + } + result = Decimal.root(result, unref(processedExponent)); + if (supportLowNumbers) { + result = Decimal.sub(result, 1); + } + return result; + }, enabled: processedEnabled, description: description == null @@ -179,6 +201,7 @@ export function createExponentialModifier( {/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */} {renderJSX(unref(processedDescription)!)} + {supportLowNumbers ? " (+1 effective)" : null} ) : null}