From 6b1205e160e8b8827219808049a2e4774cb0b6ec Mon Sep 17 00:00:00 2001 From: ZioPao Date: Sun, 7 Jan 2024 22:44:58 +0100 Subject: [PATCH] Fixed some last stuff in the PlayerHandler and Healthpanel --- .../client/TOC/Handlers/CachedDataHandler.lua | 23 ++++----- .../lua/client/TOC/Handlers/PlayerHandler.lua | 4 +- media/lua/client/TOC/UI/HealthPanel.lua | 49 ++++++++++++------- 3 files changed, 44 insertions(+), 32 deletions(-) diff --git a/media/lua/client/TOC/Handlers/CachedDataHandler.lua b/media/lua/client/TOC/Handlers/CachedDataHandler.lua index a3ea289..4c44513 100644 --- a/media/lua/client/TOC/Handlers/CachedDataHandler.lua +++ b/media/lua/client/TOC/Handlers/CachedDataHandler.lua @@ -38,7 +38,7 @@ end ---@param username string ---@param limbName string function CachedDataHandler.AddAmputatedLimb(username, limbName) - TOC_DEBUG.print("added " .. limbName .. " to known amputated limbs for " .. username) + TOC_DEBUG.print("[CachedDataHandler] Added " .. limbName .. " to known amputated limbs for " .. username) -- Add it to the generic list CachedDataHandler.amputatedLimbs[username][limbName] = limbName @@ -64,16 +64,17 @@ 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 + -- 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 + -- 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] CachedDataHandler.highestAmputatedLimbs[username] = {} @@ -83,7 +84,7 @@ function CachedDataHandler.CalculateHighestAmputatedLimbs(username) local limbName = k local index = CommonMethods.GetSide(limbName) if modDataHandler:getIsCut(limbName) and modDataHandler:getIsVisible(limbName) then - TOC_DEBUG.print("found high amputation " .. limbName) + TOC_DEBUG.print("[CachedDataHandler] Added Highest Amputation: " .. limbName) CachedDataHandler.highestAmputatedLimbs[username][index] = limbName end end diff --git a/media/lua/client/TOC/Handlers/PlayerHandler.lua b/media/lua/client/TOC/Handlers/PlayerHandler.lua index 019f399..d76310c 100644 --- a/media/lua/client/TOC/Handlers/PlayerHandler.lua +++ b/media/lua/client/TOC/Handlers/PlayerHandler.lua @@ -44,8 +44,8 @@ function PlayerHandler.InitializePlayer(playerObj, isForced) CachedDataHandler.Reset(username) end - -- Overrides various functions on the Health Panel ONLY after we're done initializing the player - OverrideHealthPanelForTOC() + -- Set a bool to use an overriding GetDamagedParts + SetHealthPanelTOC() end diff --git a/media/lua/client/TOC/UI/HealthPanel.lua b/media/lua/client/TOC/UI/HealthPanel.lua index bc8853e..a35fc1b 100644 --- a/media/lua/client/TOC/UI/HealthPanel.lua +++ b/media/lua/client/TOC/UI/HealthPanel.lua @@ -4,8 +4,13 @@ local CachedDataHandler = require("TOC/Handlers/CachedDataHandler") local CutLimbHandler = require("TOC/UI/CutLimbInteractions") local WoundCleaningHandler = require("TOC/UI/WoundCleaningInteraction") +local isReady = false -function OverrideHealthPanelForTOC() +function SetHealthPanelTOC() + isReady = true +end + +--function OverrideHealthPanelForTOC() -- We're overriding ISHealthPanel to add custom textures to the body panel. -- By doing so we can show the player which limbs have been cut without having to use another menu @@ -98,7 +103,7 @@ function OverrideHealthPanelForTOC() else if highestAmputations[side] == nil then return end local limbName = highestAmputations[side] - --TOC_DEBUG.print("Drawing " .. tostring(limbName) .. " for " .. username) + TOC_DEBUG.print("Drawing " .. tostring(limbName) .. " for " .. username) local cicTime = ModDataHandler.GetInstance(username):getCicatrizationTime(limbName) redColor = GetColorFromCicatrizationTime(cicTime, limbName) @@ -176,7 +181,7 @@ function OverrideHealthPanelForTOC() local og_ISMedicalCheckAction_perform = ISMedicalCheckAction.perform function ISMedicalCheckAction:perform() local username = self.otherPlayer:getUsername() - TOC_DEBUG.print("Medical Action on " .. username ) + TOC_DEBUG.print("[HealthPanel] Medical Action on " .. username ) -- We need to recalculate them here before we can create the highest amputations point CachedDataHandler.CalculateAmputatedLimbs(username) @@ -233,24 +238,30 @@ function OverrideHealthPanelForTOC() function ISHealthPanel:getDamagedParts() -- TODO Overriding it is a lot easier, but ew - local result = {} - local bodyParts = self:getPatient():getBodyDamage():getBodyParts() - if isClient() and not self:getPatient():isLocalPlayer() then - bodyParts = self:getPatient():getBodyDamageRemote():getBodyParts() - end + if isReady then - local patientUsername = self:getPatient():getUsername() - local mdh = ModDataHandler.GetInstance(patientUsername) - for i=1,bodyParts:size() do - local bodyPart = bodyParts:get(i-1) - local bodyPartTypeStr = BodyPartType.ToString(bodyPart:getType()) - local limbName = StaticData.LIMBS_IND_STR[bodyPartTypeStr] - - if ISHealthPanel.cheat or bodyPart:HasInjury() or bodyPart:bandaged() or bodyPart:stitched() or bodyPart:getSplintFactor() > 0 or bodyPart:getAdditionalPain() > 10 or bodyPart:getStiffness() > 5 or (mdh:getIsCut(limbName) and mdh:getIsVisible(limbName)) then - table.insert(result, bodyPart) + local result = {} + local bodyParts = self:getPatient():getBodyDamage():getBodyParts() + if isClient() and not self:getPatient():isLocalPlayer() then + bodyParts = self:getPatient():getBodyDamageRemote():getBodyParts() end + + local patientUsername = self:getPatient():getUsername() + local mdh = ModDataHandler.GetInstance(patientUsername) + for i=1,bodyParts:size() do + local bodyPart = bodyParts:get(i-1) + local bodyPartTypeStr = BodyPartType.ToString(bodyPart:getType()) + local limbName = StaticData.LIMBS_IND_STR[bodyPartTypeStr] + + if ISHealthPanel.cheat or bodyPart:HasInjury() or bodyPart:bandaged() or bodyPart:stitched() or bodyPart:getSplintFactor() > 0 or bodyPart:getAdditionalPain() > 10 or bodyPart:getStiffness() > 5 or (mdh:getIsCut(limbName) and mdh:getIsVisible(limbName)) then + table.insert(result, bodyPart) + end + end + return result + + else + return og_ISHealthPanel_getDamagedParts(self) end - return result end -end \ No newline at end of file +--end \ No newline at end of file