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

Commit

Permalink
Handle common error cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Pluviolithic committed Dec 16, 2023
1 parent bcd3047 commit b1ccaa2
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 33 deletions.
22 changes: 21 additions & 1 deletion src/client/UI/Displays.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local Players = game:GetService "Players"
local RunService = game:GetService "RunService"
local StarterGui = game:GetService "StarterGui"
local StarterPlayer = game:GetService "StarterPlayer"
local ReplicatedStorage = game:GetService "ReplicatedStorage"
Expand Down Expand Up @@ -92,11 +93,30 @@ end):andThen(function(interfaces)
}

playerStatePromise:andThen(function()
StarterGui:SetCore("ResetButtonCallback", false)
updateDisplays(displays)
store.changed:connect(function()
updateDisplays(displays)
end)

-- implementation taken from https://devforum.roblox.com/t/resetbuttoncallback-has-not-been-registered-by-the-corescripts/78470/6
local coreCall
do
local MAX_RETRIES = 8

function coreCall(method, ...)
local result = {}
for _ = 1, MAX_RETRIES do
result = { pcall(StarterGui[method], StarterGui, ...) }
if result[1] then
break
end
RunService.Stepped:Wait()
end
return unpack(result)
end
end

coreCall("SetCore", "ResetButtonCallback", false)
end)
end)

Expand Down
11 changes: 7 additions & 4 deletions src/server/Combat/Enemies/ApplyDamageToPlayers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local ServerScriptService = game:GetService "ServerScriptService"
local bossAttackSpeed = ReplicatedStorage.Config.Combat.BossAttackSpeed.Value
local enemyAttackSpeed = ReplicatedStorage.Config.Combat.EnemyAttackSpeed.Value

local Janitor = require(ReplicatedStorage.Common.lib.Janitor)
local store = require(ServerScriptService.Server.State.Store)
local actions = require(ServerScriptService.Server.State.Actions)
local selectors = require(ReplicatedStorage.Common.State.selectors)
Expand Down Expand Up @@ -43,8 +44,10 @@ return function(enemy, info, janitor)
end
end)

janitor:Add(function()
info.DamageActive = nil
damagePlayers = false
end, true)
if Janitor.Is(janitor) then
janitor:Add(function()
info.DamageActive = nil
damagePlayers = false
end, true)
end
end
21 changes: 12 additions & 9 deletions src/server/Combat/Enemies/ApplyEnemyAnimations.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
local ReplicatedStorage = game:GetService "ReplicatedStorage"
local CollectionService = game:GetService "CollectionService"

local Janitor = require(ReplicatedStorage.Common.lib.Janitor)
local animationUtilities = require(ReplicatedStorage.Common.Utils.AnimationUtils)

local random = Random.new()
local bossAttackSpeed = ReplicatedStorage.Config.Combat.BossAttackSpeed.Value
local enemyAttackSpeed = ReplicatedStorage.Config.Combat.EnemyAttackSpeed.Value

return function(enemy, info, janitor)
if info.AnimationsActive then
if info.AnimationsActive or not enemy:FindFirstChild "Configuration" then
return
end
info.AnimationsActive = true
Expand All @@ -22,7 +23,7 @@ return function(enemy, info, janitor)
local currentIndex, animationTrack, animation = 0, nil, nil

task.spawn(function()
while runAnimations do
while runAnimations and enemy:FindFirstChild "Humanoid" do
currentIndex, animation = animationUtilities.getNextIndexAndAnimationTrack(animationInstances, currentIndex)
animationTrack = enemy.Humanoid:LoadAnimation(animation)
animationTrack.Priority = Enum.AnimationPriority.Action
Expand Down Expand Up @@ -51,11 +52,13 @@ return function(enemy, info, janitor)
end
end)

janitor:Add(function()
runAnimations = false
info.AnimationsActive = nil
if animationTrack.IsPlaying then
animationTrack:Stop()
end
end, true)
if Janitor.Is(janitor) then
janitor:Add(function()
runAnimations = false
info.AnimationsActive = nil
if animationTrack.IsPlaying then
animationTrack:Stop()
end
end, true)
end
end
35 changes: 21 additions & 14 deletions src/server/Combat/Enemies/ApplyPlayerAnimations.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local ReplicatedStorage = game:GetService "ReplicatedStorage"
local ServerScriptService = game:GetService "ServerScriptService"

