Some fixes to cicatrization handling

This commit is contained in:
ZioPao
2023-12-24 02:15:19 -05:00
parent 2c5c3885d1
commit 33140938c9
7 changed files with 44 additions and 24 deletions

View File

@@ -148,6 +148,13 @@ function AmputationHandler:execute(damagePlayer)
-- Add it to the list of cut limbs on this local client -- Add it to the list of cut limbs on this local client
local username = self.patientPl:getUsername() local username = self.patientPl:getUsername()
CachedDataHandler.AddAmputatedLimb(username, self.limbName) 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) CachedDataHandler.CalculateHighestAmputatedLimbs(username)
-- If the part was actually infected, heal the player, if they were in time (infectionLevel < 20) -- If the part was actually infected, heal the player, if they were in time (infectionLevel < 20)

View File

@@ -37,7 +37,10 @@ function CachedDataHandler.AddAmputatedLimb(username, limbName)
TOC_DEBUG.print("added " .. limbName .. " to known amputated limbs for " .. username) TOC_DEBUG.print("added " .. limbName .. " to known amputated limbs for " .. username)
-- Add it to the generic list -- 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 end
---Returns a table containing the cached amputated limbs ---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) TOC_DEBUG.print("Amputated limbs weren't calculated. Trying to calculate them now for " .. username)
CachedDataHandler.CalculateAmputatedLimbs(username) CachedDataHandler.CalculateAmputatedLimbs(username)
end end
local amputatedLimbs = CachedDataHandler.amputatedLimbs[username] local amputatedLimbs = CachedDataHandler.amputatedLimbs[username]
CachedDataHandler.highestAmputatedLimbs[username] = {} CachedDataHandler.highestAmputatedLimbs[username] = {}
--TOC_DEBUG.print("Searching highest amputations for " .. username) --TOC_DEBUG.print("Searching highest amputations for " .. username)
@@ -72,8 +76,8 @@ function CachedDataHandler.CalculateHighestAmputatedLimbs(username)
return return
end end
for i=1, #amputatedLimbs do for k, _ in pairs(amputatedLimbs) do
local limbName = amputatedLimbs[i] local limbName = k
local index = CommonMethods.GetSide(limbName) local index = CommonMethods.GetSide(limbName)
if modDataHandler:getIsCut(limbName) and modDataHandler:getIsVisible(limbName) then if modDataHandler:getIsCut(limbName) and modDataHandler:getIsVisible(limbName) then
TOC_DEBUG.print("found high amputation " .. limbName) TOC_DEBUG.print("found high amputation " .. limbName)

View File

@@ -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 -- We don't care about isOperated, isCicatrized, isCauterized since this is depending on another limb
-- Same story for cicatrizationTime, which will be 0 -- 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 end
-- Set that a limb has been cut, to activate some functions without having to loop through the parts -- Set that a limb has been cut, to activate some functions without having to loop through the parts
self:setIsAnyLimbCut(true) self:setIsAnyLimbCut(true)
-- TODO IN theory we should cache data from here, not AMputationHandler
end end
---Set a limb data ---Set a limb data

View File

@@ -213,22 +213,23 @@ function PlayerHandler.UpdateCicatrization()
local amputatedLimbs = CachedDataHandler.GetAmputatedLimbs(pl:getUsername()) local amputatedLimbs = CachedDataHandler.GetAmputatedLimbs(pl:getUsername())
local needsUpdate = false local needsUpdate = false
for i=1, #amputatedLimbs do for k, _ in pairs(amputatedLimbs) do
local limbName = amputatedLimbs[i] local limbName = k
local isCicatrized = modDataHandler:getIsCicatrized(limbName) local isCicatrized = modDataHandler:getIsCicatrized(limbName)
if not isCicatrized then if not isCicatrized then
needsUpdate = true needsUpdate = true
local cicTime = modDataHandler:getCicatrizationTime(limbName) local cicTime = modDataHandler:getCicatrizationTime(limbName)
TOC_DEBUG.print("updating cicatrization for " .. tostring(limbName)) TOC_DEBUG.print("updating cicatrization for " .. tostring(limbName))
if cicTime > 0 then cicTime = cicTime - SandboxVars.TOC.CicatrizationSpeed
cicTime = cicTime - SandboxVars.TOC.CicatrizationSpeed modDataHandler:setCicatrizationTime(limbName, cicTime)
modDataHandler:setCicatrizationTime(limbName, cicTime) TOC_DEBUG.print("new cicatrization time: " .. tostring(cicTime))
TOC_DEBUG.print("new cicatrization time: " .. tostring(cicTime)) if cicTime <= 0 then
if cicTime < 0 then TOC_DEBUG.print(tostring(limbName) .. " is cicatrized")
modDataHandler:setIsCicatrized(limbName, true) modDataHandler:setIsCicatrized(limbName, true)
end
end end
end end
end end
@@ -270,8 +271,9 @@ function ISBaseTimedAction:adjustMaxTime(maxTime)
if time ~= -1 and modDataHandler and modDataHandler:getIsAnyLimbCut() then if time ~= -1 and modDataHandler and modDataHandler:getIsAnyLimbCut() then
local pl = getPlayer() local pl = getPlayer()
local amputatedLimbs = CachedDataHandler.GetAmputatedLimbs(pl:getUsername()) 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 --if modDataHandler:getIsCut(limbName) then
local perk = Perks["Side_" .. CommonMethods.GetSide(limbName)] local perk = Perks["Side_" .. CommonMethods.GetSide(limbName)]
local perkLevel = pl:getPerkLevel(perk) local perkLevel = pl:getPerkLevel(perk)
@@ -296,8 +298,8 @@ function ISBaseTimedAction:perform()
if not modDataHandler:getIsAnyLimbCut() then return end if not modDataHandler:getIsAnyLimbCut() then return end
local amputatedLimbs = CachedDataHandler.GetAmputatedLimbs(PlayerHandler.username) local amputatedLimbs = CachedDataHandler.GetAmputatedLimbs(PlayerHandler.username)
for i=1, #amputatedLimbs do for k, _ in pairs(amputatedLimbs) do
local limbName = amputatedLimbs[i] local limbName = k
if modDataHandler:getIsCut(limbName) then if modDataHandler:getIsCut(limbName) then
local side = CommonMethods.GetSide(limbName) local side = CommonMethods.GetSide(limbName)
PlayerHandler.playerObj:getXp():AddXP(Perks["Side_" .. side], 1) -- TODO Make it dynamic PlayerHandler.playerObj:getXp():AddXP(Perks["Side_" .. side], 1) -- TODO Make it dynamic

