Fixed equipping prosthesis on upper arms

This commit is contained in:
ZioPao
2024-03-21 03:02:52 +01:00
parent 5b524e5a4f
commit 3fb22a9b1e
3 changed files with 71 additions and 46 deletions

View File

@@ -228,4 +228,34 @@ function ISInventoryPaneContextMenu.doEquipOption(context, playerObj, isWeapon,
end end
-- TODO IMPORTANT!!!! ADD LIMIT FOR UPPER ARM AND WHEN YOU DON'T HAVE AMPUTATIONS FOR PROSTHETITCS -- 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

View File

@@ -96,7 +96,7 @@ end
---Get the cached highest point of amputation for each side ---Get the cached highest point of amputation for each side
---@param username string ---@param username string
---@return table ---@return table<string, string>
function CachedDataHandler.GetHighestAmputatedLimbs(username) function CachedDataHandler.GetHighestAmputatedLimbs(username)
return CachedDataHandler.highestAmputatedLimbs[username] return CachedDataHandler.highestAmputatedLimbs[username]
end end

View File

@@ -14,7 +14,12 @@ local bodyLocArmProst = StaticData.MOD_BODYLOCS_BASE_IND_STR.TOC_ArmProst
---@return boolean ---@return boolean
function ProsthesisHandler.CheckIfProst(item) function ProsthesisHandler.CheckIfProst(item)
-- TODO Won't be correct when prost for legs are gonna be in -- 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) return item:getBodyLocation():contains(bodyLocArmProst)
end end
@@ -30,18 +35,19 @@ function ProsthesisHandler.GetGroup(item)
end 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 ---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 ---@return boolean
function ProsthesisHandler.CheckIfEquippable(bodyLocation) function ProsthesisHandler.CheckIfEquippable(name)
TOC_DEBUG.print("Current item is a prosthesis") 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)) TOC_DEBUG.print("Checking side: " .. tostring(side))
local amputatedLimbs = CachedDataHandler.GetAmputatedLimbs(getPlayer():getUsername()) local highestAmputatedLimbs = CachedDataHandler.GetHighestAmputatedLimbs(getPlayer():getUsername())
for k, _ in pairs(amputatedLimbs) do
local limbName = k if highestAmputatedLimbs then
if string.contains(limbName, side) and not string.contains(limbName, "UpperArm") then local hal = highestAmputatedLimbs[side]
TOC_DEBUG.print("Found acceptable limb to use prosthesis") if not string.contains(hal, "UpperArm") then
TOC_DEBUG.print("Found acceptable limb to use prosthesis => " .. tostring(hal))
return true return true
end end
end end
@@ -58,7 +64,7 @@ function ProsthesisHandler.SearchAndSetupProsthesis(item, isEquipping)
if not ProsthesisHandler.CheckIfProst(item) then return end if not ProsthesisHandler.CheckIfProst(item) then return end
local group = ProsthesisHandler.GetGroup(item) 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() local dcInst = DataController.GetInstance()
dcInst:setIsProstEquipped(group, isEquipping) dcInst:setIsProstEquipped(group, isEquipping)
dcInst:apply() dcInst:apply()
@@ -68,23 +74,32 @@ end
--* Overrides *-- --* 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 ---@diagnostic disable-next-line: duplicate-set-field
local og_ISWearClothing_isValid = ISWearClothing.isValid local og_ISWearClothing_isValid = ISWearClothing.isValid
function ISWearClothing:isValid() function ISWearClothing:isValid()
local isEquippable = og_ISWearClothing_isValid(self) local isEquippable = og_ISWearClothing_isValid(self)
return HandleProsthesisValidation(self.item, isEquippable)
-- 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
end end
local og_ISWearClothing_perform = ISWearClothing.perform local og_ISWearClothing_perform = ISWearClothing.perform
@@ -97,27 +112,7 @@ local og_ISClothingExtraAction_isValid = ISClothingExtraAction.isValid
---@diagnostic disable-next-line: duplicate-set-field ---@diagnostic disable-next-line: duplicate-set-field
function ISClothingExtraAction:isValid() function ISClothingExtraAction:isValid()
local isEquippable = og_ISClothingExtraAction_isValid(self) local isEquippable = og_ISClothingExtraAction_isValid(self)
return HandleProsthesisValidation(self.item, isEquippable)
--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
end end
local og_ISClothingExtraAction_perform = ISClothingExtraAction.perform local og_ISClothingExtraAction_perform = ISClothingExtraAction.perform