From 9a4d07900cad00ca97282d8fdde622f9689300d5 Mon Sep 17 00:00:00 2001 From: ZioPao Date: Thu, 16 Nov 2023 01:42:56 +0100 Subject: [PATCH] Fixing healing mechanisms --- media/lua/client/TOC/CommonMethods.lua | 2 - .../client/TOC/Handlers/AmputationHandler.lua | 12 +++- .../lua/client/TOC/Handlers/PlayerHandler.lua | 66 ++++++++++++++++--- .../lua/client/TOC/UI/CutLimbInteractions.lua | 1 + 4 files changed, 70 insertions(+), 11 deletions(-) diff --git a/media/lua/client/TOC/CommonMethods.lua b/media/lua/client/TOC/CommonMethods.lua index f9298a7..860e410 100644 --- a/media/lua/client/TOC/CommonMethods.lua +++ b/media/lua/client/TOC/CommonMethods.lua @@ -7,6 +7,4 @@ function CommonMethods.GetSide(name) if string.find(name, "_L") then return "L" else return "R" end end - - return CommonMethods \ No newline at end of file diff --git a/media/lua/client/TOC/Handlers/AmputationHandler.lua b/media/lua/client/TOC/Handlers/AmputationHandler.lua index 9846b7d..84021d2 100644 --- a/media/lua/client/TOC/Handlers/AmputationHandler.lua +++ b/media/lua/client/TOC/Handlers/AmputationHandler.lua @@ -1,6 +1,7 @@ local ModDataHandler = require("TOC/Handlers/ModDataHandler") local ItemsHandler = require("TOC/Handlers/ItemsHandler") local CachedDataHandler = require("TOC/Handlers/CachedDataHandler") +local PlayerHandler = require("TOC/Handlers/PlayerHandler") local StaticData = require("TOC/StaticData") --------------------------- @@ -135,6 +136,11 @@ function AmputationHandler:execute(damagePlayer) modDataHandler:setCutLimb(self.limbName, false, false, false, surgeonFactor) modDataHandler:apply() -- This will force rechecking the cached amputated limbs on the other client + -- Heal the area, we're gonna re-set the damage after (if it's enabled) + local bd = self.patientPl:getBodyDamage() + local bodyPart = bd:getBodyPart(self.bodyPartType) + PlayerHandler.HealArea(bodyPart) + -- Give the player the correct amputation item ItemsHandler.Player.DeleteOldAmputationItem(self.patientPl, self.limbName) ItemsHandler.Player.SpawnAmputationItem(self.patientPl, self.limbName) @@ -144,9 +150,13 @@ function AmputationHandler:execute(damagePlayer) CachedDataHandler.AddAmputatedLimb(username, self.limbName) CachedDataHandler.CalculateHighestAmputatedLimbs(username) + -- If the part was actually infected, heal the player + if bodyPart:IsInfected() and not modDataHandler:getIsIgnoredPartInfected() then + PlayerHandler.HealZombieInfection(bd, bodyPart, self.limbName, modDataHandler) + end + -- The last part is to handle the damage that the player will receive after the amputation if not damagePlayer then return end - self:damageAfterAmputation(surgeonFactor) end diff --git a/media/lua/client/TOC/Handlers/PlayerHandler.lua b/media/lua/client/TOC/Handlers/PlayerHandler.lua index d409b24..4a67fc6 100644 --- a/media/lua/client/TOC/Handlers/PlayerHandler.lua +++ b/media/lua/client/TOC/Handlers/PlayerHandler.lua @@ -53,14 +53,52 @@ function PlayerHandler.ManageTraits(playerObj) end end +---Used to heal an area that has been cut previously. There's an exception for bites, those are managed differently +---@param bodyPart BodyPart +function PlayerHandler.HealArea(bodyPart) + bodyPart:setBleeding(false) + bodyPart:setBleedingTime(0) + + bodyPart:SetBitten(false) + bodyPart:setBiteTime(0) + + bodyPart:setCut(false) + bodyPart:setCutTime(0) + + bodyPart:setDeepWounded(false) + bodyPart:setDeepWoundTime(0) + + bodyPart:setHaveBullet(false, 0) + bodyPart:setHaveGlass(false) + bodyPart:setSplint(false, 0) +end + +---comment +---@param bodyDamage BodyDamage +---@param bodyPart BodyPart +---@param limbName string +---@param modDataHandler ModDataHandler +function PlayerHandler.HealZombieInfection(bodyDamage, bodyPart, limbName, modDataHandler) + if bodyDamage:isInfected() == false then return end + + bodyDamage:setInfected(false) + bodyDamage:setInfectionMortalityDuration(0) + bodyDamage:setInfectionTime(0) + bodyDamage:setInfectionLevel(0) + bodyPart:SetInfected(false) + + modDataHandler:setIsInfected(limbName, false) + modDataHandler:apply() +end + ------------------------- --* Events *-- ----Check if the player has an infected (as in, zombie infection) body part +---Check if the player has in infected body part or if they have been hit in a cut area ---@param character IsoGameCharacter ---@param damageType string ---@param damageAmount number -function PlayerHandler.CheckInfection(character, damageType, damageAmount) +function PlayerHandler.CheckDamage(character, damageType, damageAmount) -- TODO This fucking event barely works. Bleeding seems to be the only thing that triggers it. use this to trigger something else and then do not let it keep going @@ -69,17 +107,27 @@ function PlayerHandler.CheckInfection(character, damageType, damageAmount) if character ~= getPlayer() then return end local bd = character:getBodyDamage() local modDataHandler = ModDataHandler.GetInstance() - for i=1, #StaticData.LIMBS_STR do local limbName = StaticData.LIMBS_STR[i] local bptEnum = StaticData.BODYLOCS_IND_BPT[limbName] local bodyPart = bd:getBodyPart(bptEnum) - if bodyPart:bitten() or bodyPart:IsInfected() then - if modDataHandler:getIsCut(limbName) then - bodyPart:SetBitten(false) - else + if modDataHandler:getIsCut(limbName) then + + -- Generic injury, let's heal it since they already cut the limb off + if bodyPart:HasInjury() then + PlayerHandler.HealArea(bodyPart) + end + + -- Special case for bites\zombie infections + if bodyPart:IsInfected() then + TOC_DEBUG.print("Healed from zombie infection " .. tostring(bodyPart)) + PlayerHandler.HealZombieInfection(bd, bodyPart, limbName, modDataHandler) + end + else + if bodyPart:bitten() or bodyPart:IsInfected() then modDataHandler:setIsInfected(limbName, true) + modDataHandler:apply() end end end @@ -95,9 +143,11 @@ function PlayerHandler.CheckInfection(character, damageType, damageAmount) ModDataHandler.GetInstance():setIsIgnoredPartInfected(true) end end + + -- TODO in theory we should sync modData, but it's gonna be expensive as fuck. Figure it out end -Events.OnPlayerGetDamage.Add(PlayerHandler.CheckInfection) +Events.OnPlayerGetDamage.Add(PlayerHandler.CheckDamage) ---Updates the cicatrization process, run when a limb has been cut diff --git a/media/lua/client/TOC/UI/CutLimbInteractions.lua b/media/lua/client/TOC/UI/CutLimbInteractions.lua index 5d505b5..18dd3a4 100644 --- a/media/lua/client/TOC/UI/CutLimbInteractions.lua +++ b/media/lua/client/TOC/UI/CutLimbInteractions.lua @@ -165,6 +165,7 @@ function CutLimbHandler:checkItem(item) TOC_DEBUG.print("checkItem: " .. tostring(itemType)) if CheckIfSaw(itemType) then + TOC_DEBUG.print("added to list -> " .. itemType) self:addItem(self.items.ITEMS, item) end end