diff --git a/dev_stuff/healthPanelHide.psd b/dev_stuff/healthPanelHide.psd index ab18f59..7fa36bc 100644 Binary files a/dev_stuff/healthPanelHide.psd and b/dev_stuff/healthPanelHide.psd differ diff --git a/media/lua/client/TOC/CommonMethods.lua b/media/lua/client/TOC/CommonMethods.lua index 860e410..ee335f3 100644 --- a/media/lua/client/TOC/CommonMethods.lua +++ b/media/lua/client/TOC/CommonMethods.lua @@ -7,4 +7,12 @@ function CommonMethods.GetSide(name) if string.find(name, "_L") then return "L" else return "R" end end +---Stops and start an event, making sure that we don't stack them up +---@param event string +---@param method function +function CommonMethods.SafeStartEvent(event, method) + Events[event].Remove(method) + Events[event].Add(method) +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 b9752d5..fea4d21 100644 --- a/media/lua/client/TOC/Handlers/AmputationHandler.lua +++ b/media/lua/client/TOC/Handlers/AmputationHandler.lua @@ -5,6 +5,13 @@ local PlayerHandler = require("TOC/Handlers/PlayerHandler") local StaticData = require("TOC/StaticData") --------------------------- +--Triggered when a limb has been amputated +---@class Events +---@field OnAmputatedLimb any +LuaEventManager.AddEvent("OnAmputatedLimb") + +-------------- + -- TODO Add Bandages, Torniquet, etc. --- Manages an amputation. Will be run on the patient client ---@class AmputationHandler @@ -150,15 +157,17 @@ function AmputationHandler:execute(damagePlayer) CachedDataHandler.AddAmputatedLimb(username, self.limbName) CachedDataHandler.CalculateHighestAmputatedLimbs(username) - -- TODO Check infection level! - -- If the part was actually infected, heal the player, if they were in time - if bodyPart:IsInfected() and not modDataHandler:getIsIgnoredPartInfected() then + -- 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 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) + + -- Trigger this event + triggerEvent("OnAmputatedLimb") end ---Deletes the instance diff --git a/media/lua/client/TOC/Handlers/ModDataHandler.lua b/media/lua/client/TOC/Handlers/ModDataHandler.lua index 8ccb967..d1f272f 100644 --- a/media/lua/client/TOC/Handlers/ModDataHandler.lua +++ b/media/lua/client/TOC/Handlers/ModDataHandler.lua @@ -109,6 +109,20 @@ function ModDataHandler:setIsInfected(limbName, isInfected) self.tocData.limbs[limbName].isInfected = isInfected end +---Set isCicatrized +---@param limbName string +---@param isCicatrized boolean +function ModDataHandler:setIsCicatrized(limbName, isCicatrized) + self.tocData.limbs[limbName].isCicatrized = isCicatrized +end + +---Set cicatrizationTime +---@param limbName string +---@param cicatrizationTime number +function ModDataHandler:setCicatrizationTime(limbName, cicatrizationTime) + self.tocData.limbs[limbName].cicatrizationTime = cicatrizationTime +end + ---Set isProstEquipped ---@param group string ---@param isProstEquipped boolean @@ -152,6 +166,20 @@ function ModDataHandler:getIsVisible(limbName) return self.tocData.limbs[limbName].isVisible end +---Get isCicatrized +---@param limbName string +---@return boolean +function ModDataHandler:getIsCicatrized(limbName) + return self.tocData.limbs[limbName].isCicatrized +end + +---Get cicatrizationTime +---@param limbName string +---@return number +function ModDataHandler:getCicatrizationTime(limbName) + return self.tocData.limbs[limbName].cicatrizationTime +end + ---Get isProstEquipped ---@param group string ---@return boolean @@ -213,6 +241,13 @@ function ModDataHandler:setLimbParams(limbName, ampStatus, cicatrizationTime) if cicatrizationTime ~= nil then limbData.cicatrizationTime = cicatrizationTime end end +--* Update statuses of a limb *-- + +---Decreases the cicatrization time +---@param limbName string +function ModDataHandler:decreaseCicatrizationTime(limbName) + self.tocData.limbs[limbName].cicatrizationTime = self.tocData.limbs[limbName].cicatrizationTime - 1 +end --* Global Mod Data Handling *-- diff --git a/media/lua/client/TOC/Handlers/PlayerHandler.lua b/media/lua/client/TOC/Handlers/PlayerHandler.lua index bbf97fe..3437df9 100644 --- a/media/lua/client/TOC/Handlers/PlayerHandler.lua +++ b/media/lua/client/TOC/Handlers/PlayerHandler.lua @@ -29,6 +29,11 @@ function PlayerHandler.InitializePlayer(playerObj, isForced) CachedDataHandler.CalculateAmputatedLimbs(username) CachedDataHandler.CalculateHighestAmputatedLimbs(username) + -- TODO Check if there are cut limbs and that needs cicatrization. If yes, then enable the loop + if ModDataHandler.GetInstance(username):getIsAnyLimbCut() then + CommonMethods.SafeStartEvent("EveryHours", PlayerHandler.UpdateCicatrization) + end + -- Since isForced is used to reset an existing player data, we're gonna clean their ISHealthPanel table too if isForced then --ISHealthPanel.highestAmputations = {} @@ -149,14 +154,50 @@ end Events.OnPlayerGetDamage.Add(PlayerHandler.CheckDamage) - ----Updates the cicatrization process, run when a limb has been cut +---Updates the cicatrization process, run when a limb has been cut. Run it every 1 hour function PlayerHandler.UpdateCicatrization() - if ModDataHandler.GetInstance():getIsAnyLimbCut() == false then return end + local modDataHandler = ModDataHandler.GetInstance() + if modDataHandler:getIsAnyLimbCut() == false then + Events.EveryHours.Remove(PlayerHandler.UpdateCicatrization) + end + + local pl = PlayerHandler.playerObj + local amputatedLimbs = CachedDataHandler.GetAmputatedLimbs(pl:getUsername()) + local needsUpdate = false + + for i=1, #amputatedLimbs do + local limbName = amputatedLimbs[i] + local isCicatrized = modDataHandler:getIsCicatrized(limbName) + if not isCicatrized then + needsUpdate = true + local cicTime = modDataHandler:getCicatrizationTime(limbName) + + if cicTime > 0 then + cicTime = cicTime - 60 -- 1 per minute, each cicatrizationTime is divisible by 60 + modDataHandler:setCicatrizationTime(limbName, cicTime) + if cicTime < 0 then + modDataHandler:setIsCicatrized(limbName, true) + end + end + end + end + + if needsUpdate then + modDataHandler:apply() -- TODO This is gonna be heavy. Not entirely sure + else + Events.EveryHours.Remove(PlayerHandler.UpdateCicatrization) -- We can remove it safely, no cicatrization happening here boys + end + TOC_DEBUG.print("updating cicatrization!") - -- TODO Update cicatrization end +---Starts safely the loop to update cicatrzation +function PlayerHandler.ToggleCicatrizationUpdate() + CommonMethods.SafeStartEvent("EveryHours", PlayerHandler.UpdateCicatrization) +end + +Events.OnAmputatedLimb.Add(PlayerHandler.ToggleCicatrizationUpdate) + ------------------------------------------ @@ -181,13 +222,13 @@ function ISBaseTimedAction:adjustMaxTime(maxTime) local amputatedLimbs = CachedDataHandler.GetAmputatedLimbs(pl:getUsername()) for i=1, #amputatedLimbs do local limbName = amputatedLimbs[i] - if modDataHandler:getIsCut(limbName) then - local perk = Perks["Side_" .. CommonMethods.GetSide(limbName)] - local perkLevel = pl:getPerkLevel(perk) - local perkLevelScaled - if perkLevel ~= 0 then perkLevelScaled = perkLevel / 10 else perkLevelScaled = 0 end - time = time * (StaticData.LIMBS_TIME_MULTIPLIER_IND_NUM[limbName] - perkLevelScaled) - end + --if modDataHandler:getIsCut(limbName) then + local perk = Perks["Side_" .. CommonMethods.GetSide(limbName)] + local perkLevel = pl:getPerkLevel(perk) + local perkLevelScaled + if perkLevel ~= 0 then perkLevelScaled = perkLevel / 10 else perkLevelScaled = 0 end + time = time * (StaticData.LIMBS_TIME_MULTIPLIER_IND_NUM[limbName] - perkLevelScaled) + --end end end return time diff --git a/media/lua/client/TOC/Main.lua b/media/lua/client/TOC/Main.lua index c4fc077..e5b6a06 100644 --- a/media/lua/client/TOC/Main.lua +++ b/media/lua/client/TOC/Main.lua @@ -1,4 +1,5 @@ local PlayerHandler = require("TOC/Handlers/PlayerHandler") +local CommonMethods = require("TOC/CommonMethods") ------------------ ---@class Main @@ -44,6 +45,7 @@ end function Main.Initialize() + ---Looop until we've successfully initialized the mod local function TryToInitialize() local pl = getPlayer() TOC_DEBUG.print("Current username in TryToInitialize: " .. pl:getUsername()) @@ -55,8 +57,7 @@ function Main.Initialize() PlayerHandler.InitializePlayer(pl, false) Events.OnTick.Remove(TryToInitialize) end - - Events.OnTick.Add(TryToInitialize) + CommonMethods.SafeStartEvent("OnTick", TryToInitialize) end diff --git a/media/lua/shared/TOC/StaticData.lua b/media/lua/shared/TOC/StaticData.lua index 2eaa1a0..16f15b4 100644 --- a/media/lua/shared/TOC/StaticData.lua +++ b/media/lua/shared/TOC/StaticData.lua @@ -55,9 +55,11 @@ StaticData.LIMBS_BASE_DAMAGE_IND_NUM = {} StaticData.LIMBS_TIME_MULTIPLIER_IND_NUM = {} StaticData.BODYLOCS_IND_BPT = {} +-- CicatrizationBaseTime should be mod 60 since we're using EveryHours to update the cicatrizationTime + local function AssembleHandData(assembledName) StaticData.LIMBS_BASE_DAMAGE_IND_NUM[assembledName] = 60 - StaticData.LIMBS_CICATRIZATION_TIME_IND_NUM[assembledName] = 1700 + StaticData.LIMBS_CICATRIZATION_TIME_IND_NUM[assembledName] = 1200 StaticData.LIMBS_TIME_MULTIPLIER_IND_NUM[assembledName] = 2 StaticData.LIMBS_DEPENDENCIES_IND_STR[assembledName] = {} end @@ -71,7 +73,7 @@ end local function AssembleUpperarmData(assembledName, side) StaticData.LIMBS_BASE_DAMAGE_IND_NUM[assembledName] = 100 - StaticData.LIMBS_CICATRIZATION_TIME_IND_NUM[assembledName] = 2000 + StaticData.LIMBS_CICATRIZATION_TIME_IND_NUM[assembledName] = 1800 StaticData.LIMBS_TIME_MULTIPLIER_IND_NUM[assembledName] = 4 StaticData.LIMBS_DEPENDENCIES_IND_STR[assembledName] = { StaticData.PARTS_IND_STR.Hand .. "_" .. side, StaticData.PARTS_IND_STR.ForeArm .. "_" .. side }