From 2a2b6ef9784a4583ce3e89a836fc3974cc63eba4 Mon Sep 17 00:00:00 2001 From: Pao Date: Wed, 18 Jan 2023 04:12:44 +0100 Subject: [PATCH] Some fixes and a compat function for older versions --- media/lua/client/TOC_Debug.lua | 2 +- media/lua/client/TOC_HelperFunctions.lua | 9 ++- media/lua/client/TOC_main.lua | 57 +++++++++++++++++-- .../TimedActions/ISInstallProsthesis.lua | 2 +- media/lua/client/Utils/UsefulFunctions.lua | 2 +- 5 files changed, 60 insertions(+), 12 deletions(-) diff --git a/media/lua/client/TOC_Debug.lua b/media/lua/client/TOC_Debug.lua index 962f69d..fad42cd 100644 --- a/media/lua/client/TOC_Debug.lua +++ b/media/lua/client/TOC_Debug.lua @@ -1,7 +1,7 @@ function ResetEverything() local player = getPlayer() - local mod_data = player:getModData() + local mod_data = player:getModData() mod_data.TOC = nil TheOnlyCure.InitTheOnlyCure(_, player) diff --git a/media/lua/client/TOC_HelperFunctions.lua b/media/lua/client/TOC_HelperFunctions.lua index 5a20ac2..23c73cc 100644 --- a/media/lua/client/TOC_HelperFunctions.lua +++ b/media/lua/client/TOC_HelperFunctions.lua @@ -79,13 +79,16 @@ function CheckIfItemIsAmputatedLimb(item) local item_full_type = item:getFullType() local sides = {"Left", "Right"} - local limbs_to_check = {"Hand", "Forearm", "Arm"} + local limbs_to_check = {"Hand", "LowerArm", "UpperArm"} local is_amputated_limb = false - for _, part_name in ipairs(limbs_to_check) do + for _, part in ipairs(limbs_to_check) do for _, side in ipairs(sides) do - local check_name = "TOC.Arm" .. side .. "_no" .. part_name + + local part_name = side .. "_" .. part + + local check_name = "TOC.Amputation_" .. part_name print(check_name) if item_full_type == check_name then is_amputated_limb = true diff --git a/media/lua/client/TOC_main.lua b/media/lua/client/TOC_main.lua index ad3ed50..568edfe 100644 --- a/media/lua/client/TOC_main.lua +++ b/media/lua/client/TOC_main.lua @@ -15,8 +15,10 @@ function TheOnlyCure.InitTheOnlyCure(_, player) local mod_data = player:getModData() + -- TODO if mod_data.TOC == nil then + print("TOC: Creating mod_data.TOC") mod_data.TOC = { @@ -32,9 +34,35 @@ function TheOnlyCure.InitTheOnlyCure(_, player) is_other_bodypart_infected = false }, Prosthesis = { - WoodenHook = {}, - MetalHook = {}, - MetalHand = {} + WoodenHook = { + Right_Hand = {}, + Right_LowerArm = {}, + Right_UpperArm = {}, + + Left_Hand = {}, + Left_LowerArm = {}, + Left_UpperArm = {}, + }, + MetalHook = { + Right_Hand = {}, + Right_LowerArm = {}, + Right_UpperArm = {}, + + Left_Hand = {}, + Left_LowerArm = {}, + Left_UpperArm = {}, + }, + MetalHand = { + Right_Hand = {}, + Right_LowerArm = {}, + Right_UpperArm = {}, + + Left_Hand = {}, + Left_LowerArm = {}, + Left_UpperArm = {}, + }, + Accepted_Prosthesis = {} + }, Generic = {}, } @@ -97,7 +125,7 @@ function TheOnlyCure.InitTheOnlyCure(_, player) mod_data.TOC.Limbs[part_name].depends_on = {} - mod_data.TOC.Prosthesis.AcceptedProsthesis[part_name] = accepted_prosthesis_hand + mod_data.TOC.Prosthesis.Accepted_Prosthesis[part_name] = accepted_prosthesis_hand mod_data.TOC.Prosthesis["WoodenHook"][part_name].prosthesis_factor = 1.5 mod_data.TOC.Prosthesis["MetalHook"][part_name].prosthesis_factor = 1.3 mod_data.TOC.Prosthesis["MetalHand"][part_name].prosthesis_factor = 1.1 @@ -106,7 +134,7 @@ function TheOnlyCure.InitTheOnlyCure(_, player) elseif limb == "LowerArm" then mod_data.TOC.Limbs[part_name].cicatrization_base_time = 1800 mod_data.TOC.Limbs[part_name].depends_on = {side .. "_Hand",} - mod_data.TOC.Prosthesis.AcceptedProsthesis[part_name] = accepted_prosthesis_lowerarm + mod_data.TOC.Prosthesis.Accepted_Prosthesis[part_name] = accepted_prosthesis_lowerarm mod_data.TOC.Prosthesis["WoodenHook"][part_name].prosthesis_factor = 1.65 mod_data.TOC.Prosthesis["MetalHook"][part_name].prosthesis_factor = 1.45 @@ -114,7 +142,7 @@ function TheOnlyCure.InitTheOnlyCure(_, player) elseif limb == "UpperArm" then mod_data.TOC.Limbs[part_name].cicatrization_base_time = 2000 mod_data.TOC.Limbs[part_name].depends_on = {side .. "_Hand", side .. "_LowerArm",} - mod_data.TOC.Prosthesis.AcceptedProsthesis[part_name] = accepted_prosthesis_upperarm + mod_data.TOC.Prosthesis.Accepted_Prosthesis[part_name] = accepted_prosthesis_upperarm end end @@ -146,6 +174,9 @@ function TheOnlyCure.InitTheOnlyCure(_, player) mod_data.TOC.Left_UpperArm.is_cicatrized = true end + else + TheOnlyCure.CheckCompatibilityWithOlderVersions(mod_data) + end end @@ -166,7 +197,21 @@ function TheOnlyCure.DeclareTraits() TraitFactory.setMutualExclusive("Amputee_LowerArm", "Amputee_UpperArm") end +function TheOnlyCure.CheckCompatibilityWithOlderVersions(mod_data) + -- Gets the old status and turns it into the new. + if mod_data.TOC.Limbs == nil then + print("TOC: Limbs is nil, resetting mod_data") + ResetEverything() + + elseif mod_data.TOC.Limbs.Right_Hand.is_cut == nil then + print("TOC: Couldn't recreate all, some stuff is still nil") + ResetEverything() + else + print("TOC: Found compatible data") + end + +end ----------------------------------------------------------------------- function TheOnlyCure.CutLimb(part_name, surgeon_factor, bandage_table, painkiller_table) diff --git a/media/lua/client/TimedActions/ISInstallProsthesis.lua b/media/lua/client/TimedActions/ISInstallProsthesis.lua index bc93fbf..f481017 100644 --- a/media/lua/client/TimedActions/ISInstallProsthesis.lua +++ b/media/lua/client/TimedActions/ISInstallProsthesis.lua @@ -40,7 +40,7 @@ function ISInstallProsthesis:perform() return end - local prosthesis_name =TocFindCorrectClothingProsthesis(prosthesis_base_name, part_name) + local prosthesis_name = TocFindCorrectClothingProsthesis(prosthesis_base_name, part_name) self.cloth = self.character:getInventory():AddItem(prosthesis_name) if self.cloth ~= nil then diff --git a/media/lua/client/Utils/UsefulFunctions.lua b/media/lua/client/Utils/UsefulFunctions.lua index 1206dd3..a88ecc2 100644 --- a/media/lua/client/Utils/UsefulFunctions.lua +++ b/media/lua/client/Utils/UsefulFunctions.lua @@ -156,7 +156,7 @@ end function TocFindCorrectClothingProsthesis(item_name, part_name) - local correct_name = "TOC." .. item_name .. "_" .. part_name + local correct_name = "TOC.Prost_" .. part_name .. "_" .. item_name return correct_name end \ No newline at end of file