local Janitor = require(ReplicatedStorage.Common.lib.Janitor)
local store = require(ServerScriptService.Server.State.Store)
local selectors = require(ReplicatedStorage.Common.State.selectors)
local animationUtilities = require(ReplicatedStorage.Common.Utils.AnimationUtils)
Expand Down Expand Up @@ -44,7 +45,11 @@ return function(player, janitor)
local sounds = player.Character[weapon]:FindFirstChild "Sounds"
while not sounds do
task.wait()
sounds = player.Character[weapon]:FindFirstChild "Sounds"
local weaponObject = player.Character:FindFirstChild(weapon)
if not weaponObject then
return
end
sounds = weaponObject:FindFirstChild "Sounds"
end
for _, sound in sounds:GetChildren() do
task.spawn(function()
Expand Down Expand Up @@ -72,17 +77,19 @@ return function(player, janitor)
end
end)

janitor:Add(function()
runAnimations = false
if loadedIdleAnimation.IsPlaying then
loadedIdleAnimation:Stop()
end
loadedIdleAnimation:Destroy()
if animationTrack.IsPlaying then
task.spawn(function()
animationTrack.Stopped:Wait()
animationTrack:Destroy()
end)
end
end, true)
if Janitor.Is(janitor) then
janitor:Add(function()
runAnimations = false
if loadedIdleAnimation.IsPlaying then
loadedIdleAnimation:Stop()
end
loadedIdleAnimation:Destroy()
if animationTrack.IsPlaying then
task.spawn(function()
animationTrack.Stopped:Wait()
animationTrack:Destroy()
end)
end
end, true)
end
end
21 changes: 16 additions & 5 deletions src/server/Combat/Enemies/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ local function handleEnemy(enemy)
"disconnect"
)
playerJanitor:Add(humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
playerJanitor:Destroy()
if Janitor.Is(playerJanitor) then
playerJanitor:Destroy()
end
end))
playerJanitor:Add(function()
local playerIndex = table.find(info.EngagedPlayers, player)
Expand All @@ -228,22 +230,31 @@ local function handleEnemy(enemy)
orientEnemy(rootPart, info.EngagedPlayers[1].Character.HumanoidRootPart.Position)
elseif #info.EngagedPlayers == 0 then
lastInCombat = os.time()
enemyAnimationJanitor:Cleanup()
if Janitor.Is(enemyAnimationJanitor) then
enemyAnimationJanitor:Cleanup()
end
end
end, true)

local runServiceJanitor = Janitor.new()
runServiceJanitor:Add(RunService.Stepped:Connect(function()
local oldPosition = player.Character.Humanoid.RootPart.Position
task.wait(0.05)
humanoid = if player.Character then player.Character:FindFirstChild "Humanoid" else nil
if not humanoid then
runServiceJanitor:Destroy()
return
end
local oldPosition = humanoid.RootPart.Position
task.wait(0.1)
humanoid = if player.Character then player.Character:FindFirstChild "Humanoid" else nil
if not Janitor.Is(playerJanitor) and Janitor.Is(runServiceJanitor) then
runServiceJanitor:Destroy()
return
elseif not Janitor.Is(runServiceJanitor) then
return
end
if
player.Character.Humanoid.RootPart.Position == oldPosition
humanoid
and humanoid.RootPart.Position == oldPosition
and player:DistanceFromCharacter(rootPart.Position) <= fightRange + 5
then
runServiceJanitor:Destroy()
Expand Down
3 changes: 3 additions & 0 deletions src/shared/State/Reducer/PetData.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ return Rodux.createReducer({}, {
if petUtils.getPet(petName):FindFirstChild "PermaLock" and not action.force then
continue
end
if not draft[action.playerName].LockedPets[petName] then
continue
end
draft[action.playerName].LockedPets[petName] -= quantity
if draft[action.playerName].LockedPets[petName] < 1 then
draft[action.playerName].LockedPets[petName] = nil
Expand Down

0 comments on commit b1ccaa2

Please sign in to comment.