From c4529d089084c84038284d31283e851421f55c83 Mon Sep 17 00:00:00 2001 From: ZioPao Date: Mon, 22 Apr 2024 18:09:04 +0200 Subject: [PATCH] Fixed items floating --- media/lua/client/TOC/CommonMethods.lua | 13 ++++++ .../Controllers/LimitActionsController.lua | 40 +++++++++++++++++++ .../TOC/Controllers/LocalPlayerController.lua | 33 ++++++++++----- media/lua/shared/TOC/StaticData.lua | 34 ++++++++++++++++ 4 files changed, 109 insertions(+), 11 deletions(-) diff --git a/media/lua/client/TOC/CommonMethods.lua b/media/lua/client/TOC/CommonMethods.lua index 03c5b57..5c96a80 100644 --- a/media/lua/client/TOC/CommonMethods.lua +++ b/media/lua/client/TOC/CommonMethods.lua @@ -24,6 +24,19 @@ function CommonMethods.GetSide(name) if string.find(name, "_L") then return "L" else return "R" end end +---Returns full name for the side, to be used with BodyLocations +---@param side string +---@return string +function CommonMethods.GetSideFull(side) + if side == 'R' then + return "Right" + elseif side == 'L' then + return 'Left' + end + + return nil +end + ---Stops and start an event, making sure that we don't stack them up ---@param event string ---@param method function diff --git a/media/lua/client/TOC/Controllers/LimitActionsController.lua b/media/lua/client/TOC/Controllers/LimitActionsController.lua index 63df387..52c5479 100644 --- a/media/lua/client/TOC/Controllers/LimitActionsController.lua +++ b/media/lua/client/TOC/Controllers/LimitActionsController.lua @@ -263,3 +263,43 @@ function ISWorldObjectContextMenu.createMenu(player, worldobjects, x, y, test) end +--* DISABLE WEARING CERTAIN ITEMS WHEN NO LIMB + +local function CheckLimbFeasibility(limbName) + local dcInst = DataController.GetInstance() + local isFeasible = not dcInst:getIsCut(limbName) or dcInst:getIsProstEquipped(limbName) + TOC_DEBUG.print("isFeasible="..tostring(isFeasible)) + return isFeasible +end + + +---@diagnostic disable-next-line: duplicate-set-field +local og_ISWearClothing_isValid = ISWearClothing.isValid +function ISWearClothing:isValid() + local isEquippable = og_ISWearClothing_isValid(self) + if not isEquippable then return isEquippable end + + ---@type Item + local item = self.item + local itemBodyLoc = item:getBodyLocation() + + local limbToCheck = StaticData.AFFECTED_BODYLOCS_TO_LIMBS_IND_STR[itemBodyLoc] + if CheckLimbFeasibility(limbToCheck) then return isEquippable else return false end +end + +local og_ISClothingExtraAction_isValid = ISClothingExtraAction.isValid +---@diagnostic disable-next-line: duplicate-set-field +function ISClothingExtraAction:isValid() + local isEquippable = og_ISClothingExtraAction_isValid(self) + if not isEquippable then return isEquippable end + + + TOC_DEBUG.print("Checking if we can equip item") + -- self.extra is a string, not the item + local testItem = InventoryItemFactory.CreateItem(self.extra) + local itemBodyLoc = testItem:getBodyLocation() + + local limbToCheck = StaticData.AFFECTED_BODYLOCS_TO_LIMBS_IND_STR[itemBodyLoc] + TOC_DEBUG.print("Limb to check: " .. tostring(limbToCheck)) + if CheckLimbFeasibility(limbToCheck) then return isEquippable else return false end +end \ No newline at end of file diff --git a/media/lua/client/TOC/Controllers/LocalPlayerController.lua b/media/lua/client/TOC/Controllers/LocalPlayerController.lua index fb4aa39..4816021 100644 --- a/media/lua/client/TOC/Controllers/LocalPlayerController.lua +++ b/media/lua/client/TOC/Controllers/LocalPlayerController.lua @@ -325,24 +325,35 @@ Events.OnPuttingTourniquet.Add(LocalPlayerController.HandleTourniquet) --* Object drop handling when amputation occurs ---- Drop all items from the affected limb ----@param limbName string -function LocalPlayerController.DropItemsAfterAmputation(limbName) - -- TODO Check for watches and stuff like that - TOC_DEBUG.print("Triggered DropItemsAfterAmputation") +function LocalPlayerController.CanItemBeEquipped(itemObj, limbName) + local bl = itemObj:getBodyLocation() local side = CommonMethods.GetSide(limbName) - local sideStr + local sideStr = CommonMethods.GetSideFull(side) - if side == 'R' then - sideStr = "Right" - else - sideStr = 'Left' + -- TODO Check from DataController + + if string.contains(limbName, "Hand_") and (bl == sideStr .. "_MiddleFinger" or bl == sideStr .. "_RingFinger") then + return false end - local pl = getPlayer() + if string.contains(limbName, "ForeArm_") and (bl == sideStr .. "Wrist") then + return false + end + return true +end + + +--- Drop all items from the affected limb +---@param limbName string +function LocalPlayerController.DropItemsAfterAmputation(limbName) + TOC_DEBUG.print("Triggered DropItemsAfterAmputation") + local side = CommonMethods.GetSide(limbName) + local sideStr = CommonMethods.GetSideFull(side) + + local pl = getPlayer() local wornItems = pl:getWornItems() for i = 1, wornItems:size() do diff --git a/media/lua/shared/TOC/StaticData.lua b/media/lua/shared/TOC/StaticData.lua index e20735c..14c4349 100644 --- a/media/lua/shared/TOC/StaticData.lua +++ b/media/lua/shared/TOC/StaticData.lua @@ -178,6 +178,40 @@ StaticData.TOURNIQUET_BODYLOCS_TO_GROUPS_IND_STR = { } +StaticData.AFFECTED_BODYLOCS_TO_LIMBS_IND_STR = {} + +local handsBodyLocs = {"Hands%s", "%s_MiddleFinger", "%s_RingFinger"} +local foreArmBodyLocs = {"%sWrist"} + + + +for side, _ in pairs(StaticData.SIDES_IND_STR) do + for part, _ in pairs(StaticData.PARTS_IND_STR) do + local limbName = part .. "_" .. side + + local sideFull + if side == 'R' then sideFull = "Right" else sideFull = "Left" end + + if part == "Hand" then + for i=1, #handsBodyLocs do + local bl = string.format(handsBodyLocs[i], sideFull) + StaticData.AFFECTED_BODYLOCS_TO_LIMBS_IND_STR[bl] = limbName + end + elseif part == "ForeArm" then + -- -- UGLY very ugly + -- for i=1, #handsBodyLocs do + -- local bl = string.format(handsBodyLocs[i], sideFull) + -- StaticData.AFFECTED_BODYLOCS_TO_LIMBS_IND_STR[bl] = limbName + -- end + for i=1, #foreArmBodyLocs do + local bl = string.format(foreArmBodyLocs[i], sideFull) + StaticData.AFFECTED_BODYLOCS_TO_LIMBS_IND_STR[bl] = limbName + end + + end + + end +end