Some fixes to cicatrization handling
This commit is contained in:
@@ -148,6 +148,13 @@ function AmputationHandler:execute(damagePlayer)
|
||||
-- Add it to the list of cut limbs on this local client
|
||||
local username = self.patientPl:getUsername()
|
||||
CachedDataHandler.AddAmputatedLimb(username, self.limbName)
|
||||
|
||||
-- TODO Not optimal, we're already cycling through this when using setCutLimb
|
||||
for i=1, #StaticData.LIMBS_DEPENDENCIES_IND_STR[self.limbName] do
|
||||
local dependedLimbName = StaticData.LIMBS_DEPENDENCIES_IND_STR[self.limbName][i]
|
||||
CachedDataHandler.AddAmputatedLimb(username, dependedLimbName)
|
||||
end
|
||||
|
||||
CachedDataHandler.CalculateHighestAmputatedLimbs(username)
|
||||
|
||||
-- If the part was actually infected, heal the player, if they were in time (infectionLevel < 20)
|
||||
|
||||
@@ -37,7 +37,10 @@ function CachedDataHandler.AddAmputatedLimb(username, limbName)
|
||||
TOC_DEBUG.print("added " .. limbName .. " to known amputated limbs for " .. username)
|
||||
|
||||
-- Add it to the generic list
|
||||
table.insert(CachedDataHandler.amputatedLimbs[username], limbName)
|
||||
-- TODO this is wrong
|
||||
|
||||
CachedDataHandler.amputatedLimbs[username][limbName] = limbName
|
||||
--table.insert(CachedDataHandler.amputatedLimbs[username], limbName)
|
||||
end
|
||||
|
||||
---Returns a table containing the cached amputated limbs
|
||||
@@ -63,6 +66,7 @@ function CachedDataHandler.CalculateHighestAmputatedLimbs(username)
|
||||
TOC_DEBUG.print("Amputated limbs weren't calculated. Trying to calculate them now for " .. username)
|
||||
CachedDataHandler.CalculateAmputatedLimbs(username)
|
||||
end
|
||||
|
||||
local amputatedLimbs = CachedDataHandler.amputatedLimbs[username]
|
||||
CachedDataHandler.highestAmputatedLimbs[username] = {}
|
||||
--TOC_DEBUG.print("Searching highest amputations for " .. username)
|
||||
@@ -72,8 +76,8 @@ function CachedDataHandler.CalculateHighestAmputatedLimbs(username)
|
||||
return
|
||||
end
|
||||
|
||||
for i=1, #amputatedLimbs do
|
||||
local limbName = amputatedLimbs[i]
|
||||
for k, _ in pairs(amputatedLimbs) do
|
||||
local limbName = k
|
||||
local index = CommonMethods.GetSide(limbName)
|
||||
if modDataHandler:getIsCut(limbName) and modDataHandler:getIsVisible(limbName) then
|
||||
TOC_DEBUG.print("found high amputation " .. limbName)
|
||||
|
||||
@@ -246,12 +246,14 @@ function ModDataHandler:setCutLimb(limbName, isOperated, isCicatrized, isCauteri
|
||||
|
||||
-- We don't care about isOperated, isCicatrized, isCauterized since this is depending on another limb
|
||||
-- Same story for cicatrizationTime, which will be 0
|
||||
self:setLimbParams(dependedLimbName, {isCut = true, isInfected = false, isVisible = false}, 0)
|
||||
-- isCicatized is to true to prevent it from doing the cicatrization process
|
||||
self:setLimbParams(dependedLimbName, {isCut = true, isInfected = false, isVisible = false, isCicatrized = true}, 0)
|
||||
end
|
||||
|
||||
-- Set that a limb has been cut, to activate some functions without having to loop through the parts
|
||||
self:setIsAnyLimbCut(true)
|
||||
|
||||
-- TODO IN theory we should cache data from here, not AMputationHandler
|
||||
end
|
||||
|
||||
---Set a limb data
|
||||
|
||||
@@ -213,22 +213,23 @@ function PlayerHandler.UpdateCicatrization()
|
||||
local amputatedLimbs = CachedDataHandler.GetAmputatedLimbs(pl:getUsername())
|
||||
local needsUpdate = false
|
||||
|
||||
for i=1, #amputatedLimbs do
|
||||
local limbName = amputatedLimbs[i]
|
||||
for k, _ in pairs(amputatedLimbs) do
|
||||
local limbName = k
|
||||
local isCicatrized = modDataHandler:getIsCicatrized(limbName)
|
||||
|
||||
if not isCicatrized then
|
||||
needsUpdate = true
|
||||
local cicTime = modDataHandler:getCicatrizationTime(limbName)
|
||||
TOC_DEBUG.print("updating cicatrization for " .. tostring(limbName))
|
||||
|
||||
if cicTime > 0 then
|
||||
cicTime = cicTime - SandboxVars.TOC.CicatrizationSpeed
|
||||
modDataHandler:setCicatrizationTime(limbName, cicTime)
|
||||
TOC_DEBUG.print("new cicatrization time: " .. tostring(cicTime))
|
||||
if cicTime < 0 then
|
||||
modDataHandler:setIsCicatrized(limbName, true)
|
||||
end
|
||||
cicTime = cicTime - SandboxVars.TOC.CicatrizationSpeed
|
||||
modDataHandler:setCicatrizationTime(limbName, cicTime)
|
||||
TOC_DEBUG.print("new cicatrization time: " .. tostring(cicTime))
|
||||
if cicTime <= 0 then
|
||||
TOC_DEBUG.print(tostring(limbName) .. " is cicatrized")
|
||||
modDataHandler:setIsCicatrized(limbName, true)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -270,8 +271,9 @@ function ISBaseTimedAction:adjustMaxTime(maxTime)
|
||||
if time ~= -1 and modDataHandler and modDataHandler:getIsAnyLimbCut() then
|
||||
local pl = getPlayer()
|
||||
local amputatedLimbs = CachedDataHandler.GetAmputatedLimbs(pl:getUsername())
|
||||
for i=1, #amputatedLimbs do
|
||||
local limbName = amputatedLimbs[i]
|
||||
|
||||
for k, _ in pairs(amputatedLimbs) do
|
||||
local limbName = k
|
||||
--if modDataHandler:getIsCut(limbName) then
|
||||
local perk = Perks["Side_" .. CommonMethods.GetSide(limbName)]
|
||||
local perkLevel = pl:getPerkLevel(perk)
|
||||
@@ -296,8 +298,8 @@ function ISBaseTimedAction:perform()
|
||||
if not modDataHandler:getIsAnyLimbCut() then return end
|
||||
|
||||
local amputatedLimbs = CachedDataHandler.GetAmputatedLimbs(PlayerHandler.username)
|
||||
for i=1, #amputatedLimbs do
|
||||
local limbName = amputatedLimbs[i]
|
||||
for k, _ in pairs(amputatedLimbs) do
|
||||
local limbName = k
|
||||
if modDataHandler:getIsCut(limbName) then
|
||||
local side = CommonMethods.GetSide(limbName)
|
||||
PlayerHandler.playerObj:getXp():AddXP(Perks["Side_" .. side], 1) -- TODO Make it dynamic
|
||||
|
||||
@@ -46,8 +46,8 @@ function ProsthesisHandler.CheckIfEquippable(bodyLocation)
|
||||
TOC_DEBUG.print("checking side: " .. tostring(side))
|
||||
|
||||
local amputatedLimbs = CachedDataHandler.GetAmputatedLimbs(getPlayer():getUsername())
|
||||
for i = 1, #amputatedLimbs do
|
||||
local limbName = amputatedLimbs[i]
|
||||
for k, _ in pairs(amputatedLimbs) do
|
||||
local limbName = k
|
||||
if string.contains(limbName, side) and not string.contains(limbName, "UpperArm") then
|
||||
TOC_DEBUG.print("found acceptable limb to use prosthesis")
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user