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

Commit

Permalink
Add remaining boosts backend and stat boosts
Browse files Browse the repository at this point in the history
  • Loading branch information
Pluviolithic committed Nov 27, 2023
1 parent 7045191 commit 41e5972
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/server/PlayerManager/ProfileTemplate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ return {
AwardedGamepasses = {},
PurchasedTeleporters = {},
PurchasedBoosts = {},
InUseBoosts = {},
ActiveBoosts = {},
},

PetData = {
Expand Down
13 changes: 0 additions & 13 deletions src/server/PurchaseManager/BoostClock.lua

This file was deleted.

38 changes: 38 additions & 0 deletions src/server/PurchaseManager/DeveloperProducts/Boosts.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
local Players = game:GetService "Players"
local ReplicatedStorage = game:GetService "ReplicatedStorage"
local ServerScriptService = game:GetService "ServerScriptService"

local Remotes = require(ReplicatedStorage.Common.Remotes)
local store = require(ServerScriptService.Server.State.Store)
local actions = require(ServerScriptService.Server.State.Actions)
local selectors = require(ReplicatedStorage.Common.State.selectors)
local clockUtils = require(ReplicatedStorage.Common.Utils.ClockUtils)

Remotes.Server:Get("UseBoost"):Connect(function(player, boostName)
if selectors.getBoostCount(store:getState(), player.Name, boostName) < 1 then
return
end
store:dispatch(actions.incrementPlayerBoostCount(player.Name, boostName, -1))
store:dispatch(actions.applyBoostToPlayer(player.Name, boostName))
end)

task.spawn(function()
while true do
local currentState = store:getState()
for _, player in Players:GetPlayers() do
if not selectors.isPlayerLoaded(currentState, player.Name) then
continue
end
local activeBoosts = selectors.getActiveBoosts(currentState, player.Name)

for boostName, boostData in activeBoosts do
if not clockUtils.hasTimeLeft(boostData.StartTime, boostData.Duration) then
store:dispatch(actions.removeBoostFromPlayer(player.Name, boostName))
end
end
end
task.wait(1)
end
end)

return 0
14 changes: 14 additions & 0 deletions src/server/State/Actions/ProductActions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,18 @@ return {
}
end
),
applyBoostToPlayer = makeActionCreator("applyBoostToPlayer", function(playerName: string, boostName: string)
return {
playerName = playerName,
boostName = boostName,
shouldSave = true,
}
end),
removeBoostFromPlayer = makeActionCreator("removeBoostFromPlayer", function(playerName: string, boostName: string)
return {
playerName = playerName,
boostName = boostName,
shouldSave = true,
}
end),
}
7 changes: 7 additions & 0 deletions src/server/State/Middleware/ApplyMultipliersMiddleware.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ return function(nextDispatch, store)
multiplierCount += sourceMultiplierCount
end

local boostData =
selectors.getActiveBoosts(store:getState(), action.playerName)[action.statName .. "Boost"]
if boostData then
multiplier += 2
multiplierCount += 1
end

if multiplierCount < 1 then
action.incrementAmount *= (1 + multiplier)
else
Expand Down
6 changes: 6 additions & 0 deletions src/shared/Remotes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ local Remotes = Net.CreateDefinitions {
},
Net.Middleware.TypeChecking(t.string),
},
UseBoost = Net.Definitions.ClientToServerEvent {
Net.Middleware.RateLimit {
MaxRequestsPerMinute = 60,
},
Net.Middleware.TypeChecking(t.string),
},

LegendaryUnboxed = Net.Definitions.ServerToClientEvent(),
SendRoduxAction = Net.Definitions.ServerToClientEvent(),
Expand Down
2 changes: 1 addition & 1 deletion src/shared/State/DefaultStates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ return {
AwardedGamepasses = {},
PurchasedTeleporters = {},
PurchasedBoosts = {},
InUseBoosts = {},
ActiveBoosts = {},
},

MissionData = {
Expand Down
13 changes: 13 additions & 0 deletions src/shared/State/Reducer/PurchaseData.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,17 @@ return Rodux.createReducer({}, {
) + (action.incrementAmount or 1)
end)
end,
applyBoostToPlayer = function(state, action)
return produce(state, function(draft)
local currentBoostData = draft[action.playerName].ActiveBoosts[action.boostName:match "%D+"]
if currentBoostData then
currentBoostData.Duration += tonumber(action.boostName:match "%d*%.?%d+")
else
draft[action.playerName].ActiveBoosts[action.boostName:match "%D+"] = {
StartTime = os.time(),
Duration = tonumber(action.boostName:match "(%d*%.?%d+)"),
}
end
end)
end,
})
4 changes: 2 additions & 2 deletions src/shared/State/selectors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ return {
getPurchasedBoosts = function(state, playerName)
return state.PurchaseData[playerName].PurchasedBoosts
end,
getInUseBoosts = function(state, playerName)
return state.PurchaseData[playerName].InUseBoosts
getActiveBoosts = function(state, playerName)
return state.PurchaseData[playerName].ActiveBoosts
end,
getBoostCount = function(state, playerName, boostName)
return state.PurchaseData[playerName].PurchasedBoosts[boostName] or 0
Expand Down
15 changes: 15 additions & 0 deletions src/shared/Utils/ClockUtils.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
return {
hasTimeLeft = function(startTime, duration)
return (os.time() - startTime) < duration
end,
getFormattedRemainingTime = function(startTime, duration)
local timeLeft = duration - (os.time() - startTime)
local minutes = math.floor(timeLeft / 60)

if minutes < 1 then
return "<1m"
else
return minutes .. "m"
end
end,
}

0 comments on commit 41e5972

Please sign in to comment.