From 4d5e20d1fd1d18354fbb23d0c7edf72bded2fc31 Mon Sep 17 00:00:00 2001 From: Pao Date: Sun, 15 Jan 2023 16:25:43 +0100 Subject: [PATCH] Rewrote a bit of ISUninstallProsthesis --- media/lua/client/TOC_GlobalFunctions.lua | 2 + .../TimedActions/ISInstallProsthesis.lua | 112 ++++-------------- .../TimedActions/ISUninstallProsthesis.lua | 5 +- media/lua/client/Utils/UsefulFunctions.lua | 60 ++++++++-- 4 files changed, 74 insertions(+), 105 deletions(-) diff --git a/media/lua/client/TOC_GlobalFunctions.lua b/media/lua/client/TOC_GlobalFunctions.lua index fd98966..8ae3a47 100644 --- a/media/lua/client/TOC_GlobalFunctions.lua +++ b/media/lua/client/TOC_GlobalFunctions.lua @@ -1,5 +1,7 @@ + + function GetKitInInventory(surgeon) local playerInv = surgeon:getInventory(); local item = playerInv:getItemFromType('TOC.Real_surgeon_kit') or playerInv:getItemFromType('TOC.Surgeon_kit') or playerInv:getItemFromType('TOC.Improvised_surgeon_kit') diff --git a/media/lua/client/TimedActions/ISInstallProsthesis.lua b/media/lua/client/TimedActions/ISInstallProsthesis.lua index a396026..b6269eb 100644 --- a/media/lua/client/TimedActions/ISInstallProsthesis.lua +++ b/media/lua/client/TimedActions/ISInstallProsthesis.lua @@ -23,110 +23,38 @@ function ISInstallProsthesis:stop() end function ISInstallProsthesis:perform() + + + + local prosthesis_base_name = self.item:getType() + + + self.item:setJobDelta(0.0) + local toc_data = self.character:getModData().TOC + local part_name = TocGetPartNameFromBodyPartType(self.bodyPart:getType()) - local modData = self.character:getModData() - --local toc_data = self.character:getModData().TOC - local lor = 0 -- LEFT OR RIGHT - local foh = 0 -- FOREARM OR HAND - - -- Check if can be performed. This shouldn't be necessary, but just to be sure if self.bodyPart:getType() == BodyPartType.UpperArm_L or self.bodyPart:getType() == BodyPartType.UpperArm_R then print("Can't equip prosthesis") return end - - local prosthesis_table = { - WoodenHook = { - material_id = 1 - }, - MetalHook = { - material_id = 2 - }, - MetalHand = { - material_id = 3 - } - } - - - if self.bodyPart:getType() == BodyPartType.Hand_R then lor = 1; foh = 1 - elseif self.bodyPart:getType() == BodyPartType.ForeArm_R then lor = 1; foh = 2 - elseif self.bodyPart:getType() == BodyPartType.Hand_L then lor = 0; foh = 1 - elseif self.bodyPart:getType() == BodyPartType.ForeArm_L then lor = 0; foh = 2 - end - - local mat_id = 0 - local weight = math.floor(self.item:getWeight() * 10 + 0.5) / 10 - - if weight == 1 and foh == 1 then - if lor == 1 then - self.cloth = self.character:getInventory():AddItem("TOC.WoodenHook_right_noHand"); - mat_id = 1; - else - self.cloth = self.character:getInventory():AddItem("TOC.WoodenHook_left_noHand"); - mat_id = 1; - end - elseif weight == 0.5 and foh == 1 then - if lor == 1 then - self.cloth = self.character:getInventory():AddItem("TOC.MetalHook_right_noHand"); - mat_id = 2; - else - self.cloth = self.character:getInventory():AddItem("TOC.MetalHook_left_noHand"); - mat_id = 2; - end - elseif weight == 0.3 and foh == 1 then - if lor == 1 then - self.cloth = self.character:getInventory():AddItem("TOC.MetalHand_right_noHand"); - mat_id = 3; - else - self.cloth = self.character:getInventory():AddItem("TOC.MetalHand_left_noHand"); - mat_id = 3; - end - elseif weight == 1 and foh == 2 then - if lor == 1 then - self.cloth = self.character:getInventory():AddItem("TOC.WoodenHook_right_noForearm"); - mat_id = 1; - else - self.cloth = self.character:getInventory():AddItem("TOC.WoodenHook_left_noForearm"); - mat_id = 1; - end - elseif weight == 0.5 and foh == 2 then - if lor == 1 then - self.cloth = self.character:getInventory():AddItem("TOC.MetalHook_right_noForearm"); - mat_id = 2; - else - self.cloth = self.character:getInventory():AddItem("TOC.MetalHook_left_noForearm"); - mat_id = 2; - end - elseif weight == 0.3 and foh == 2 then - if lor == 1 then - self.cloth = self.character:getInventory():AddItem("TOC.MetalHand_right_noForearm"); - mat_id = 3; - else - self.cloth = self.character:getInventory():AddItem("TOC.MetalHand_left_noForearm"); - mat_id = 3; - end - end + local prosthesis_name =TocFindCorrectClothingProsthesis(self.item:getType(), part_name) + self.cloth = self.character:getInventory():AddItem(prosthesis_name) if self.cloth ~= nil then - if self.bodyPart:getType() == BodyPartType.Hand_R then - modData.TOC.RightHand.is_prosthesis_equipped = true; - modData.TOC.RightHand.prosthesis_factor = find_protheseFact_TOC(self.cloth); - elseif self.bodyPart:getType() == BodyPartType.ForeArm_R then - modData.TOC.RightForearm.is_prosthesis_equipped = true; - modData.TOC.RightForearm.prosthesis_factor = find_protheseFact_TOC(self.cloth); - elseif self.bodyPart:getType() == BodyPartType.Hand_L then - modData.TOC.LeftHand.is_prosthesis_equipped = true; - modData.TOC.LeftHand.prosthesis_factor = find_protheseFact_TOC(self.cloth); - elseif self.bodyPart:getType() == BodyPartType.ForeArm_L then - modData.TOC.LeftForearm.is_prosthesis_equipped = true; - modData.TOC.LeftForearm.prosthesis_factor = find_protheseFact_TOC(self.cloth); + + + if part_name then + toc_data[part_name].is_prosthesis_equipped = true + toc_data[part_name].prosthesis_factor = TocFindProsthesisFactorFromItem(self.cloth) + + self.character:getInventory():Remove(self.item) + self.character:setWornItem(self.cloth:getBodyLocation(), self.cloth) end - self.character:getInventory():Remove(self.item); - self.character:setWornItem(self.cloth:getBodyLocation(), self.cloth); + end self.character:transmitModData() diff --git a/media/lua/client/TimedActions/ISUninstallProsthesis.lua b/media/lua/client/TimedActions/ISUninstallProsthesis.lua index 62814a3..1fc6a93 100644 --- a/media/lua/client/TimedActions/ISUninstallProsthesis.lua +++ b/media/lua/client/TimedActions/ISUninstallProsthesis.lua @@ -57,11 +57,10 @@ function ISUninstallProsthesis:perform() toc_data[part_name].is_prosthesis_equipped = false toc_data[part_name].prosthesis_factor = 1 - local side = string.gsub(part_name, "Hand" or "Forearm", "") + --local side = string.gsub(part_name, "Hand" or "Forearm", "") - local prosthesis_list = {"TOC.WoodenHook", "TOC.MetalHook", "TOC.MetalHand"} - for _, prost_v in ipairs(prosthesis_list) do + for _, prost_v in ipairs(GetProsthesisList()) do local prosthesis_name = string.match(self.item:getName(), prost_v) if prosthesis_name then diff --git a/media/lua/client/Utils/UsefulFunctions.lua b/media/lua/client/Utils/UsefulFunctions.lua index d3854d6..b6ff62d 100644 --- a/media/lua/client/Utils/UsefulFunctions.lua +++ b/media/lua/client/Utils/UsefulFunctions.lua @@ -3,6 +3,11 @@ function GetBodyParts() return bodyparts end +function GetProsthesisList() + return {"TOC.WoodenHook", "TOC.MetalHook", "TOC.MetalHand"} + +end + function GetLimbsBodyPartTypes() return {BodyPartType.Hand_R, BodyPartType.ForeArm_R, BodyPartType.UpperArm_R, @@ -54,7 +59,18 @@ function FindTocItemWorn(part_name, patient) end +function TocGetPartNameFromBodyPartType(body_part) + if body_part == BodyPartType.Hand_R then return "RightHand" + elseif body_part == BodyPartType.ForeArm_R then return "RightForearm" + elseif body_part == BodyPartType.UpperArm_R then return "RightArm" + elseif body_part == BodyPartType.Hand_L then return "LeftHand" + elseif body_part == BodyPartType.ForeArm_L then return "LeftForearm" + elseif body_part == BodyPartType.UpperArm_L then return "LeftArm" + else return nil + end + +end @@ -106,17 +122,8 @@ function TocFindAmputatedClothingFromPartName(part_name) end +function TocFindProsthesisFactorFromItem(item) -function find_protheseID_TOC(item) - local itemType = item:getType() - if string.find(itemType, "WoodenHook") then return 1 - elseif string.find(itemType, "MetalHook") then return 2 - elseif string.find(itemType, "MetalHand") then return 3 - else return 0 - end -end - -function find_protheseFact_TOC(item) local itemType = item:getType() if string.find(itemType, "WoodenHook") and string.find(itemType, "noHand") then return 1.5 elseif string.find(itemType, "WoodenHook") and string.find(itemType, "noForearm") then return 1.65 @@ -125,4 +132,37 @@ function find_protheseFact_TOC(item) elseif string.find(itemType, "MetalHand") and string.find(itemType, "noHand") then return 1.1 elseif string.find(itemType, "MetalHand") and string.find(itemType, "noForearm") then return 1.25 end +end + + +function TocFindCorrectClothingProsthesis(item_name, part_name) + + + -- for _, v in ipairs(GetProsthesisList()) do + -- if string.find(item, v) + + -- end + + local lowered_part_name = string.lower(part_name) + local side = string.match(lowered_part_name, "left") + + if side == nil then + side = "right" + end + + local limb = string.match(part_name, "Hand") + if limb == nil then + limb = "Forearm" + end + + + -- Just to accomodate this horrendous naming scheme, let's have Hand or Forearm again... Jesus dude + -- if limb then + -- limb = limb:gsub("^%l", string.upper) + -- end + + local correct_name = "TOC." .. item_name .. "_" .. side .. "_no" .. limb + + return correct_name + end \ No newline at end of file