View File

@@ -46,8 +46,8 @@ function ProsthesisHandler.CheckIfEquippable(bodyLocation)
TOC_DEBUG.print("checking side: " .. tostring(side)) TOC_DEBUG.print("checking side: " .. tostring(side))
local amputatedLimbs = CachedDataHandler.GetAmputatedLimbs(getPlayer():getUsername()) local amputatedLimbs = CachedDataHandler.GetAmputatedLimbs(getPlayer():getUsername())
for i = 1, #amputatedLimbs do for k, _ in pairs(amputatedLimbs) do
local limbName = amputatedLimbs[i] local limbName = k
if string.contains(limbName, side) and not string.contains(limbName, "UpperArm") then if string.contains(limbName, side) and not string.contains(limbName, "UpperArm") then
TOC_DEBUG.print("found acceptable limb to use prosthesis") TOC_DEBUG.print("found acceptable limb to use prosthesis")
return true return true

View File

@@ -173,7 +173,7 @@ function ISHealthBodyPartListBox:doDrawItem(y, item, alt)
local fontHgt = getTextManager():getFontHeight(UIFont.Small) local fontHgt = getTextManager():getFontHeight(UIFont.Small)
-- TODO Get username of the correct player -- TODO Get username of the correct player
local username = getPlayer():getUsername() local username = self.parent.character:getUsername()
--local amputatedLimbs = CachedDataHandler.GetIndexedAmputatedLimbs(username) --local amputatedLimbs = CachedDataHandler.GetIndexedAmputatedLimbs(username)
---@type BodyPart ---@type BodyPart
@@ -185,8 +185,13 @@ function ISHealthBodyPartListBox:doDrawItem(y, item, alt)
local modDataHandler = ModDataHandler.GetInstance(username) local modDataHandler = ModDataHandler.GetInstance(username)
if modDataHandler:getIsCut(limbName) and modDataHandler:getIsVisible(limbName) then if modDataHandler:getIsCut(limbName) and modDataHandler:getIsVisible(limbName) then
local cicaTime = modDataHandler:getCicatrizationTime(limbName) local cicaTime = modDataHandler:getCicatrizationTime(limbName)
self:drawText("- " .. "Cicatrization " .. tostring(cicaTime), x, y, 0.89, 0.28, 0.28, 1, UIFont.Small)
y = y + fontHgt; -- Show it in percentage
local maxCicaTime = StaticData.LIMBS_CICATRIZATION_TIME_IND_NUM[limbName]
local percentage = (1 - cicaTime/maxCicaTime) * 100
self:drawText("- " .. string.format("Cicatrization %.2f", percentage) .. "%", x, y, 0.89, 0.28, 0.28, 1, UIFont.Small)
y = y + fontHgt
end end

View File

@@ -50,8 +50,8 @@ local function AddOvenContextMenu(playerNum, context, worldObjects, test)
local optionMain = context:addOption(getText("ContextMenu_Cauterize"), nil) local optionMain = context:addOption(getText("ContextMenu_Cauterize"), nil)
local subMenu = context:getNew(context) local subMenu = context:getNew(context)
context:addSubMenu(optionMain, subMenu) context:addSubMenu(optionMain, subMenu)
for i=1, #amputatedLimbs do for k, _ in pairs(amputatedLimbs) do
local limbName = amputatedLimbs[i] local limbName = k
local option = subMenu:addOption(getText("ContextMenu_Limb_" .. limbName), limbName, Cauterize) local option = subMenu:addOption(getText("ContextMenu_Limb_" .. limbName), limbName, Cauterize)
option.notAvailable = isTempLow option.notAvailable = isTempLow
if isTempLow then if isTempLow then