From 35ef646402cf619095e49a88201b1f56f670f21e Mon Sep 17 00:00:00 2001 From: ZioPao Date: Thu, 21 Mar 2024 22:56:10 +0100 Subject: [PATCH] Fixed various problems with prosts --- .../Controllers/LimitActionsController.lua | 3 - .../client/TOC/Handlers/ProsthesisHandler.lua | 59 +++++++++++++++---- .../lua/server/TOC/LimitActionsController.lua | 3 +- media/lua/shared/TOC/StaticData.lua | 1 + 4 files changed, 48 insertions(+), 18 deletions(-) diff --git a/media/lua/client/TOC/Controllers/LimitActionsController.lua b/media/lua/client/TOC/Controllers/LimitActionsController.lua index 65e4ac6..63df387 100644 --- a/media/lua/client/TOC/Controllers/LimitActionsController.lua +++ b/media/lua/client/TOC/Controllers/LimitActionsController.lua @@ -86,9 +86,6 @@ end ---@class ISEquipWeaponAction ---@field character IsoPlayer -local primaryHand = StaticData.PARTS_IND_STR.Hand .. "_" .. StaticData.SIDES_IND_STR.R -local secondaryHand = StaticData.PARTS_IND_STR.Hand .. "_" .. StaticData.SIDES_IND_STR.L - --* Equipping items overrides *-- local og_ISEquipWeaponAction_isValid = ISEquipWeaponAction.isValid ---Add a condition to check the feasibility of having 2 handed weapons or if both arms are cut off diff --git a/media/lua/client/TOC/Handlers/ProsthesisHandler.lua b/media/lua/client/TOC/Handlers/ProsthesisHandler.lua index 46c16bc..6ef5b5b 100644 --- a/media/lua/client/TOC/Handlers/ProsthesisHandler.lua +++ b/media/lua/client/TOC/Handlers/ProsthesisHandler.lua @@ -8,15 +8,16 @@ local CachedDataHandler = require("TOC/Handlers/CachedDataHandler") local ProsthesisHandler = {} local bodyLocArmProst = StaticData.MOD_BODYLOCS_BASE_IND_STR.TOC_ArmProst +local bodyLocLegProst = StaticData.MOD_BODYLOCS_BASE_IND_STR.TOC_LegProst ---Check if the following item is a prosthesis or not ---@param item InventoryItem? ---@return boolean function ProsthesisHandler.CheckIfProst(item) -- TODO Won't be correct when prost for legs are gonna be in - TOC_DEBUG.print("Checking if item is prost") + --TOC_DEBUG.print("Checking if item is prost") if item == nil then - TOC_DEBUG.print("Not prost") + --TOC_DEBUG.print("Not prost") return false end @@ -27,9 +28,22 @@ end ---@param item InventoryItem ---@return string function ProsthesisHandler.GetGroup(item) + local fullType = item:getFullType() + local side = CommonMethods.GetSide(fullType) + + local bodyLocation = item:getBodyLocation() - local side = CommonMethods.GetSide(bodyLocation) - local index = bodyLocation:contains(bodyLocArmProst) and "Top_" .. side or "Bottom_" .. side + local position + if bodyLocation == bodyLocArmProst then + position = "Top_" + elseif bodyLocation == bodyLocLegProst then + position = "Bottom_" + else + TOC_DEBUG.print("Something is wrong, no position in this item") + position = nil + end + + local index = position .. side local group = StaticData.PROSTHESES_GROUPS_IND_STR[index] return group end @@ -38,16 +52,16 @@ end ---@param fullType string ---@return boolean function ProsthesisHandler.CheckIfEquippable(fullType) - TOC_DEBUG.print("Current item is a prosthesis") + --TOC_DEBUG.print("Current item is a prosthesis") local side = CommonMethods.GetSide(fullType) - TOC_DEBUG.print("Checking side: " .. tostring(side)) + --TOC_DEBUG.print("Checking side: " .. tostring(side)) local highestAmputatedLimbs = CachedDataHandler.GetHighestAmputatedLimbs(getPlayer():getUsername()) if highestAmputatedLimbs then local hal = highestAmputatedLimbs[side] if hal and not string.contains(hal, "UpperArm") then - TOC_DEBUG.print("Found acceptable limb to use prosthesis => " .. tostring(hal)) + --TOC_DEBUG.print("Found acceptable limb to use prosthesis => " .. tostring(hal)) return true end end @@ -60,8 +74,9 @@ end ---Handle equipping or unequipping prosthetics ---@param item InventoryItem ---@param isEquipping boolean +---@return boolean function ProsthesisHandler.SearchAndSetupProsthesis(item, isEquipping) - if not ProsthesisHandler.CheckIfProst(item) then return end + if not ProsthesisHandler.CheckIfProst(item) then return false end local group = ProsthesisHandler.GetGroup(item) TOC_DEBUG.print("Setup Prosthesis => " .. group .. " - is equipping? " .. tostring(isEquipping)) @@ -71,6 +86,7 @@ function ProsthesisHandler.SearchAndSetupProsthesis(item, isEquipping) -- Calculates hands feasibility once again CachedDataHandler.CalculateBothHandsFeasibility() + return true end ------------------------- @@ -135,18 +151,35 @@ end local og_ISClothingExtraAction_perform = ISClothingExtraAction.perform function ISClothingExtraAction:perform() + --local extraItem = InventoryItemFactory.CreateItem(self.extra) + local isProst = ProsthesisHandler.SearchAndSetupProsthesis(self.item, true) + local group + if isProst then + group = BodyLocations.getGroup("Human") + group:setMultiItem("TOC_ArmProst", false) + end + og_ISClothingExtraAction_perform(self) - ProsthesisHandler.SearchAndSetupProsthesis(self.item, true) + + if isProst then + group:setMultiItem("TOC_ArmProst", true) + end + end local og_ISUnequipAction_perform = ISUnequipAction.perform function ISUnequipAction:perform() - ProsthesisHandler.SearchAndSetupProsthesis(self.item, false) - local group = BodyLocations.getGroup("Human") - group:setMultiItem("TOC_ArmProst", false) + local isProst = ProsthesisHandler.SearchAndSetupProsthesis(self.item, false) + local group + if isProst then + group = BodyLocations.getGroup("Human") + group:setMultiItem("TOC_ArmProst", false) + end og_ISUnequipAction_perform(self) - group:setMultiItem("TOC_ArmProst", true) + if isProst then + group:setMultiItem("TOC_ArmProst", true) + end end diff --git a/media/lua/server/TOC/LimitActionsController.lua b/media/lua/server/TOC/LimitActionsController.lua index a45a90d..aa86f5b 100644 --- a/media/lua/server/TOC/LimitActionsController.lua +++ b/media/lua/server/TOC/LimitActionsController.lua @@ -1,6 +1,5 @@ local CachedDataHandler = require("TOC/Handlers/CachedDataHandler") - - +------------------------------ local og_ISObjectClickHandler_doClickSpecificObject = ISObjectClickHandler.doClickSpecificObject diff --git a/media/lua/shared/TOC/StaticData.lua b/media/lua/shared/TOC/StaticData.lua index 629050c..9156001 100644 --- a/media/lua/shared/TOC/StaticData.lua +++ b/media/lua/shared/TOC/StaticData.lua @@ -43,6 +43,7 @@ StaticData.PARTS_STR = { StaticData.MOD_BODYLOCS_BASE_IND_STR = { TOC_ArmProst = "TOC_ArmProst", + TOC_LegProst = "TOC_LegProst", TOC_Arm = "TOC_Arm", }