cleaning up crap
This commit is contained in:
@@ -273,33 +273,32 @@ local function CheckLimbFeasibility(limbName)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
---@diagnostic disable-next-line: duplicate-set-field
|
|
||||||
local og_ISWearClothing_isValid = ISWearClothing.isValid
|
|
||||||
function ISWearClothing:isValid()
|
---@param obj any
|
||||||
local isEquippable = og_ISWearClothing_isValid(self)
|
---@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
|
if not isEquippable then return isEquippable end
|
||||||
|
|
||||||
---@type Item
|
|
||||||
local item = self.item
|
|
||||||
local itemBodyLoc = item:getBodyLocation()
|
local itemBodyLoc = item:getBodyLocation()
|
||||||
|
|
||||||
local limbToCheck = StaticData.AFFECTED_BODYLOCS_TO_LIMBS_IND_STR[itemBodyLoc]
|
local limbToCheck = StaticData.AFFECTED_BODYLOCS_TO_LIMBS_IND_STR[itemBodyLoc]
|
||||||
if CheckLimbFeasibility(limbToCheck) then return isEquippable else return false end
|
if CheckLimbFeasibility(limbToCheck) then return isEquippable else return false end
|
||||||
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
|
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)
|
return WrapClothingAction(self, og_ISClothingExtraAction_isValid, InventoryItemFactory.CreateItem(self.extra))
|
||||||
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
|
|
||||||
end
|
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
|
||||||
@@ -3,7 +3,7 @@ local ItemsController = require("TOC/Controllers/ItemsController")
|
|||||||
local CachedDataHandler = require("TOC/Handlers/CachedDataHandler")
|
local CachedDataHandler = require("TOC/Handlers/CachedDataHandler")
|
||||||
local LocalPlayerController = require("TOC/Controllers/LocalPlayerController")
|
local LocalPlayerController = require("TOC/Controllers/LocalPlayerController")
|
||||||
local StaticData = require("TOC/StaticData")
|
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
|
--- Manages an amputation. Will be run on the patient client
|
||||||
@@ -42,31 +42,6 @@ end
|
|||||||
|
|
||||||
--* Static methods *--
|
--* 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 player IsoPlayer
|
||||||
---@param limbName string
|
---@param limbName string
|
||||||
function AmputationHandler.ApplyDamageDuringAmputation(player, limbName)
|
function AmputationHandler.ApplyDamageDuringAmputation(player, limbName)
|
||||||
@@ -159,7 +134,7 @@ function AmputationHandler:damageAfterAmputation(surgeonFactor)
|
|||||||
|
|
||||||
-- Check if player has tourniquet equipped on the limb
|
-- Check if player has tourniquet equipped on the limb
|
||||||
-- TODO Suboptimal checks, but they should work for now.
|
-- 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
|
if hasTourniquet then
|
||||||
TOC_DEBUG.print("Do something different for the damage calculation because tourniquet is applied")
|
TOC_DEBUG.print("Do something different for the damage calculation because tourniquet is applied")
|
||||||
baseDamage = baseDamage * 0.5 -- 50% less damage due to tourniquet
|
baseDamage = baseDamage * 0.5 -- 50% less damage due to tourniquet
|
||||||
|
|||||||
Reference in New Issue
Block a user