diff --git a/media/lua/client/TOC/Controllers/LimitActionsController.lua b/media/lua/client/TOC/Controllers/LimitActionsController.lua index 48a042e..e34d71f 100644 --- a/media/lua/client/TOC/Controllers/LimitActionsController.lua +++ b/media/lua/client/TOC/Controllers/LimitActionsController.lua @@ -15,8 +15,12 @@ local StaticData = require("TOC/StaticData") -- a prosthesis on, that can trigger random bleeds. local function CheckHandFeasibility(limbName) + TOC_DEBUG.print("Checking hand feasibility: " .. limbName) local dcInst = DataController.GetInstance() - return not dcInst:getIsCut(limbName) or dcInst:getIsProstEquipped(limbName) + + local isFeasible = not dcInst:getIsCut(limbName) or dcInst:getIsProstEquipped(limbName) + TOC_DEBUG.print("isFeasible: " .. tostring(isFeasible)) + return isFeasible end @@ -107,6 +111,8 @@ end ---A recreation of the original method, but with amputations in mind ---@param dcInst DataController function ISEquipWeaponAction:performWithAmputation(dcInst) + + TOC_DEBUG.print("running ISEquipWeaponAction performWithAmputation") local hand = nil local otherHand = nil local getMethodFirst = nil @@ -130,6 +136,10 @@ function ISEquipWeaponAction:performWithAmputation(dcInst) setMethodSecond = self.character.setSecondaryHandItem end + local isFirstValid = CheckHandFeasibility(hand) + local isSecondValid = CheckHandFeasibility(otherHand) + + if not self.twoHands then if getMethodFirst(self.character) and getMethodFirst(self.character):isRequiresEquippedBothHands() then setMethodFirst(self.character, nil) @@ -145,10 +155,10 @@ function ISEquipWeaponAction:performWithAmputation(dcInst) setMethodSecond(self.character, nil) -- TODO We should use the CachedData indexable instead of dcInst - if not dcInst:getIsCut(hand) then + if isFirstValid then setMethodSecond(self.character, self.item) -- Check other HAND! - elseif not dcInst:getIsCut(otherHand) then + elseif isSecondValid then setMethodFirst(self.character, self.item) end end @@ -156,13 +166,10 @@ function ISEquipWeaponAction:performWithAmputation(dcInst) setMethodFirst(self.character, nil) setMethodSecond(self.character, nil) - - local isFirstValid = CheckHandFeasibility(hand) - local isSecondValid = CheckHandFeasibility(otherHand) -- TOC_DEBUG.print("First Hand: " .. tostring(hand)) - -- TOC_DEBUG.print("Prost Group: " .. tostring(prostGroup)) + -- --TOC_DEBUG.print("Prost Group: " .. tostring(prostGroup)) -- TOC_DEBUG.print("Other Hand: " .. tostring(otherHand)) - -- TOC_DEBUG.print("Other Prost Group: " .. tostring(otherProstGroup)) + -- --TOC_DEBUG.print("Other Prost Group: " .. tostring(otherProstGroup)) -- TOC_DEBUG.print("isPrimaryHandValid: " .. tostring(isFirstValid)) -- TOC_DEBUG.print("isSecondaryHandValid: " .. tostring(isSecondValid)) diff --git a/media/lua/client/TOC/Controllers/LocalPlayerController.lua b/media/lua/client/TOC/Controllers/LocalPlayerController.lua index 24bdc65..73fc2a0 100644 --- a/media/lua/client/TOC/Controllers/LocalPlayerController.lua +++ b/media/lua/client/TOC/Controllers/LocalPlayerController.lua @@ -354,10 +354,20 @@ function LocalPlayerController.DropItemsAfterAmputation(limbName) end end end + + -- TODO Consider 2 handed weapons too + + -- equipped items too + if side == "R" then + pl:setPrimaryHandItem(nil) + elseif side == "L" then + pl:setSecondaryHandItem(nil) + end + end Events.OnAmputatedLimb.Add(LocalPlayerController.DropItemsAfterAmputation) - +Events.OnProsthesisUnequipped.Add(LocalPlayerController.DropItemsAfterAmputation) diff --git a/media/lua/client/TOC/Events.lua b/media/lua/client/TOC/Events.lua index 13b9246..0d3b4c9 100644 --- a/media/lua/client/TOC/Events.lua +++ b/media/lua/client/TOC/Events.lua @@ -1,3 +1,4 @@ --* Setup Events *-- LuaEventManager.AddEvent("OnAmputatedLimb") --Triggered when a limb has been amputated +LuaEventManager.AddEvent("OnProsthesisUnequipped") LuaEventManager.AddEvent("OnReceivedTocData") -- Triggered when TOC data is ready diff --git a/media/lua/client/TOC/Handlers/CachedDataHandler.lua b/media/lua/client/TOC/Handlers/CachedDataHandler.lua index 77aa059..2d6330d 100644 --- a/media/lua/client/TOC/Handlers/CachedDataHandler.lua +++ b/media/lua/client/TOC/Handlers/CachedDataHandler.lua @@ -111,6 +111,8 @@ end + + --* Hand feasibility caching *-- CachedDataHandler.handFeasibility = {} diff --git a/media/lua/client/TOC/Handlers/ProsthesisHandler.lua b/media/lua/client/TOC/Handlers/ProsthesisHandler.lua index afdd5f6..cfb4943 100644 --- a/media/lua/client/TOC/Handlers/ProsthesisHandler.lua +++ b/media/lua/client/TOC/Handlers/ProsthesisHandler.lua @@ -70,11 +70,10 @@ function ProsthesisHandler.CheckIfEquippable(fullType) return false end - ---Handle equipping or unequipping prosthetics ---@param item InventoryItem ---@param isEquipping boolean ----@return boolean +---@return boolean function ProsthesisHandler.SearchAndSetupProsthesis(item, isEquipping) if not ProsthesisHandler.CheckIfProst(item) then return false end @@ -100,7 +99,7 @@ local function HandleProsthesisValidation(item, isEquippable) local isProst = ProsthesisHandler.CheckIfProst(item) if not isProst then return isEquippable end - local fullType = item:getFullType() -- use fulltype for side + local fullType = item:getFullType() -- use fulltype for side if isEquippable then isEquippable = ProsthesisHandler.CheckIfEquippable(fullType) else @@ -133,8 +132,6 @@ function ISClothingExtraAction:isValid() return HandleProsthesisValidation(testItem, isEquippable) end - - --[[ Horrendous workaround @@ -161,7 +158,6 @@ function ISClothingExtraAction:perform() if isProst then group:setMultiItem("TOC_ArmProst", true) end - end local og_ISUnequipAction_perform = ISUnequipAction.perform @@ -176,8 +172,15 @@ function ISUnequipAction:perform() if isProst then group:setMultiItem("TOC_ArmProst", true) + + -- we need to fetch the limbname associated to the prosthesis + local side = CommonMethods.GetSide(self.item:getFullType()) + local highestAmputatedLimbs = CachedDataHandler.GetHighestAmputatedLimbs(getPlayer():getUsername()) + if highestAmputatedLimbs then + local hal = highestAmputatedLimbs[side] + triggerEvent("OnProsthesisUnequipped", hal) + end end end - return ProsthesisHandler diff --git a/media/lua/server/TOC/ServerDataHandler.lua b/media/lua/server/TOC/ServerDataHandler.lua index e302f46..68fea34 100644 --- a/media/lua/server/TOC/ServerDataHandler.lua +++ b/media/lua/server/TOC/ServerDataHandler.lua @@ -29,18 +29,11 @@ function ServerDataHandler.AddTable(key, table) --TOC_DEBUG.printTable(table) -- Set that the data has been modified and it's updated on the server - table.isUpdateFromServer = true -- FIX this is useless + table.isUpdateFromServer = true -- FIX this is useless as of now ModData.add(key, table) -- Add it to the server mod data ServerDataHandler.modData[key] = table - - -- if table.isInitializing == true then - -- TOC_DEBUG.print("Applied data after setup") - -- table.isInitializing = false - -- end - - -- Since this could be triggered by a different client than the one referenced in the key, we're gonna -- apply the changes back to the key client again to be sure that everything is in sync local username = CommandsData.GetUsername(key)