cleaning up crap

This commit is contained in:
ZioPao
2024-04-30 18:00:34 +02:00
parent 074950ebf6
commit 7b07b7954a
3 changed files with 129 additions and 45 deletions

View File

@@ -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

View 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

View File

@@ -3,7 +3,7 @@ local ItemsController = require("TOC/Controllers/ItemsController")
local CachedDataHandler = require("TOC/Handlers/CachedDataHandler")
local LocalPlayerController = require("TOC/Controllers/LocalPlayerController")
local StaticData = require("TOC/StaticData")
local CommonMethods = require("TOC/CommonMethods")
local TourniquetController = require("TOC/Controllers/TourniquetController")
---------------------------
--- Manages an amputation. Will be run on the patient client
@@ -42,31 +42,6 @@ end
--* Static methods *--
---@param player IsoPlayer
---@param limbName string
---@return boolean
function AmputationHandler.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
---@param player IsoPlayer
---@param limbName string
function AmputationHandler.ApplyDamageDuringAmputation(player, limbName)
@@ -159,7 +134,7 @@ function AmputationHandler:damageAfterAmputation(surgeonFactor)
-- Check if player has tourniquet equipped on the limb
-- TODO Suboptimal checks, but they should work for now.
local hasTourniquet = AmputationHandler.CheckTourniquet(self.patientPl, self.limbName)
local hasTourniquet = TourniquetController.CheckTourniquetOnLimb(self.patientPl, self.limbName)
if hasTourniquet then
TOC_DEBUG.print("Do something different for the damage calculation because tourniquet is applied")
baseDamage = baseDamage * 0.5 -- 50% less damage due to tourniquet