cleaning up crap
This commit is contained in:
@@ -273,33 +273,32 @@ local function CheckLimbFeasibility(limbName)
|
||||
end
|
||||
|
||||
|
||||
---@diagnostic disable-next-line: duplicate-set-field
|
||||
local og_ISWearClothing_isValid = ISWearClothing.isValid
|
||||
function ISWearClothing:isValid()
|
||||
local isEquippable = og_ISWearClothing_isValid(self)
|
||||
|
||||
|
||||
---@param obj any
|
||||
---@param wrappedFunc function
|
||||
---@param item InventoryItem
|
||||
---@return boolean
|
||||
local function WrapClothingAction(obj, wrappedFunc, item)
|
||||
local isEquippable = wrappedFunc(obj)
|
||||
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
|
||||
|
||||
|
||||
|
||||
---@diagnostic disable-next-line: duplicate-set-field
|
||||
local og_ISWearClothing_isValid = ISWearClothing.isValid
|
||||
function ISWearClothing:isValid()
|
||||
return WrapClothingAction(self, og_ISWearClothing_isValid, self.item)
|
||||
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
|
||||
return WrapClothingAction(self, og_ISClothingExtraAction_isValid, InventoryItemFactory.CreateItem(self.extra))
|
||||
end
|
||||
110
media/lua/client/TOC/Controllers/TourniquetController.lua
Normal file
110
media/lua/client/TOC/Controllers/TourniquetController.lua
Normal file
@@ -0,0 +1,110 @@
|
||||
|
||||
local CommonMethods = require("TOC/CommonMethods")
|
||||
|
||||
|
||||
---@class TourniquetController
|
||||
local TourniquetController = {
|
||||
bodyLoc = "TOC_ArmAccessory"
|
||||
}
|
||||
|
||||
|
||||
function TourniquetController.CheckTourniquetOnLimb(player, limbName)
|
||||
local side = CommonMethods.GetSide(limbName)
|
||||
|
||||
local wornItems = player:getWornItems()
|
||||
for j=1,wornItems:size() do
|
||||
local wornItem = wornItems:get(j-1)
|
||||
|
||||
local fType = wornItem:getItem():getFullType()
|
||||
if TourniquetController.IsItemTourniquet(fType) then
|
||||
-- Check side
|
||||
if luautils.stringEnds(fType, side) then
|
||||
TOC_DEBUG.print("Found acceptable tourniquet")
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
function TourniquetController.IsItemTourniquet(fType)
|
||||
-- TODO Add legs stuff
|
||||
return string.contains(fType, "Surg_Arm_Tourniquet_")
|
||||
end
|
||||
|
||||
|
||||
|
||||
---@param player IsoPlayer
|
||||
---@param limbName string
|
||||
---@return boolean
|
||||
function TourniquetController.CheckTourniquet(player, limbName)
|
||||
|
||||
local side = CommonMethods.GetSide(limbName)
|
||||
|
||||
local wornItems = player:getWornItems()
|
||||
for j=1,wornItems:size() do
|
||||
local wornItem = wornItems:get(j-1)
|
||||
|
||||
local fType = wornItem:getItem():getFullType()
|
||||
if string.contains(fType, "Surg_Arm_Tourniquet_") then
|
||||
-- Check side
|
||||
if luautils.stringEnds(fType, side) then
|
||||
TOC_DEBUG.print("Found acceptable tourniquet")
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
---@private
|
||||
---@param obj any self
|
||||
---@param wrappedFunc function
|
||||
function TourniquetController.WrapClothingAction(obj, wrappedFunc)
|
||||
local isTourniquet = TourniquetController.IsItemTourniquet(obj.item:getFullType())
|
||||
local group
|
||||
if isTourniquet then
|
||||
group = BodyLocations.getGroup("Human")
|
||||
group:setMultiItem(TourniquetController.bodyLoc, false)
|
||||
end
|
||||
|
||||
wrappedFunc(obj)
|
||||
|
||||
if isTourniquet then
|
||||
group:setMultiItem(TourniquetController.bodyLoc, true)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Horrendous workaround
|
||||
|
||||
To unequp items, the java side uses WornItems.setItem, which has
|
||||
a check for multiItem. Basically, if it's active, it won't actually remove the item,
|
||||
fucking things up. So, to be 100% sure that we're removing the items, we're gonna
|
||||
disable and re-enable the multi-item bool for the Unequip Action.
|
||||
|
||||
Same story as the prosthesis item basically.
|
||||
]]
|
||||
|
||||
|
||||
local og_ISClothingExtraAction_perform = ISClothingExtraAction.perform
|
||||
function ISClothingExtraAction:perform()
|
||||
TourniquetController.WrapClothingAction(self, og_ISClothingExtraAction_perform)
|
||||
end
|
||||
|
||||
local og_ISWearClothing_isValid = ISWearClothing.isValid
|
||||
function ISWearClothing:isValid()
|
||||
TourniquetController.WrapClothingAction(self, og_ISWearClothing_isValid)
|
||||
end
|
||||
|
||||
local og_ISUnequipAction_perform = ISUnequipAction.perform
|
||||
function ISUnequipAction:perform()
|
||||
TourniquetController.WrapClothingAction(self, og_ISUnequipAction_perform)
|
||||
end
|
||||
|
||||
|
||||
return TourniquetController
|
||||
Reference in New Issue
Block a user