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

Commit

Permalink
Add group and vip chests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pluviolithic committed Nov 28, 2023
1 parent 344bac2 commit 4e552cb
Show file tree
Hide file tree
Showing 13 changed files with 220 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/client/UI/ChestTimerUI.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
local Players = game:GetService "Players"
local StarterPlayer = game:GetService "StarterPlayer"
local ReplicatedStorage = game:GetService "ReplicatedStorage"
local CollectionService = game:GetService "CollectionService"

local selectors = require(ReplicatedStorage.Common.State.selectors)
local clockUtils = require(ReplicatedStorage.Common.Utils.ClockUtils)
local store = require(StarterPlayer.StarterPlayerScripts.Client.State.Store)
local playerStatePromise = require(StarterPlayer.StarterPlayerScripts.Client.State.PlayerStatePromise)

local player = Players.LocalPlayer

playerStatePromise:andThen(function()
while true do
local chestTimers = selectors.getChestTimers(store:getState(), player.Name)
for _, VIPChestTimer in CollectionService:GetTagged "VIPChestTimer" do
VIPChestTimer.Text = clockUtils.getFormattedChestTimer(chestTimers.VIPChest)
end
for _, groupChestTimer in CollectionService:GetTagged "GroupChestTimer" do
groupChestTimer.Text = clockUtils.getFormattedChestTimer(chestTimers.GroupChest)
end
task.wait(1)
end
end)

return 0
4 changes: 4 additions & 0 deletions src/client/UI/Shops/RobuxShop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ function RobuxShop:_initialize(): ()
self:setEnabled(not self._isOpen)
end)

Remotes.Client:Get("OpenRobuxShopOnClient"):Connect(function(subShopName)
self:OpenSubShop(subShopName)
end)

