Refactor ProsthesisHandler for B42 compatibility

This commit is contained in:
guiriguy
2025-12-18 22:48:17 +01:00
committed by GitHub
parent b650b2a590
commit 38fe71bc72

View File

@@ -9,7 +9,7 @@ local OverridenMethodsArchive = require("TOC/OverridenMethodsArchive")
---@class ProsthesisHandler ---@class ProsthesisHandler
local ProsthesisHandler = {} local ProsthesisHandler = {}
local bodylocArmProstBaseline = "TOC_ArmProst" local bodylocArmProstBaseline = "toc:toc_armprost"
--local bodyLocLegProst = "TOC_LegProst" --local bodyLocLegProst = "TOC_LegProst"
---Check if the following item is a prosthesis or not ---Check if the following item is a prosthesis or not
@@ -17,13 +17,12 @@ local bodylocArmProstBaseline = "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
--TOC_DEBUG.print("Checking if item is prost")
if item == nil then if item == nil then
--TOC_DEBUG.print("Not prost") TOC_DEBUG.print("Not prost")
return false return false
end end
return item:getBodyLocation():contains(bodylocArmProstBaseline) return item:getBodyLocation():toString():contains(bodylocArmProstBaseline)
end end
---Get the grouping for the prosthesis ---Get the grouping for the prosthesis
@@ -35,7 +34,7 @@ function ProsthesisHandler.GetGroup(item)
local bodyLocation = item:getBodyLocation() local bodyLocation = item:getBodyLocation()
local position local position
if bodyLocation:contains(bodylocArmProstBaseline) then if bodyLocation:toString():contains(bodylocArmProstBaseline) then
position = "Top_" position = "Top_"
else else
TOC_DEBUG.print("Something is wrong, no position in this item") TOC_DEBUG.print("Something is wrong, no position in this item")
@@ -133,14 +132,19 @@ function ISClothingExtraAction:isValid()
local isEquippable = og_ISClothingExtraAction_isValid(self) local isEquippable = og_ISClothingExtraAction_isValid(self)
-- self.extra is a string, not the item -- self.extra is a string, not the item
local testItem = instanceItem(self.extra) -- B42 Compatibility to add
local testItem = InventoryItemFactory.CreateItem(self.extra)
return ProsthesisHandler.Validate(testItem, isEquippable) return ProsthesisHandler.Validate(testItem, isEquippable)
end end
local og_ISClothingExtraAction_perform = OverridenMethodsArchive.Save("ISClothingExtraAction_perform", ISClothingExtraAction.perform) local og_ISClothingExtraAction_perform = OverridenMethodsArchive.Save("ISClothingExtraAction_perform", ISClothingExtraAction.perform)
---@diagnostic disable-next-line: duplicate-set-field ---@diagnostic disable-next-line: duplicate-set-field
function ISClothingExtraAction:perform() function ISClothingExtraAction:perform()
local extraItem = instanceItem(self.extra)
-- B42 Compatibility to add
local extraItem = InventoryItemFactory.CreateItem(self.extra)
ProsthesisHandler.SearchAndSetupProsthesis(extraItem, true) ProsthesisHandler.SearchAndSetupProsthesis(extraItem, true)
og_ISClothingExtraAction_perform(self) og_ISClothingExtraAction_perform(self)
end end
@@ -182,22 +186,4 @@ function ISUnequipAction:perform()
end end
end end
local og_ISUnequipAction_complete = ISUnequipAction.complete
function ISUnequipAction:complete()
-- Horrendous workaround. For B42, as of now, it will basically happen two times, once with :perform and once with :complete. Shouldn't
-- matter for performance but it's really ugly.
-- local isProst = ProsthesisHandler.SearchAndSetupProsthesis(self.item, false)
-- local group
-- if isProst then
-- group = BodyLocations.getGroup("Human")
-- group:setMultiItem("TOC_ArmProst", false)
-- end
og_ISUnequipAction_complete(self)
-- if isProst then
-- group:setMultiItem("TOC_ArmProst", true)
-- end
end
return ProsthesisHandler return ProsthesisHandler