Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Implement alternate rebirth strength multiplier approach
Browse files Browse the repository at this point in the history
  • Loading branch information
Pluviolithic committed Jan 15, 2024
1 parent 99e96e1 commit 0dec572
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 15 deletions.
36 changes: 26 additions & 10 deletions src/client/UI/RebirthUI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,29 @@ local function modifiedBinarySearch(array, value)
local high = #array
local mid = math.floor((low + high) / 2)
while low <= high do
if array[mid].RangeStart <= value and array[mid + 1].RangeStart > value then
return array[mid].Multiplier
if array[mid].RangeStart <= value and (not array[mid + 1] or array[mid + 1].RangeStart > value) then
return mid
elseif array[mid].RangeStart > value then
high = mid - 1
else
low = mid + 1
end
mid = math.floor((low + high) / 2)
end
return array[#array].Multiplier
return #array
end

local function getRebirthStrengthMultiplier(array, rebirths)
local multiplier = 1
local index = modifiedBinarySearch(array, rebirths)
if index == 1 then
return multiplier + rebirths * array[1].Multiplier
end
for i = 1, index - 1 do
rebirths -= (array[i + 1].RangeStart - array[i].RangeStart)
multiplier += array[i].PreComputedResult
end
return multiplier + rebirths * array[index].Multiplier
end

function RebirthUI:_initialize()
Expand Down Expand Up @@ -90,6 +103,12 @@ function RebirthUI:_initialize()
return a.RangeStart < b.RangeStart
end)

for i = 1, #self._rebirthMultipliers - 1 do
self._rebirthMultipliers[i].PreComputedResult = (
self._rebirthMultipliers[i + 1].RangeStart - self._rebirthMultipliers[i].RangeStart
) * self._rebirthMultipliers[i].Multiplier
end

playerStatePromise:andThen(function()
self:Refresh()
store.changed:connect(function(newState, oldState)
Expand All @@ -116,13 +135,10 @@ function RebirthUI:Refresh()
end
self._ui.Background.Tokens.Text = `{formatter.formatNumberWithSuffix(rebirths * tokenMultiplier)} Rebirth Tokens`
self._ui.Background.Strength.Text = `{formatter.formatNumberWithCommas(
1
+ modifiedBinarySearch(
self._rebirthMultipliers,
selectors.getStat(store:getState(), player.Name, "Rebirths") + rebirths
)
* rebirths,
2
getRebirthStrengthMultiplier(
self._rebirthMultipliers,
rebirths + selectors.getStat(store:getState(), player.Name, "Rebirths")
)
)}x Strength`
end

Expand Down
30 changes: 25 additions & 5 deletions src/server/State/Middleware/ApplyMultipliersMiddleware.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,39 @@ table.sort(rebirthMultipliers, function(a, b)
return a.RangeStart < b.RangeStart
end)

for i = 1, #rebirthMultipliers - 1 do
rebirthMultipliers[i].PreComputedResult = (rebirthMultipliers[i + 1].RangeStart - rebirthMultipliers[i].RangeStart)
* rebirthMultipliers[i].Multiplier
end

local function modifiedBinarySearch(array, value)
local low = 1
local high = #array
local mid = math.floor((low + high) / 2)
while low <= high do
if array[mid].RangeStart <= value and array[mid + 1].RangeStart > value then
return array[mid].Multiplier
if array[mid].RangeStart <= value and (not array[mid + 1] or array[mid + 1].RangeStart > value) then
return mid
elseif array[mid].RangeStart > value then
high = mid - 1
else
low = mid + 1
end
mid = math.floor((low + high) / 2)
end
return array[#array].Multiplier
return #array
end

local function getRebirthStrengthMultiplier(array, rebirths)
local multiplier = 1
local index = modifiedBinarySearch(array, rebirths)
if index == 1 then
return multiplier + rebirths * array[1].Multiplier
end
for i = 1, index - 1 do
rebirths -= (array[i + 1].RangeStart - array[i].RangeStart)
multiplier += array[i].PreComputedResult
end
return multiplier + rebirths * array[index].Multiplier
end

return function(nextDispatch, store)
Expand Down Expand Up @@ -100,8 +118,10 @@ return function(nextDispatch, store)
end

if action.statName == "Strength" then
local rebirths = selectors.getStat(store:getState(), action.playerName, "Rebirths")
action.incrementAmount *= (1 + modifiedBinarySearch(rebirthMultipliers, rebirths) * rebirths)
action.incrementAmount *= getRebirthStrengthMultiplier(
rebirthMultipliers,
selectors.getStat(store:getState(), action.playerName, "Rebirths")
)
end
end
end
Expand Down

0 comments on commit 0dec572

Please sign in to comment.