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

Commit

Permalink
First option; not accepted
Browse files Browse the repository at this point in the history
  • Loading branch information
Pluviolithic committed Jan 15, 2024
1 parent da48d4d commit 99e96e1
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 15 deletions.
40 changes: 39 additions & 1 deletion src/client/UI/RebirthUI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ local function shouldRefresh(newState, oldState)
~= selectors.getStat(oldState, player.Name, "Strength")
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
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
end

function RebirthUI:_initialize()
mainUI.Rebirth.Activated:Connect(function()
playSoundEffect "UIButton"
Expand Down Expand Up @@ -60,6 +77,19 @@ function RebirthUI:_initialize()
end))
end)

self._rebirthMultipliers = {}

for _, multiplierValue in ReplicatedStorage.Config.Rebirth.StrengthMultipliers:GetChildren() do
table.insert(self._rebirthMultipliers, {
RangeStart = tonumber(multiplierValue.Name),
Multiplier = multiplierValue.Value,
})
end

table.sort(self._rebirthMultipliers, function(a, b)
return a.RangeStart < b.RangeStart
end)

playerStatePromise:andThen(function()
self:Refresh()
store.changed:connect(function(newState, oldState)
Expand All @@ -85,7 +115,15 @@ function RebirthUI:Refresh()
self._ui.Background.Passes["2xTokens"].Visible = true
end
self._ui.Background.Tokens.Text = `{formatter.formatNumberWithSuffix(rebirths * tokenMultiplier)} Rebirth Tokens`
self._ui.Background.Strength.Text = `{formatter.formatNumberWithCommas(1 + 0.01 * rebirths, 2)}x Strength`
self._ui.Background.Strength.Text = `{formatter.formatNumberWithCommas(
1
+ modifiedBinarySearch(
self._rebirthMultipliers,
selectors.getStat(store:getState(), player.Name, "Rebirths") + rebirths
)
* rebirths,
2
)}x Strength`
end

task.spawn(RebirthUI._initialize, RebirthUI)
Expand Down
57 changes: 43 additions & 14 deletions src/server/State/Middleware/ApplyMultipliersMiddleware.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,44 @@ local rankUtils = require(ReplicatedStorage.Common.Utils.RankUtils)
local selectors = require(ReplicatedStorage.Common.State.selectors)
local Count = require(ReplicatedStorage.Common.lib.Sift).Dictionary.count

local rebirthMultipliers = {}
local applyMultiplierToNegativeWhitelist = {}

for _, multiplierValue in ReplicatedStorage.Config.Rebirth.StrengthMultipliers:GetChildren() do
table.insert(rebirthMultipliers, {
RangeStart = tonumber(multiplierValue.Name),
Multiplier = multiplierValue.Value,
})
end

table.sort(rebirthMultipliers, function(a, b)
return a.RangeStart < b.RangeStart
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
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
end

return function(nextDispatch, store)
return function(action)
local initialMaxFearMeter = nil
if action.playerName and selectors.isPlayerLoaded(store:getState(), action.playerName) then
initialMaxFearMeter =
rankUtils.getMaxFearMeterFromRank(selectors.getStat(store:getState(), action.playerName, "Rank"))
end
if action.statName and action.incrementAmount then
if action.incrementAmount > 0 or applyMultiplierToNegativeWhitelist[action.statName] then
local multiplierData = selectors.getMultiplierData(store:getState(), action.playerName)
Expand Down Expand Up @@ -66,26 +100,21 @@ return function(nextDispatch, store)
end

if action.statName == "Strength" then
action.incrementAmount *= (1 + 0.01 * selectors.getStat(
store:getState(),
action.playerName,
"Rebirths"
))
local rebirths = selectors.getStat(store:getState(), action.playerName, "Rebirths")
action.incrementAmount *= (1 + modifiedBinarySearch(rebirthMultipliers, rebirths) * rebirths)
end
end
end
nextDispatch(action)
if action.statName == "Strength" then
local endMaxFearMeter = nil
if action.playerName and selectors.isPlayerLoaded(store:getState(), action.playerName) then
endMaxFearMeter =
rankUtils.getMaxFearMeterFromRank(selectors.getStat(store:getState(), action.playerName, "Rank"))
end
if endMaxFearMeter and initialMaxFearMeter ~= endMaxFearMeter then
local multiplier = selectors.getMultiplierData(store:getState(), action.playerName).MaxFearMeterMultiplier
or 1
store:dispatch(
actions.setPlayerStat(
action.playerName,
"MaxFearMeter",
rankUtils.getMaxFearMeterFromRank(selectors.getStat(store:getState(), action.playerName, "Rank"))
* multiplier
)
)
store:dispatch(actions.setPlayerStat(action.playerName, "MaxFearMeter", endMaxFearMeter * multiplier))
end
end
end

0 comments on commit 99e96e1

Please sign in to comment.