- Fixed bug that could cause bit status to amputated limbs

- Optimizations to various functions
This commit is contained in:
Pao
2023-01-26 19:52:22 +01:00
parent 753061e6dc
commit e29bb1c9df
3 changed files with 46 additions and 90 deletions

View File

@@ -20,29 +20,23 @@ function TocCheckIfStillInfected(limbs_data)
return check return check
end end
function TocCureInfection(body_damage, limbs_data, part_name) function TocCureInfection(body_damage, part_name)
local body_part_type = body_damage:getBodyPart(TocGetBodyPartTypeFromPartName(part_name)) local body_part_type = body_damage:getBodyPart(TocGetBodyPartTypeFromPartName(part_name))
-- Check if we can heal the infection body_damage:setInfected(false)
local is_other_bodypart_infected = getPlayer():getModData().TOC.Limbs.is_other_bodypart_infected body_part_type:SetInfected(false)
body_damage:setInfectionMortalityDuration(-1)
body_damage:setInfectionTime(-1)
body_damage:setInfectionLevel(0)
local body_part_types = body_damage:getBodyParts()
if not is_other_bodypart_infected and not TheOnlyCure.CheckIfOtherLimbsAreInfected(limbs_data, part_name) then -- TODO I think this is enough... we should just cycle if with everything instead of that crap up there
body_damage:setInfected(false) for i = body_part_types:size() - 1, 0, -1 do
body_part_type:SetInfected(false) local bodyPart = body_part_types:get(i);
body_damage:setInfectionMortalityDuration(-1) bodyPart:SetInfected(false);
body_damage:setInfectionTime(-1)
body_damage:setInfectionLevel(0)
local body_part_types = body_damage:getBodyParts()
-- TODO I think this is enough... we should just cycle if with everything instead of that crap up there
for i = body_part_types:size() - 1, 0, -1 do
local bodyPart = body_part_types:get(i);
bodyPart:SetInfected(false);
end
end end
if body_part_type:scratched() then body_part_type:setScratched(false, false) end if body_part_type:scratched() then body_part_type:setScratched(false, false) end
if body_part_type:haveGlass() then body_part_type:setHaveGlass(false) end if body_part_type:haveGlass() then body_part_type:setHaveGlass(false) end
if body_part_type:haveBullet() then body_part_type:setHaveBullet(false, 0) end if body_part_type:haveBullet() then body_part_type:setHaveBullet(false, 0) end
@@ -50,11 +44,6 @@ function TocCureInfection(body_damage, limbs_data, part_name)
if body_part_type:isBurnt() then body_part_type:setBurnTime(0) end if body_part_type:isBurnt() then body_part_type:setBurnTime(0) end
if body_part_type:isCut() then body_part_type:setCut(false, false) end --Lacerations if body_part_type:isCut() then body_part_type:setCut(false, false) end --Lacerations
if body_part_type:getFractureTime() > 0 then body_part_type:setFractureTime(0) end if body_part_type:getFractureTime() > 0 then body_part_type:setFractureTime(0) end
end end
function TocDeleteOtherAmputatedLimbs(side) function TocDeleteOtherAmputatedLimbs(side)
@@ -89,8 +78,6 @@ function TocGetSawInInventory(surgeon)
return item return item
end end
function TocDamagePlayerDuringAmputation(patient, part_name) function TocDamagePlayerDuringAmputation(patient, part_name)
local body_part_type = TocGetBodyPartTypeFromPartName(part_name) local body_part_type = TocGetBodyPartTypeFromPartName(part_name)
local body_damage = patient:getBodyDamage() local body_damage = patient:getBodyDamage()
@@ -103,21 +90,7 @@ function TocDamagePlayerDuringAmputation(patient, part_name)
end end
-- OperateLimb -- OperateLimb
function SetBodyPartsStatusAfterOperation(player, limbs_data, part_name, use_oven) local function FixSingleBodyPartType(body_part_type, use_oven)
--for _, v in ipairs(GetBodyParts()) do
local body_part_type = player:getBodyDamage():getBodyPart(TocGetBodyPartTypeFromPartName(part_name))
FixSingleBodyPartType(body_part_type, use_oven)
for _, v in ipairs(limbs_data[part_name].depends_on) do
local depended_body_part_type = player:getBodyDamage():getBodyPart(TocGetBodyPartTypeFromPartName(v))
FixSingleBodyPartType(depended_body_part_type, use_oven)
end
end
function FixSingleBodyPartType(body_part_type, use_oven)
body_part_type:setDeepWounded(false) --Basically like stitching body_part_type:setDeepWounded(false) --Basically like stitching
body_part_type:setDeepWoundTime(0) body_part_type:setDeepWoundTime(0)
if use_oven then if use_oven then
@@ -133,6 +106,21 @@ function FixSingleBodyPartType(body_part_type, use_oven)
end end
end end
function SetBodyPartsStatusAfterOperation(player, limbs_data, part_name, use_oven)
--for _, v in ipairs(GetBodyParts()) do
local body_part_type = player:getBodyDamage():getBodyPart(TocGetBodyPartTypeFromPartName(part_name))
FixSingleBodyPartType(body_part_type, use_oven)
for _, v in ipairs(limbs_data[part_name].depends_on) do
local depended_body_part_type = player:getBodyDamage():getBodyPart(TocGetBodyPartTypeFromPartName(v))
FixSingleBodyPartType(depended_body_part_type, use_oven)
end
end
-- Unequip Prosthesis -- Unequip Prosthesis
@@ -147,8 +135,6 @@ local function PartNameToBodyLocationProsthesis(name)
if name == "Left_UpperArm" then return "ArmLeft_Prot" end if name == "Left_UpperArm" then return "ArmLeft_Prot" end
end end
local function PartNameToBodyLocationAmputation(name) local function PartNameToBodyLocationAmputation(name)
-- This is still correct but naming sucks -- This is still correct but naming sucks
if name == "Right_Hand" then return "ArmRight" end if name == "Right_Hand" then return "ArmRight" end

