From 3fb22a9b1e9ec0ddfdfc8c8285dfa5439647baad Mon Sep 17 00:00:00 2001 From: ZioPao Date: Thu, 21 Mar 2024 03:02:52 +0100 Subject: [PATCH] Fixed equipping prosthesis on upper arms --- .../Controllers/LimitActionsController.lua | 32 ++++++- .../client/TOC/Handlers/CachedDataHandler.lua | 2 +- .../client/TOC/Handlers/ProsthesisHandler.lua | 83 +++++++++---------- 3 files changed, 71 insertions(+), 46 deletions(-) diff --git a/media/lua/client/TOC/Controllers/LimitActionsController.lua b/media/lua/client/TOC/Controllers/LimitActionsController.lua index 8219f8a..03d443b 100644 --- a/media/lua/client/TOC/Controllers/LimitActionsController.lua +++ b/media/lua/client/TOC/Controllers/LimitActionsController.lua @@ -228,4 +228,34 @@ function ISInventoryPaneContextMenu.doEquipOption(context, playerObj, isWeapon, end --- TODO IMPORTANT!!!! ADD LIMIT FOR UPPER ARM AND WHEN YOU DON'T HAVE AMPUTATIONS FOR PROSTHETITCS \ No newline at end of file +-- local og_ISInventoryPaneContextMenu_doClothingItemExtraMenu = ISInventoryPaneContextMenu.doClothingItemExtraMenu + +-- ---@param context ISContextMenu +-- ---@param clothingItemExtra any +-- ---@param playerObj IsoPlayer +-- function ISInventoryPaneContextMenu.doClothingItemExtraMenu(context, clothingItemExtra, playerObj) +-- og_ISInventoryPaneContextMenu_doClothingItemExtraMenu(context, clothingItemExtra, playerObj) + +-- -- local dc = DataController.GetInstance(playerObj:getUsername()) +-- -- local text = getText("ContextMenu_InstallProstRight") +-- -- local rightOpt = context:getOptionFromName(text) + +-- -- if rightOpt then +-- -- -- check if can be equipped +-- -- rightOpt.notAvailable = dc:getIsAnyLimbCut() and not dc:getIsCut("UpperArm_R") +-- -- end + + +-- -- text = getText("ContextMenu_InstallProstLeft") +-- -- local leftOpt = context:getOptionFromName(text) + +-- -- if leftOpt then +-- -- leftOpt.notAvailable = dc:getIsAnyLimbCut() and not dc:getIsCut("UpperArm_L") +-- -- end + + + + +-- -- Check if in context there are the options for the prosts +-- end +-- -- TODO IMPORTANT!!!! ADD LIMIT FOR UPPER ARM AND WHEN YOU DON'T HAVE AMPUTATIONS FOR PROSTHETITCSmhh \ No newline at end of file diff --git a/media/lua/client/TOC/Handlers/CachedDataHandler.lua b/media/lua/client/TOC/Handlers/CachedDataHandler.lua index 5a34487..b26f774 100644 --- a/media/lua/client/TOC/Handlers/CachedDataHandler.lua +++ b/media/lua/client/TOC/Handlers/CachedDataHandler.lua @@ -96,7 +96,7 @@ end ---Get the cached highest point of amputation for each side ---@param username string ----@return table +---@return table function CachedDataHandler.GetHighestAmputatedLimbs(username) return CachedDataHandler.highestAmputatedLimbs[username] end diff --git a/media/lua/client/TOC/Handlers/ProsthesisHandler.lua b/media/lua/client/TOC/Handlers/ProsthesisHandler.lua index c5525dd..dd50564 100644 --- a/media/lua/client/TOC/Handlers/ProsthesisHandler.lua +++ b/media/lua/client/TOC/Handlers/ProsthesisHandler.lua @@ -14,7 +14,12 @@ local bodyLocArmProst = StaticData.MOD_BODYLOCS_BASE_IND_STR.TOC_ArmProst ---@return boolean function ProsthesisHandler.CheckIfProst(item) -- TODO Won't be correct when prost for legs are gonna be in - if item == nil then return false end + TOC_DEBUG.print("Checking if item is prost") + if item == nil then + TOC_DEBUG.print("Not prost") + + return false + end return item:getBodyLocation():contains(bodyLocArmProst) end @@ -30,18 +35,19 @@ function ProsthesisHandler.GetGroup(item) end ---Check if a prosthesis is equippable. It depends whether the player has a cut limb or not on that specific side. There's an exception for Upper arm, obviously ----@param bodyLocation string +---@param name string ---@return boolean -function ProsthesisHandler.CheckIfEquippable(bodyLocation) +function ProsthesisHandler.CheckIfEquippable(name) TOC_DEBUG.print("Current item is a prosthesis") - local side = CommonMethods.GetSide(bodyLocation) + local side = CommonMethods.GetSide(name) TOC_DEBUG.print("Checking side: " .. tostring(side)) - local amputatedLimbs = CachedDataHandler.GetAmputatedLimbs(getPlayer():getUsername()) - for k, _ in pairs(amputatedLimbs) do - local limbName = k - if string.contains(limbName, side) and not string.contains(limbName, "UpperArm") then - TOC_DEBUG.print("Found acceptable limb to use prosthesis") + local highestAmputatedLimbs = CachedDataHandler.GetHighestAmputatedLimbs(getPlayer():getUsername()) + + if highestAmputatedLimbs then + local hal = highestAmputatedLimbs[side] + if not string.contains(hal, "UpperArm") then + TOC_DEBUG.print("Found acceptable limb to use prosthesis => " .. tostring(hal)) return true end end @@ -58,7 +64,7 @@ function ProsthesisHandler.SearchAndSetupProsthesis(item, isEquipping) if not ProsthesisHandler.CheckIfProst(item) then return end local group = ProsthesisHandler.GetGroup(item) - TOC_DEBUG.print("Applying prosthesis stuff for " .. group) + TOC_DEBUG.print("Setup Prosthesis => " .. group .. " - is equipping? " .. tostring(isEquipping)) local dcInst = DataController.GetInstance() dcInst:setIsProstEquipped(group, isEquipping) dcInst:apply() @@ -68,23 +74,32 @@ end --* Overrides *-- +---@param item InventoryItem +---@param isEquippable boolean +---@return unknown +local function HandleProsthesisValidation(item, isEquippable) + local isProst = ProsthesisHandler.CheckIfProst(item) + if not isProst then return isEquippable end + + local itemName = item:getName() -- use name for side + if isEquippable then + isEquippable = ProsthesisHandler.CheckIfEquippable(itemName) + end + + + if not isEquippable then + getPlayer():Say(getText("UI_Say_CantEquip")) + end + + return isEquippable +end + + ---@diagnostic disable-next-line: duplicate-set-field local og_ISWearClothing_isValid = ISWearClothing.isValid function ISWearClothing:isValid() local isEquippable = og_ISWearClothing_isValid(self) - - -- TODO Do we actually need this? - local isProst = ProsthesisHandler.CheckIfProst(self.item) - - if not isProst then return isEquippable end - - --the item that we gets is the OG one, so if we're coming from the left one and wanna switch to the right one we're still gonna get the Left bodylocation - local bodyLocation = self.item:getBodyLocation() - if isEquippable and string.contains(bodyLocation, bodyLocArmProst) then - isEquippable = ProsthesisHandler.CheckIfEquippable(bodyLocation) - end - - return isEquippable + return HandleProsthesisValidation(self.item, isEquippable) end local og_ISWearClothing_perform = ISWearClothing.perform @@ -97,27 +112,7 @@ local og_ISClothingExtraAction_isValid = ISClothingExtraAction.isValid ---@diagnostic disable-next-line: duplicate-set-field function ISClothingExtraAction:isValid() local isEquippable = og_ISClothingExtraAction_isValid(self) - - --the item that we gets is the OG one, so if we're coming from the left one and wanna switch to the right one we're still gonna get the Left bodylocation - local testItem = InventoryItemFactory.CreateItem(self.extra) - local isProst = ProsthesisHandler.CheckIfProst(testItem) - - -- Early exit if it's not a prostheesis - if not isProst then return isEquippable end - - if isEquippable and isProst then - local bodyLocation = testItem:getBodyLocation() - isEquippable = ProsthesisHandler.CheckIfEquippable(bodyLocation) - - -- Just to let the player know - if not isEquippable then - -- TODO if its in here then it's gonna run at least 2 times - getPlayer():Say(getText("UI_Say_CantEquip")) - end - - end - - return isEquippable + return HandleProsthesisValidation(self.item, isEquippable) end local og_ISClothingExtraAction_perform = ISClothingExtraAction.perform