diff --git a/src/client/Jumpscare.lua b/src/client/Jumpscare.lua index d4e805e..49f9a73 100644 --- a/src/client/Jumpscare.lua +++ b/src/client/Jumpscare.lua @@ -76,6 +76,7 @@ local jumpscareAnimations = {} for _, jumpscare in jumpscares:GetChildren() do table.insert(jumpscareAnimations, jumpscare.Enemy.Configuration.Anim) end -ContentProvider:PreloadAsync(jumpscareAnimations) + +task.spawn(ContentProvider.PreloadAsync, ContentProvider, jumpscareAnimations) return 0 diff --git a/src/client/State/Middleware.lua b/src/client/State/Middleware.lua index 5036dd5..f474edb 100644 --- a/src/client/State/Middleware.lua +++ b/src/client/State/Middleware.lua @@ -1,60 +1,9 @@ -local Players = game:GetService "Players" -local CollectionService = game:GetService "CollectionService" local ReplicatedStorage = game:GetService "ReplicatedStorage" -local player = Players.LocalPlayer local Rodux = require(ReplicatedStorage.Common.lib.Rodux) -local selectors = require(ReplicatedStorage.Common.State.selectors) local displayClientLogs = ReplicatedStorage.Config.Output.DisplayClientLogs.Value -local originalAnimationId - -local function updateIdleAnimationMiddleware(nextDispatch, store) - return function(action) - if - action.playerName ~= player.Name - or (action.type ~= "switchPlayerEnemy" and action.type ~= "setCurrentPunchingBag") - then - nextDispatch(action) - return - end - - if player.Character then - if action.enemy or action.currentPunchingBag then - if not originalAnimationId then - originalAnimationId = player.Character.Animate.idle.Animation1.AnimationId - end - local equippedWeapon = selectors.getEquippedWeapon(store:getState(), player.Name) - if - equippedWeapon - and not action.currentPunchingBag - and not CollectionService:HasTag(action.enemy, "Dummy") - then - player.Character.Animate.idle.Animation1.AnimationId = - ReplicatedStorage.CombatAnimations[equippedWeapon].Idle.AnimationId - player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Landed) - else - player.Character.Animate.idle.Animation1.AnimationId = - ReplicatedStorage.CombatAnimations.Fists.Idle.AnimationId - end - elseif originalAnimationId then - local humanoid = player.Character and player.Character:FindFirstChild "Humanoid" - if humanoid then - for _, animationTrack in player.Character.Humanoid.Animator:GetPlayingAnimationTracks() do - if animationTrack.Priority == Enum.AnimationPriority.Idle then - animationTrack:Stop() - end - end - end - player.Character.Animate.idle.Animation1.AnimationId = originalAnimationId - player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Landed) - end - end - nextDispatch(action) - end -end return { - updateIdleAnimationMiddleware, if displayClientLogs then Rodux.loggerMiddleware else nil, } diff --git a/src/client/UI/Combat/CombatAnimationPreloader.lua b/src/client/UI/Combat/CombatAnimationPreloader.lua new file mode 100644 index 0000000..81b471f --- /dev/null +++ b/src/client/UI/Combat/CombatAnimationPreloader.lua @@ -0,0 +1,13 @@ +local ContentProvider = game:GetService "ContentProvider" +local ReplicatedStorage = game:GetService "ReplicatedStorage" + +local animationsToPreload = {} +for _, animation in ReplicatedStorage.CombatAnimations:GetDescendants() do + if animation:IsA "Animation" then + table.insert(animationsToPreload, animation) + end +end + +task.spawn(ContentProvider.PreloadAsync, ContentProvider, animationsToPreload) + +return 0 diff --git a/src/server/Combat/Enemies/ApplyPlayerAnimations.lua b/src/server/Combat/Enemies/ApplyPlayerAnimations.lua index b1f20d3..79a181f 100644 --- a/src/server/Combat/Enemies/ApplyPlayerAnimations.lua +++ b/src/server/Combat/Enemies/ApplyPlayerAnimations.lua @@ -11,10 +11,14 @@ return function(player, janitor) local runAnimations = true local currentIndex, animationTrack, animation = 0, nil, nil + local idleAnimation = combatAnimations[selectors.getEquippedWeapon(store:getState(), player.Name)].Idle local animationInstances = animationUtilities.filterAndSortAnimationInstances( combatAnimations[selectors.getEquippedWeapon(store:getState(), player.Name)]:GetChildren() ) + local loadedIdleAnimation = player.Character.Humanoid:LoadAnimation(idleAnimation) + loadedIdleAnimation.Priority = Enum.AnimationPriority.Idle + task.spawn(function() while runAnimations do currentIndex, animation = animationUtilities.getNextIndexAndAnimationTrack(animationInstances, currentIndex) @@ -24,7 +28,12 @@ return function(player, janitor) animationTrack:Play() animationTrack.Stopped:Wait() animationTrack:Destroy() + + loadedIdleAnimation:Play() + task.wait(animationUtilities.getPlayerAttackSpeed(player)) + + loadedIdleAnimation:Stop() end end) @@ -33,5 +42,10 @@ return function(player, janitor) if animationTrack.IsPlaying then animationTrack:Stop() end + if loadedIdleAnimation.IsPlaying then + loadedIdleAnimation:Stop() + end + animationTrack:Destroy() + loadedIdleAnimation:Destroy() end, true) end