Caching hand feasibility, disabling interactions if there are no hands

This commit is contained in:
ZioPao
2024-03-21 19:37:30 +01:00
parent 0e911ec860
commit 1c990f3b9b
9 changed files with 133 additions and 31 deletions

View File

@@ -154,7 +154,8 @@ function AmputationHandler:execute(damagePlayer)
CachedDataHandler.AddAmputatedLimb(username, dependedLimbName)
end
CachedDataHandler.CalculateHighestAmputatedLimbs(username)
-- Cache highest amputation and hand feasibility
CachedDataHandler.CalculateCacheableValues(username)
-- If the part was actually infected, heal the player, if they were in time (infectionLevel < 20)
if bd:getInfectionLevel() < 20 and bodyPart:IsInfected() and not dcInst:getIsIgnoredPartInfected() then

View File

@@ -11,9 +11,23 @@ local CachedDataHandler = {}
---@param username string
function CachedDataHandler.Setup(username)
CachedDataHandler.amputatedLimbs[username] = {}
-- username -> side
CachedDataHandler.highestAmputatedLimbs[username] = {}
-- Local only, doesn't matter for Health Panel
CachedDataHandler.handFeasibility = {}
end
---Will calculate all the values that we need
function CachedDataHandler.CalculateCacheableValues(username)
CachedDataHandler.CalculateHighestAmputatedLimbs(username)
CachedDataHandler.CalculateBothHandsFeasibility()
end
--* Amputated Limbs caching *--
CachedDataHandler.amputatedLimbs = {}
@@ -67,16 +81,6 @@ function CachedDataHandler.CalculateHighestAmputatedLimbs(username)
return
end
-- if CachedDataHandler.amputatedLimbs == nil or CachedDataHandler.amputatedLimbs[username] == nil then
-- --- This function gets ran pretty early, we need to account for the Bob stuff
-- -- if username == "Bob" then
-- -- TOC_DEBUG.print("skip, Bob is default char")
-- -- return
-- -- end
-- TOC_DEBUG.print("Amputated limbs weren't calculated. Trying to calculate them now for " .. username)
-- CachedDataHandler.CalculateAmputatedLimbs(username)
-- end
CachedDataHandler.CalculateAmputatedLimbs(username)
local amputatedLimbs = CachedDataHandler.amputatedLimbs[username]
@@ -103,4 +107,38 @@ end
--* Hand feasibility caching *--
CachedDataHandler.handFeasibility = {}
---@param limbName string
function CachedDataHandler.CalculateHandFeasibility(limbName)
local dcInst = DataController.GetInstance()
local side = CommonMethods.GetSide(limbName)
CachedDataHandler.handFeasibility[side] = not dcInst:getIsCut(limbName) or dcInst:getIsProstEquipped(limbName)
end
function CachedDataHandler.GetHandFeasibility(side)
return CachedDataHandler.handFeasibility[side]
end
function CachedDataHandler.CalculateBothHandsFeasibility()
CachedDataHandler.CalculateHandFeasibility("Hand_L")
CachedDataHandler.CalculateHandFeasibility("Hand_R")
if not CachedDataHandler.GetBothHandsFeasibility() then
TOC_DEBUG.print("Disabling interact key")
getCore():addKeyBinding("Interact", Keyboard.KEY_NONE)
else
-- FIX DEFAULT ONE!!!!!!!
TOC_DEBUG.print("Re-enabling interact key")
getCore():addKeyBinding("Interact", Keyboard.KEY_E)
end
end
function CachedDataHandler.GetBothHandsFeasibility()
return CachedDataHandler.handFeasibility["L"] or CachedDataHandler.handFeasibility["R"]
end
return CachedDataHandler

View File

@@ -68,6 +68,9 @@ function ProsthesisHandler.SearchAndSetupProsthesis(item, isEquipping)
local dcInst = DataController.GetInstance()
dcInst:setIsProstEquipped(group, isEquipping)
dcInst:apply()
-- Calculates hands feasibility once again
CachedDataHandler.CalculateBothHandsFeasibility()
end
-------------------------