From 6f17b428bca85b479c837c8b299cd0a09c93f5f0 Mon Sep 17 00:00:00 2001 From: ZioPao Date: Mon, 13 Nov 2023 18:23:39 +0100 Subject: [PATCH] Moved event to PlayerHandler --- .../client/TOC/Handlers/AmputationHandler.lua | 46 +++++++++---------- .../lua/client/TOC/Handlers/PlayerHandler.lua | 43 ++++++----------- media/lua/client/TOC/Tests.lua | 12 ++--- 3 files changed, 40 insertions(+), 61 deletions(-) diff --git a/media/lua/client/TOC/Handlers/AmputationHandler.lua b/media/lua/client/TOC/Handlers/AmputationHandler.lua index 6e569d4..b931105 100644 --- a/media/lua/client/TOC/Handlers/AmputationHandler.lua +++ b/media/lua/client/TOC/Handlers/AmputationHandler.lua @@ -42,6 +42,7 @@ end --* Main methods *-- +---Damage the player part during the amputation process function AmputationHandler:damageDuringAmputation() local bodyDamage = self.patientPl:getBodyDamage() local bodyDamagePart = bodyDamage:getBodyPart(self.bodyPartType) @@ -52,32 +53,35 @@ function AmputationHandler:damageDuringAmputation() bodyDamagePart:setBleedingTime(ZombRand(10, 20)) end +---Set the damage to the amputated area +---@param surgeonFactor number +function AmputationHandler:damageAfterAmputation(surgeonFactor) + local patientStats = self.patientPl:getStats() + local bd = self.patientPl:getBodyDamage() + local bodyPart = bd:getBodyPart(self.bodyPartType) + local baseDamage = StaticData.LIMBS_BASE_DAMAGE[self.limbName] + + bodyPart:AddDamage(baseDamage - surgeonFactor) + bodyPart:setAdditionalPain(baseDamage - surgeonFactor) + bodyPart:setBleeding(true) + bodyPart:setBleedingTime(baseDamage - surgeonFactor) + bodyPart:setDeepWounded(true) + bodyPart:setDeepWoundTime(baseDamage - surgeonFactor) + patientStats:setEndurance(surgeonFactor) + patientStats:setStress(baseDamage - surgeonFactor) +end + ---Execute the amputation ----@param damagePlayer boolean? +---@param damagePlayer boolean function AmputationHandler:execute(damagePlayer) -- TODO Calculate surgeonStats -- TODO Cap it to a certain amount, it shouldn't be more than ...? local surgeonFactor = 1 - if damagePlayer == nil then damagePlayer = true end -- Default at true if damagePlayer then - local patientStats = self.patientPl:getStats() - local bd = self.patientPl:getBodyDamage() - local bodyPart = bd:getBodyPart(self.bodyPartType) - local baseDamage = StaticData.LIMBS_BASE_DAMAGE[self.limbName] - - -- Set the bleeding and all the damage stuff in that part - bodyPart:AddDamage(baseDamage - surgeonFactor) - bodyPart:setAdditionalPain(baseDamage - surgeonFactor) - bodyPart:setBleeding(true) - bodyPart:setBleedingTime(baseDamage - surgeonFactor) - bodyPart:setDeepWounded(true) - bodyPart:setDeepWoundTime(baseDamage - surgeonFactor) - patientStats:setEndurance(surgeonFactor) - patientStats:setStress(baseDamage - surgeonFactor) + self:damageAfterAmputation(surgeonFactor) end - -- Set the data in modData local modDataHandler = ModDataHandler.GetInstance() modDataHandler:setCutLimb(self.limbName, false, false, false, surgeonFactor) @@ -98,12 +102,4 @@ function AmputationHandler:close() AmputationHandler.instance = nil end ---* Events *-- ----Updates the cicatrization process, run when a limb has been cut -function AmputationHandler.UpdateCicatrization() - if ModDataHandler.GetInstance():getIsAnyLimbCut() == false then return end - - -- TODO Update cicatrization -end - return AmputationHandler \ No newline at end of file diff --git a/media/lua/client/TOC/Handlers/PlayerHandler.lua b/media/lua/client/TOC/Handlers/PlayerHandler.lua index 3213816..3ee50fd 100644 --- a/media/lua/client/TOC/Handlers/PlayerHandler.lua +++ b/media/lua/client/TOC/Handlers/PlayerHandler.lua @@ -4,7 +4,7 @@ local CachedDataHandler = require("TOC/Handlers/CachedDataHandler") local StaticData = require("TOC/StaticData") ----------- --- TODO THIS SHOULD BE LOCAL ONLY! WE'RE MANAGING EVENTS AND INITIALIZATION STUFF! MOVE ONLINE STUFF AWAY! +-- THIS SHOULD BE LOCAL ONLY! WE'RE MANAGING EVENTS AND INITIALIZATION STUFF! -- LIST OF STUFF THAT THIS CLASS NEEDS TO DO -- Keep track of cut limbs so that we don't have to loop through all of them all the time @@ -53,35 +53,7 @@ function PlayerHandler.ManageTraits(playerObj) end end --- ---Cycle through all the limbs and caches the ones that the player cut off --- ---@param username string --- function PlayerHandler.CacheAmputatedLimbs(username) --- PlayerHandler.amputatedLimbs[username] = {} --- local modDataHandler = ModDataHandler.GetInstance(username) --- for i=1, #StaticData.LIMBS_STRINGS do --- local limbName = StaticData.LIMBS_STRINGS[i] --- if modDataHandler:getIsCut(limbName) then --- PlayerHandler.AddLocalAmputatedLimb(username, limbName) --- end --- end --- end - - --- ---Cache the currently amputated limbs --- ---@param limbName string --- function PlayerHandler.AddLocalAmputatedLimb(username, limbName) --- TOC_DEBUG.print("added " .. limbName .. " to known amputated limbs for " .. username) --- table.insert(PlayerHandler.amputatedLimbs[username], limbName) -- TODO This should be player specific, not generic --- end - --- --* Getters *-- - --- ---Get a table with the strings of the cached amputated limbs --- ---@return table --- function PlayerHandler.GetAmputatedLimbs() --- return PlayerHandler.amputatedLimbs or {} --- end - +------------------------- --* Events *-- ---Check if the player has an infected (as in, zombie infection) body part @@ -122,6 +94,16 @@ end Events.OnPlayerGetDamage.Add(PlayerHandler.CheckInfection) +--* Events *-- +---Updates the cicatrization process, run when a limb has been cut +function PlayerHandler.UpdateCicatrization() + if ModDataHandler.GetInstance():getIsAnyLimbCut() == false then return end + + -- TODO Update cicatrization +end + + + --* Overrides *-- local og_ISBaseTimedAction_adjustMaxTime = ISBaseTimedAction.adjustMaxTime @@ -163,5 +145,6 @@ function ISBaseTimedAction:perform() end end +-- TODO Limit 2 hands weapons and stuff like that return PlayerHandler \ No newline at end of file diff --git a/media/lua/client/TOC/Tests.lua b/media/lua/client/TOC/Tests.lua index 6f9c094..b859ed8 100644 --- a/media/lua/client/TOC/Tests.lua +++ b/media/lua/client/TOC/Tests.lua @@ -46,37 +46,37 @@ TestFramework.registerTestModule("Functionality", "Amputation", function() function Tests.CutLeftHand() local handler = AmputationHandler:new("Hand_L") - handler:execute() + handler:execute(true) TestUtils.assert(ModDataHandler.GetInstance():getIsCut("Hand_L")) end function Tests.CutLeftForearm() local handler = AmputationHandler:new("ForeArm_L") - handler:execute() + handler:execute(true) TestUtils.assert(ModDataHandler.GetInstance():getIsCut("ForeArm_L") and ModDataHandler.GetInstance():getIsCut("Hand_L")) end function Tests.CutLeftUpperarm() local handler = AmputationHandler:new("UpperArm_L") - handler:execute() + handler:execute(true) TestUtils.assert(ModDataHandler.GetInstance():getIsCut("UpperArm_L") and ModDataHandler.GetInstance():getIsCut("ForeArm_L") and ModDataHandler.GetInstance():getIsCut("Hand_L")) end function Tests.CutRightHand() local handler = AmputationHandler:new("Hand_R") - handler:execute() + handler:execute(true) TestUtils.assert(ModDataHandler.GetInstance():getIsCut("Hand_R")) end function Tests.CutRightForearm() local handler = AmputationHandler:new("ForeArm_R") - handler:execute() + handler:execute(true) TestUtils.assert(ModDataHandler.GetInstance():getIsCut("ForeArm_R") and ModDataHandler.GetInstance():getIsCut("Hand_R")) end function Tests.CutRightUpperarm() local handler = AmputationHandler:new("UpperArm_R") - handler:execute() + handler:execute(true) TestUtils.assert(ModDataHandler.GetInstance():getIsCut("UpperArm_R") and ModDataHandler.GetInstance():getIsCut("ForeArm_R") and ModDataHandler.GetInstance():getIsCut("Hand_R")) end