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

Commit

Permalink
Merge pull request #82 from Pluviolithic/refactor/issue-64/improve-co…
Browse files Browse the repository at this point in the history
…mbat

Finish idle handling for combat
  • Loading branch information
Pluviolithic authored Nov 16, 2023
2 parents 5249355 + 12f72cf commit 7b70afc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/client/State/Middleware.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ local function updateIdleAnimationMiddleware(nextDispatch, store)
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
Expand All @@ -46,6 +47,7 @@ local function updateIdleAnimationMiddleware(nextDispatch, store)
end
end
player.Character.Animate.idle.Animation1.AnimationId = originalAnimationId
player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Landed)
end
end
nextDispatch(action)
Expand Down
5 changes: 5 additions & 0 deletions src/server/Combat/Enemies/ApplyDamageToEnemy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,10 @@ return function(player, enemy, info, janitor)
info.HealthValue.Value -= damageToDeal
task.wait(animationUtilities.getPlayerAttackSpeed(player))
end
local rootPart = if enemy.Humanoid.RootPart then enemy.Humanoid.RootPart else enemy:FindFirstChild "RootPart"
local fightRange = enemy.Configuration.FightRange.Value
if player:DistanceFromCharacter(rootPart.Position) > fightRange + 10 then
janitor:Destroy()
end
end)
end
7 changes: 5 additions & 2 deletions src/server/Combat/Enemies/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ local function handleEnemy(enemy)

playerJanitor:Add(
store.changed:connect(function(newState)
if selectors.getCurrentTarget(newState, player.Name) ~= enemy then
if
not selectors.isPlayerLoaded(newState, player.Name)
or selectors.getCurrentTarget(newState, player.Name) ~= enemy
then
playerJanitor:Destroy()
end
end),
Expand All @@ -175,7 +178,7 @@ local function handleEnemy(enemy)

repeat
task.wait(0.1)
until player:DistanceFromCharacter(rootPart.Position) <= fightRange + 5
until player:DistanceFromCharacter(rootPart.Position) <= fightRange + 1
or not Janitor.Is(playerJanitor)
or not selectors.isPlayerLoaded(store:getState(), player.Name)

Expand Down

0 comments on commit 7b70afc

Please sign in to comment.