View File

@@ -1,20 +1,4 @@
-- Helper for DropItem local function CheckIfPlayerIsInfected(player, toc_data)
function TheOnlyCure.CheckIfCanPickUpItem(toc_data, side, limb, secondary_limb)
-- TODO we can use this when uninstall prost or when cutting
local full_primary_limb = side .. limb
local full_secondary_limb = side .. secondary_limb
return toc_data[full_primary_limb].is_cut and
not (toc_data[full_primary_limb].is_prosthesis_equipped or toc_data[full_secondary_limb]) or
(toc_data[full_secondary_limb].is_cut and not toc_data[full_secondary_limb].is_prosthesis_equipped)
end
function TheOnlyCure.CheckIfPlayerIsInfected(player, toc_data)
local body_damage = player:getBodyDamage() local body_damage = player:getBodyDamage()
@@ -48,26 +32,11 @@ function TheOnlyCure.CheckIfPlayerIsInfected(player, toc_data)
end end
end end
function TheOnlyCure.UpdatePlayerHealth(player, part_data)
local body_damage = player:getBodyDamage()
if player:HasTrait("Insensitive") then body_damage:setPainReduction(49) end
for i, part_name in pairs(GetBodyParts()) do
if part_data[part_name].is_cut then
TheOnlyCure.SetHealthStatusForBodyPart(part_data, part_name, player)
end
end
end
--Helper function for UpdatePlayerHealth --Helper function for UpdatePlayerHealth
function TheOnlyCure.SetHealthStatusForBodyPart(part_data, part_name, player) local function SetHealthStatusForBodyPart(part_data, part_name, player)
-- TODO this can be moved away from updates -- TODO this can be moved away from updates
@@ -133,24 +102,25 @@ function TheOnlyCure.SetHealthStatusForBodyPart(part_data, part_name, player)
--body_part_type:setBandaged(true, bandage_life, false, bandage_type) --body_part_type:setBandaged(true, bandage_life, false, bandage_type)
end end
--Helper function for UpdatePlayerHealth
function TheOnlyCure.CheckIfOtherLimbsAreInfected(limbs_data, part_name) local function UpdatePlayerHealth(player, part_data)
local body_damage = player:getBodyDamage()
local body_parts = GetBodyParts()
body_parts[part_name] = nil
for _, v in pairs(body_parts) do if player:HasTrait("Insensitive") then body_damage:setPainReduction(49) end
if limbs_data[v].is_infected then
return true for _, part_name in pairs(GetBodyParts()) do
if part_data[part_name].is_cut then
SetHealthStatusForBodyPart(part_data, part_name, player)
end end
end end
return false
end end
-- MAIN UPDATE FUNCTIONS -- MAIN UPDATE FUNCTIONS
function TheOnlyCure.UpdateEveryOneMinute() local function TocUpdateEveryOneMinute()
local player = getPlayer() local player = getPlayer()
-- To prevent errors during loading -- To prevent errors during loading
@@ -161,8 +131,8 @@ function TheOnlyCure.UpdateEveryOneMinute()
local toc_data = player:getModData().TOC local toc_data = player:getModData().TOC
if toc_data ~= nil then if toc_data ~= nil then
TheOnlyCure.CheckIfPlayerIsInfected(player, toc_data) CheckIfPlayerIsInfected(player, toc_data)
TheOnlyCure.UpdatePlayerHealth(player, toc_data.Limbs) UpdatePlayerHealth(player, toc_data.Limbs)
end end
@@ -177,7 +147,7 @@ function TheOnlyCure.UpdateEveryOneMinute()
end end
function TheOnlyCure.UpdateEveryTenMinutes() local function TocUpdateEveryTenMinutes()
local player = getPlayer() local player = getPlayer()
@@ -204,5 +174,5 @@ function TheOnlyCure.UpdateEveryTenMinutes()
end end
Events.EveryTenMinutes.Add(TheOnlyCure.UpdateEveryTenMinutes) Events.EveryTenMinutes.Add(TocUpdateEveryTenMinutes)
Events.EveryOneMinute.Add(TheOnlyCure.UpdateEveryOneMinute) Events.EveryOneMinute.Add(TocUpdateEveryOneMinute)

View File

@@ -275,7 +275,7 @@ function TheOnlyCure.CutLimb(part_name, surgeon_factor, bandage_table, painkille
-- Second check, let's see if there is any other infected limb. -- Second check, let's see if there is any other infected limb.
if TocCheckIfStillInfected(limbs_data) == false then if TocCheckIfStillInfected(limbs_data) == false then
TocCureInfection(body_damage, limbs_data, part_name) TocCureInfection(body_damage, part_name)
getPlayer():Say("I'm gonna be fine...") getPlayer():Say("I'm gonna be fine...")
else else
getPlayer():Say("I'm still gonna die...") getPlayer():Say("I'm still gonna die...")