From 10f97cffa114ec048a3de58913922887271828eb Mon Sep 17 00:00:00 2001 From: ZioPao Date: Wed, 21 Aug 2024 13:21:09 +0200 Subject: [PATCH] Fixed picking up broken glass with item in off hand --- .../Controllers/LimitActionsController.lua | 33 ++++++++++++++----- .../client/TOC/Handlers/CachedDataHandler.lua | 3 +- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/media/lua/client/TOC/Controllers/LimitActionsController.lua b/media/lua/client/TOC/Controllers/LimitActionsController.lua index 482a7ef..fb1db65 100644 --- a/media/lua/client/TOC/Controllers/LimitActionsController.lua +++ b/media/lua/client/TOC/Controllers/LimitActionsController.lua @@ -74,7 +74,7 @@ function ISBaseTimedAction:perform() if not dcInst:getIsAnyLimbCut() then return end local amputatedLimbs = CachedDataHandler.GetAmputatedLimbs(LocalPlayerController.username) - local xp = self.maxTime/100 + local xp = self.maxTime / 100 for k, _ in pairs(amputatedLimbs) do local limbName = k @@ -92,7 +92,6 @@ function ISBaseTimedAction:perform() if dcInst:getIsProstEquipped(limbName) then LocalPlayerController.playerObj:getXp():AddXP(Perks["ProstFamiliarity"], xp) end - end end end @@ -124,7 +123,6 @@ end ---A recreation of the original method, but with amputations in mind function ISEquipWeaponAction:performWithAmputation() - TOC_DEBUG.print("running ISEquipWeaponAction performWithAmputation") local hand = nil local otherHand = nil @@ -203,12 +201,15 @@ local og_ISEquipWeaponAction_perform = ISEquipWeaponAction.perform function ISEquipWeaponAction:perform() og_ISEquipWeaponAction_perform(self) - -- TODO Can we do it earlier? + + --if self.character == getPlayer() then local dcInst = DataController.GetInstance(self.character:getUsername()) -- Just check it any limb has been cut. If not, we can just return from here - if dcInst:getIsAnyLimbCut() == true then + if dcInst:getIsAnyLimbCut() then self:performWithAmputation() end + + --end end function ISInventoryPaneContextMenu.doEquipOption(context, playerObj, isWeapon, items, player) @@ -268,6 +269,23 @@ function ISWorldObjectContextMenu.createMenu(player, worldobjects, x, y, test) ---@type ISContextMenu local ogContext = og_ISWorldObjectContextMenu_createMenu(player, worldobjects, x, y, test) + + -- The vanilla game doesn't count an item in the off hand as "equipped" for picking up glass. Let's fix that here + local brokenGlassOption = ogContext:getOptionFromName(getText("ContextMenu_RemoveBrokenGlass")) + + if brokenGlassOption then + local playerObj = getSpecificPlayer(player) + if (CachedDataHandler.GetHandFeasibility(StaticData.SIDES_IND_STR.R) and playerObj:getPrimaryHandItem()) or + (CachedDataHandler.GetHandFeasibility(StaticData.SIDES_IND_STR.L) and playerObj:getSecondaryHandItem()) + then + brokenGlassOption.notAvailable = false + brokenGlassOption.toolTip = nil -- This is active only when you can't do the action. + end + end + + + + -- check if no hands, disable various interactions if not CachedDataHandler.GetBothHandsFeasibility() then TOC_DEBUG.print("NO hands :((") @@ -282,8 +300,7 @@ function ISWorldObjectContextMenu.createMenu(player, worldobjects, x, y, test) return ogContext end - ---* DISABLE WEARING CERTAIN ITEMS WHEN NO LIMB +--* DISABLE WEARING CERTAIN ITEMS WHEN NO LIMB local function CheckLimbFeasibility(limbName) local dcInst = DataController.GetInstance() @@ -321,4 +338,4 @@ local og_ISClothingExtraAction_isValid = ISClothingExtraAction.isValid ---@diagnostic disable-next-line: duplicate-set-field function ISClothingExtraAction:isValid() return WrapClothingAction(self, og_ISClothingExtraAction_isValid, InventoryItemFactory.CreateItem(self.extra)) -end \ No newline at end of file +end diff --git a/media/lua/client/TOC/Handlers/CachedDataHandler.lua b/media/lua/client/TOC/Handlers/CachedDataHandler.lua index 38f5cdb..8e1c6ec 100644 --- a/media/lua/client/TOC/Handlers/CachedDataHandler.lua +++ b/media/lua/client/TOC/Handlers/CachedDataHandler.lua @@ -123,7 +123,8 @@ function CachedDataHandler.CalculateHandFeasibility(limbName) CachedDataHandler.handFeasibility[side] = not dcInst:getIsCut(limbName) or dcInst:getIsProstEquipped(limbName) end - +---@param side string Either "L" or "R" +---@return boolean function CachedDataHandler.GetHandFeasibility(side) return CachedDataHandler.handFeasibility[side] end