diff --git a/media/lua/client/TOC_Client.lua b/media/lua/client/TOC_Client.lua index ad59ca0..a77ae5e 100644 --- a/media/lua/client/TOC_Client.lua +++ b/media/lua/client/TOC_Client.lua @@ -112,19 +112,19 @@ Commands["CanResetEverything"] = function(arg) arg["command"] = "ResponseCanAct" arg["toSend"] = {part_name, "Cut", true} sendClientCommand("TOC", "SendServer", arg) - --ResetEverything() + --TocResetEverything() end Commands["ResetEverything"] = function(arg) local arg = arg["toSend"] - ResetEverything() + TocResetEverything() end -- Cheating stuff Commands["AcceptResetEverything"] = function(arg) local clicked_player = getPlayerByOnlineID(arg[1]) -- TODO delete this - ResetEverything() + TocResetEverything() end diff --git a/media/lua/client/TOC_Compatibility.lua b/media/lua/client/TOC_Compatibility.lua new file mode 100644 index 0000000..4a31354 --- /dev/null +++ b/media/lua/client/TOC_Compatibility.lua @@ -0,0 +1,86 @@ +function TocCheckCompatibilityWithOlderVersions(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") + TocMapOldDataToNew(mod_data) + else + print("TOC: Found compatible data") + end + +end + + + +function TocMapOldDataToNew(mod_data) + + local map_names = { + Right_Hand = "RightHand", + Right_LowerArm = "RightForearm", + Right_UpperArm = "RightArm", + + Left_Hand = "LeftHand", + Left_LowerArm = "LeftForearm", + Left_UpperArm = "LeftArm" + } + + local old_names_table = {"RightHand", "RightForearm", "RightArm", "LeftHand", "LeftForearm", "LeftArm"} + local new_names_table = {"Right_Hand", "Right_LowerArm", "Right_UpperArm", "Left_Hand", "Left_LowerArm", "Left_UpperArm"} + print("TOC: Trying to backup old data") + local backup_old_data = mod_data.TOC + + + + -- for k, v in pairs(map_names) do + -- print("TOC: Looping old names...") + -- print(k) + -- print(v) + -- print(backup_old_data[v].is_cut) + -- print("__________________") + -- end + + + + -- for _, v in ipairs(map_names) do + -- print("TOC: Looping old names...") + -- print(k) + -- print(v) + -- print(backup_old_data[v].is_cut) + -- print("__________________") + -- end + + + + + TocResetEverything() + -- For some reasons pairs does not work here... + -- TODO ask why + for i=1, #new_names_table do + print("TOC: Looping " .. i) + print(backup_old_data[old_names_table[i]].is_cut) + + local old_name = old_names_table[i] + local new_name = new_names_table[i] + + mod_data.TOC.Limbs[new_name].is_cut = backup_old_data[old_name].is_cut + + if mod_data.TOC.Limbs[new_name].is_cut then + local cloth = getPlayer():getInventory():AddItem(TocFindAmputatedClothingFromPartName(new_name)) + getPlayer():setWornItem(cloth:getBodyLocation(), cloth) + end + + + mod_data.TOC.Limbs[new_name].is_infected = backup_old_data[old_name].is_infected + mod_data.TOC.Limbs[new_name].is_operated = backup_old_data[old_name].is_operated + mod_data.TOC.Limbs[new_name].is_cicatrized = backup_old_data[old_name].is_cicatrized + mod_data.TOC.Limbs[new_name].is_cauterized = backup_old_data[old_name].is_cauterized + mod_data.TOC.Limbs[new_name].is_amputation_shown = backup_old_data[old_name].is_amputation_shown + + mod_data.TOC.Limbs[new_name].cicatrization_time = backup_old_data[old_name].cicatrization_time + + + end + getPlayer():transmitModData() + + +end \ No newline at end of file diff --git a/media/lua/client/TOC_ContextMenus.lua b/media/lua/client/TOC_ContextMenus.lua index 0870d6e..931e909 100644 --- a/media/lua/client/TOC_ContextMenus.lua +++ b/media/lua/client/TOC_ContextMenus.lua @@ -158,7 +158,7 @@ TocContextMenus.CreateCheatMenu = function(context, root_menu, local_player, cli local cheat_menu = TocContextMenus.CreateNewMenu("Cheat", context, root_menu) if clicked_player == local_player then - cheat_menu:addOption("Reset TOC for me", _, ResetEverything) + cheat_menu:addOption("Reset TOC for me", _, TocResetEverything) else cheat_menu:addOption("Reset TOC for " .. clicked_player:getUsername(), _, TryToToResetEverythingOtherPlayer, clicked_player, local_player) diff --git a/media/lua/client/TOC_Debug.lua b/media/lua/client/TOC_Debug.lua index fad42cd..ecd1d32 100644 --- a/media/lua/client/TOC_Debug.lua +++ b/media/lua/client/TOC_Debug.lua @@ -1,4 +1,4 @@ -function ResetEverything() +function TocResetEverything() local player = getPlayer() local mod_data = player:getModData() diff --git a/media/lua/client/TimedActions/OverridenFunctions.lua b/media/lua/client/TOC_OverridenFunctions.lua similarity index 100% rename from media/lua/client/TimedActions/OverridenFunctions.lua rename to media/lua/client/TOC_OverridenFunctions.lua diff --git a/media/lua/client/TOC_main.lua b/media/lua/client/TOC_main.lua index 568edfe..16a89a9 100644 --- a/media/lua/client/TOC_main.lua +++ b/media/lua/client/TOC_main.lua @@ -17,13 +17,31 @@ function TheOnlyCure.InitTheOnlyCure(_, player) -- TODO if mod_data.TOC == nil then + TocSetInitData(mod_data, player) + else + TocCheckCompatibilityWithOlderVersions(mod_data) + end +end - print("TOC: Creating mod_data.TOC") - - mod_data.TOC = { - - Limbs = { +function TocSetInitData(mod_data, player) + + print("TOC: Creating mod_data.TOC") + + mod_data.TOC = { + + Limbs = { + Right_Hand = {}, + Right_LowerArm = {}, + Right_UpperArm = {}, + + Left_Hand = {}, + Left_LowerArm = {}, + Left_UpperArm = {}, + is_other_bodypart_infected = false + }, + Prosthesis = { + WoodenHook = { Right_Hand = {}, Right_LowerArm = {}, Right_UpperArm = {}, @@ -31,156 +49,144 @@ function TheOnlyCure.InitTheOnlyCure(_, player) Left_Hand = {}, Left_LowerArm = {}, Left_UpperArm = {}, - is_other_bodypart_infected = false }, - Prosthesis = { - 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 = {} + MetalHook = { + Right_Hand = {}, + Right_LowerArm = {}, + Right_UpperArm = {}, + Left_Hand = {}, + Left_LowerArm = {}, + Left_UpperArm = {}, }, - Generic = {}, - } - -------- - -- NEW NAMING SCHEME - - ---- Amputations - - -- Amputation_Left_Hand - -- Amputation_Right_UpperArm - - - ---- Prosthesis to equip - -- Prost_Left_Hand_MetalHook - -- Prost_Right_Forearm_WoodenHook - - --- Objects - -- Prost_Object_WoddenHook - - - local sides = {"Left", "Right"} - local limbs = {"Hand", "LowerArm", "UpperArm"} -- Let's follow their naming - - - local prosthesis_list = {"WoodenHook", "MetalHook", "MetalHand"} - - - - local accepted_prosthesis_hand = {"WoodenHook", "MetalHook", "MetalHand"} - local accepted_prosthesis_lowerarm = {"WoodenHook", "MetalHook", "MetalHand"} - local accepted_prosthesis_upperarm = {} -- For future stuff - - - - - - for _, side in ipairs(sides) do - for _, limb in ipairs(limbs) do - - local part_name = side .. "_" .. limb - - mod_data.TOC.Limbs[part_name].is_cut = false - mod_data.TOC.Limbs[part_name].is_infected = false - mod_data.TOC.Limbs[part_name].is_operated = false - mod_data.TOC.Limbs[part_name].is_cicatrized = false - mod_data.TOC.Limbs[part_name].is_cauterized = false - mod_data.TOC.Limbs[part_name].is_amputation_shown = false - - mod_data.TOC.Limbs[part_name].cicatrization_time = 0 - - - mod_data.TOC.Limbs[part_name].is_prosthesis_equipped = false - mod_data.TOC.Limbs[part_name].equipped_prosthesis = {} + MetalHand = { + Right_Hand = {}, + Right_LowerArm = {}, + Right_UpperArm = {}, - -- Even if there are some duplicates, this is just easier in the end since we're gonna get fairly easily part_name - - - if limb == "Hand" then - mod_data.TOC.Limbs[part_name].cicatrization_base_time = 1700 - mod_data.TOC.Limbs[part_name].depends_on = {} + Left_Hand = {}, + Left_LowerArm = {}, + Left_UpperArm = {}, + }, + Accepted_Prosthesis = {} + + }, + Generic = {}, + } + -------- + -- NEW NAMING SCHEME + + ---- Amputations + + -- Amputation_Left_Hand + -- Amputation_Right_UpperArm - 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 + ---- Prosthesis to equip + -- Prost_Left_Hand_MetalHook + -- Prost_Right_Forearm_WoodenHook + + --- Objects + -- Prost_Object_WoddenHook + + + local sides = {"Left", "Right"} + local limbs = {"Hand", "LowerArm", "UpperArm"} -- Let's follow their naming + + + local prosthesis_list = {"WoodenHook", "MetalHook", "MetalHand"} + + + + local accepted_prosthesis_hand = {"WoodenHook", "MetalHook", "MetalHand"} + local accepted_prosthesis_lowerarm = {"WoodenHook", "MetalHook", "MetalHand"} + local accepted_prosthesis_upperarm = {} -- For future stuff + + + + + + for _, side in ipairs(sides) do + for _, limb in ipairs(limbs) do + + local part_name = side .. "_" .. limb + + mod_data.TOC.Limbs[part_name].is_cut = false + mod_data.TOC.Limbs[part_name].is_infected = false + mod_data.TOC.Limbs[part_name].is_operated = false + mod_data.TOC.Limbs[part_name].is_cicatrized = false + mod_data.TOC.Limbs[part_name].is_cauterized = false + mod_data.TOC.Limbs[part_name].is_amputation_shown = false - - 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.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 - mod_data.TOC.Prosthesis["MetalHand"][part_name].prosthesis_factor = 1.25 - 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.Accepted_Prosthesis[part_name] = accepted_prosthesis_upperarm - end - + mod_data.TOC.Limbs[part_name].cicatrization_time = 0 + + + mod_data.TOC.Limbs[part_name].is_prosthesis_equipped = false + mod_data.TOC.Limbs[part_name].equipped_prosthesis = {} + + -- Even if there are some duplicates, this is just easier in the end since we're gonna get fairly easily part_name + + + if limb == "Hand" then + mod_data.TOC.Limbs[part_name].cicatrization_base_time = 1700 + mod_data.TOC.Limbs[part_name].depends_on = {} + + + 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 + + + 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.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 + mod_data.TOC.Prosthesis["MetalHand"][part_name].prosthesis_factor = 1.25 + 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.Accepted_Prosthesis[part_name] = accepted_prosthesis_upperarm end end - - -- Setup traits - if player:HasTrait("Amputee_Hand") then - - -- TODO override AddItem so we can change the texture dynamically based on skin color - local amputation_clothing = player:getInventory():AddItem("TOC.Amputation_Left_Hand") - player:setWornItem(amputation_clothing:getBodyLocation(), amputation_clothing) - mod_data.TOC.Left_Hand.is_cut = true - mod_data.TOC.Left_Hand.is_operated = true - mod_data.TOC.Left_Hand.is_amputation_shown = true - mod_data.TOC.Left_Hand.is_cicatrized = true - elseif player:HasTrait("Amputee_LowerArm") then - local amputation_clothing = player:getInventory():AddItem("TOC.Amputation_Left_LowerArm") - player:setWornItem(amputation_clothing:getBodyLocation(), amputation_clothing) - mod_data.TOC.Left_LowerArm.is_cut = true - mod_data.TOC.Left_LowerArm.is_operated = true - mod_data.TOC.Left_LowerArm.is_amputation_shown = true - mod_data.TOC.Left_LowerArm.is_cicatrized = true - elseif player:HasTrait("Amputee_UpperArm") then - local amputation_clothing = player:getInventory():AddItem("TOC.Amputation_Left_UpperArm") - player:setWornItem(amputation_clothing:getBodyLocation(), amputation_clothing) - mod_data.TOC.Left_UpperArm.is_cut = true - mod_data.TOC.Left_UpperArm.is_operated = true - mod_data.TOC.Left_UpperArm.is_amputation_shown = true - mod_data.TOC.Left_UpperArm.is_cicatrized = true - end - - else - TheOnlyCure.CheckCompatibilityWithOlderVersions(mod_data) - end + -- Setup traits + if player:HasTrait("Amputee_Hand") then + + -- TODO override AddItem so we can change the texture dynamically based on skin color + local amputation_clothing = player:getInventory():AddItem("TOC.Amputation_Left_Hand") + player:setWornItem(amputation_clothing:getBodyLocation(), amputation_clothing) + mod_data.TOC.Left_Hand.is_cut = true + mod_data.TOC.Left_Hand.is_operated = true + mod_data.TOC.Left_Hand.is_amputation_shown = true + mod_data.TOC.Left_Hand.is_cicatrized = true + elseif player:HasTrait("Amputee_LowerArm") then + local amputation_clothing = player:getInventory():AddItem("TOC.Amputation_Left_LowerArm") + player:setWornItem(amputation_clothing:getBodyLocation(), amputation_clothing) + mod_data.TOC.Left_LowerArm.is_cut = true + mod_data.TOC.Left_LowerArm.is_operated = true + mod_data.TOC.Left_LowerArm.is_amputation_shown = true + mod_data.TOC.Left_LowerArm.is_cicatrized = true + elseif player:HasTrait("Amputee_UpperArm") then + local amputation_clothing = player:getInventory():AddItem("TOC.Amputation_Left_UpperArm") + player:setWornItem(amputation_clothing:getBodyLocation(), amputation_clothing) + mod_data.TOC.Left_UpperArm.is_cut = true + mod_data.TOC.Left_UpperArm.is_operated = true + mod_data.TOC.Left_UpperArm.is_amputation_shown = true + mod_data.TOC.Left_UpperArm.is_cicatrized = true + end + + + + end + + function TheOnlyCure.DeclareTraits() local amp1 = TraitFactory.addTrait("Amputee_Hand", getText("UI_trait_Amputee_Hand"), -8, getText("UI_trait_Amputee_Hand_desc"), false, false) amp1:addXPBoost(Perks.Left_Hand, 4) @@ -197,21 +203,6 @@ 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)