cicatrization process

This commit is contained in:
ZioPao
2023-11-16 12:50:07 +01:00
parent c09c3ac646
commit 34570cd013
7 changed files with 114 additions and 18 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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 *--

View File

@@ -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

View File

@@ -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