self._ui.Boosts.Activated:Connect(function()
self._ui.Background.BoostsFrame.Visible = true
self:_closeFramesWithExclude(self._ui.Background.BoostsFrame)
Expand Down
1 change: 1 addition & 0 deletions src/client/UI/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require(script.BuffsUI)
require(script.SettingsUI)
require(script.FixRichText)
require(script.Inventories)
require(script.ChestTimerUI)
require(script.BillboardShops)

return 0
8 changes: 8 additions & 0 deletions src/server/PlayerManager/ProfileTemplate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ return {
LogInCount = 0,
HoursPlayed = 0,

VIPChestAwardIndex = 1,
GroupChestAwardIndex = 1,

MaxPetCount = 30,
CurrentPetCount = 0,
MaxPetEquipCount = 3,
Expand Down Expand Up @@ -83,4 +86,9 @@ return {
VIPNameTag = false,
JumpscareCooldown = true,
},

ChestTimers = {
VIPChest = -1,
GroupChest = -1,
},
}
104 changes: 104 additions & 0 deletions src/server/PurchaseManager/Chests.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
local ReplicatedStorage = game:GetService "ReplicatedStorage"
local ServerScriptService = game:GetService "ServerScriptService"

local Remotes = require(ReplicatedStorage.Common.Remotes)
local Zone = require(ReplicatedStorage.Common.lib.ZonePlus)
local store = require(ServerScriptService.Server.State.Store)
local actions = require(ServerScriptService.Server.State.Actions)
local selectors = require(ReplicatedStorage.Common.State.selectors)
local zoneUtils = require(ReplicatedStorage.Common.Utils.ZoneUtils)
local clockUtils = require(ReplicatedStorage.Common.Utils.ClockUtils)
local productRewarders = require(ServerScriptService.Server.PurchaseManager.DeveloperProducts.Products.Rewarders)

local packIDs = ReplicatedStorage.Config.DevProductData.Packs
local chestTimerLength = ReplicatedStorage.Config.DevProductData.Chests.ChestTimerLength.Value
local VIPChestZone = Zone.new(zoneUtils.getTaggedForZone "VIPChestHitbox")
local groupChestZone = Zone.new(zoneUtils.getTaggedForZone "GroupChestHitbox")

VIPChestZone:relocate()
groupChestZone:relocate()

-- Award order for group chests: GemBoost > TinyFearPack > DamageBoost > FearBoost > SmallGemPack > FearlessBoost
-- Award order for vip chests: FearBoost > SmallGemPack > DamageBoost > GemBoost > TinyFearPack > FearlessBoost

local vipChestAwards = {
function(player)
Remotes.Server:Get("OpenRobuxShopOnClient"):SendToPlayer(player, "Boosts")
store:dispatch(actions.incrementPlayerBoostCount(player.Name, "FearBoost15"))
end,
function(player)
productRewarders[packIDs.Gems["SmallGemPack"].Value](player)
end,
function(player)
Remotes.Server:Get("OpenRobuxShopOnClient"):SendToPlayer(player, "Boosts")
store:dispatch(actions.incrementPlayerBoostCount(player.Name, "DamageBoost15"))
end,
function(player)
Remotes.Server:Get("OpenRobuxShopOnClient"):SendToPlayer(player, "Boosts")
store:dispatch(actions.incrementPlayerBoostCount(player.Name, "GemsBoost15"))
end,
function(player)
productRewarders[packIDs.Fear["TinyFearPack"].Value](player)
end,
function(player)
Remotes.Server:Get("OpenRobuxShopOnClient"):SendToPlayer(player, "Boosts")
store:dispatch(actions.incrementPlayerBoostCount(player.Name, "FearlessBoost15"))
end,
}

local groupChestAwards = {
function(player)
Remotes.Server:Get("OpenRobuxShopOnClient"):SendToPlayer(player, "Boosts")
store:dispatch(actions.incrementPlayerBoostCount(player.Name, "GemsBoost15"))
end,
function(player)
productRewarders[packIDs.Fear["TinyFearPack"].Value](player)
end,
function(player)
Remotes.Server:Get("OpenRobuxShopOnClient"):SendToPlayer(player, "Boosts")
store:dispatch(actions.incrementPlayerBoostCount(player.Name, "DamageBoost15"))
end,
function(player)
Remotes.Server:Get("OpenRobuxShopOnClient"):SendToPlayer(player, "Boosts")
store:dispatch(actions.incrementPlayerBoostCount(player.Name, "FearBoost15"))
end,
function(player)
productRewarders[packIDs.Gems["SmallGemPack"].Value](player)
end,
function(player)
Remotes.Server:Get("OpenRobuxShopOnClient"):SendToPlayer(player, "Boosts")
store:dispatch(actions.incrementPlayerBoostCount(player.Name, "FearlessBoost15"))
end,
}

VIPChestZone.playerEntered:Connect(function(player)
if not selectors.hasGamepass(store:getState(), player.Name, "VIP") then
return
end
local chestTimers = selectors.getChestTimers(store:getState(), player.Name)
if not clockUtils.hasTimeLeft(chestTimers.VIPChest, chestTimerLength) then
local currentAwardIndex = selectors.getStat(store:getState(), player.Name, "VIPChestAwardIndex")
store:dispatch(actions.startChestTimer(player.Name, "VIPChest"))
vipChestAwards[currentAwardIndex](player)
store:dispatch(
actions.setPlayerStat(player.Name, "VIPChestAwardIndex", (currentAwardIndex % #vipChestAwards) + 1)
)
end
end)

groupChestZone.playerEntered:Connect(function(player)
if not player:IsInGroup(2855772) then
return
end
local chestTimers = selectors.getChestTimers(store:getState(), player.Name)
if not clockUtils.hasTimeLeft(chestTimers.GroupChest, chestTimerLength) then
store:dispatch(actions.startChestTimer(player.Name, "GroupChest"))
local currentAwardIndex = selectors.getStat(store:getState(), player.Name, "GroupChestAwardIndex")
groupChestAwards[currentAwardIndex](player)
store:dispatch(
actions.setPlayerStat(player.Name, "GroupChestAwardIndex", (currentAwardIndex % #groupChestAwards) + 1)
)
end
end)

return 0
1 change: 1 addition & 0 deletions src/server/PurchaseManager/Codes.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
return 0
13 changes: 13 additions & 0 deletions src/server/State/Actions/ChestTimerActions.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
local ReplicatedStorage = game:GetService "ReplicatedStorage"
local Rodux = require(ReplicatedStorage.Common.lib.Rodux)
local makeActionCreator = Rodux.makeActionCreator

return {
startChestTimer = makeActionCreator("startChestTimer", function(playerName: string, chestName: string)
return {
playerName = playerName,
chestName = chestName,
shouldSave = true,
}
end),
}
2 changes: 1 addition & 1 deletion src/server/State/Middleware/SavePlayerDataMiddleware.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ local function getFilteredState(playerName, state)
PurchaseData = selectors.getPurchaseData(state, playerName),
MissionData = selectors.getMissionData(state, playerName),
SavedSettings = selectors.getSavedSettings(state, playerName),
--MultiplierData = selectors.getMultiplierData(state, playerName),
ChestTimers = selectors.getChestTimers(state, playerName),
}
for field, entry in filteredState do
for key in entry do
Expand Down
7 changes: 7 additions & 0 deletions src/shared/Remotes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,14 @@ local Remotes = Net.CreateDefinitions {
},
Net.Middleware.TypeChecking(t.string),
},
RedeemCode = Net.Definitions.ServerFunction {
Net.Middleware.RateLimit {
MaxRequestsPerMinute = 60,
},
Net.Middleware.TypeChecking(t.string),
},

OpenRobuxShopOnClient = Net.Definitions.ServerToClientEvent(),
LegendaryUnboxed = Net.Definitions.ServerToClientEvent(),
SendRoduxAction = Net.Definitions.ServerToClientEvent(),
SetControlsEnabled = Net.Definitions.ServerToClientEvent(),
Expand Down
5 changes: 5 additions & 0 deletions src/shared/State/DefaultStates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,9 @@ return {
ShowOtherPets = true,
Jumpscares = true,
},

ChestTimers = {
VIPChest = -1,
GroupChest = -1,
},
}
31 changes: 31 additions & 0 deletions src/shared/State/Reducer/ChestTimers.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
local ReplicatedStorage = game:GetService "ReplicatedStorage"

local Immut = require(ReplicatedStorage.Common.lib.Immut)
local Rodux = require(ReplicatedStorage.Common.lib.Rodux)
local Dict = require(ReplicatedStorage.Common.lib.Sift).Dictionary
local defaultStates = require(ReplicatedStorage.Common.State.DefaultStates)

local produce = Immut.produce

return Rodux.createReducer({}, {
addPlayer = function(state, action)
return produce(state, function(draft)
draft[action.playerName] = Dict.mergeDeep(defaultStates.ChestTimers, action.profileData.ChestTimers)
end)
end,
removePlayer = function(state, action)
return produce(state, function(draft)
draft[action.playerName] = nil
end)
end,
resetPlayerData = function(state, action)
return produce(state, function(draft)
draft[action.playerName] = table.clone(defaultStates.ChestTimers)
end)
end,
startChestTimer = function(state, action)
return produce(state, function(draft)
draft[action.playerName][action.chestName] = os.time()
end)
end,
})
3 changes: 3 additions & 0 deletions src/shared/State/selectors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,7 @@ return {
getBoostCount = function(state, playerName, boostName)
return state.PurchaseData[playerName].PurchasedBoosts[boostName] or 0
end,
getChestTimers = function(state, playerName)
return state.ChestTimers[playerName]
end,
}
16 changes: 16 additions & 0 deletions src/shared/Utils/ClockUtils.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
local ReplicatedStorage = game:GetService "ReplicatedStorage"

local chestTimerLength = ReplicatedStorage.Config.DevProductData.Chests.ChestTimerLength.Value

return {
hasTimeLeft = function(startTime, duration)
return (os.time() - startTime) <= duration
Expand All @@ -12,4 +16,16 @@ return {
return minutes .. "m"
end
end,
getFormattedChestTimer = function(startTime)
local timeLeft = chestTimerLength - (os.time() - startTime)
local hours = math.floor(timeLeft / 3600)
local minutes = math.floor((timeLeft - (hours * 3600)) / 60)
local seconds = timeLeft - (hours * 3600) - (minutes * 60)

if timeLeft < 1 then
return "READY!"
end

return string.format("%02d:%02d:%02d", hours, minutes, seconds)
end,
}

0 comments on commit 4e552cb

Please sign in to comment.