Fixed CutLimbHandler once again

This commit is contained in:
ZioPao
2023-11-16 18:19:47 +01:00
parent e7119cf032
commit 18cae1de98
2 changed files with 51 additions and 20 deletions

View File

@@ -13,6 +13,7 @@ local StaticData = require("TOC/StaticData")
---@class PlayerHandler ---@class PlayerHandler
---@field playerObj IsoPlayer ---@field playerObj IsoPlayer
---@field hasBeenDamaged boolean
local PlayerHandler = {} local PlayerHandler = {}
---Setup the Player Handler and modData, only for local client ---Setup the Player Handler and modData, only for local client
@@ -96,29 +97,26 @@ end
------------------------- -------------------------
--* Events *-- --* Events *--
--- Locks OnPlayerGetDamage event, to prevent it from getting spammed constantly
PlayerHandler.hasBeenDamaged = false
---Check if the player has in infected body part or if they have been hit in a cut area ---Check if the player has in infected body part or if they have been hit in a cut area
---@param character IsoGameCharacter ---@param character IsoPlayer
---@param damageType string function PlayerHandler.HandleDamage(character)
---@param damageAmount number
function PlayerHandler.CheckDamage(character, damageType, damageAmount)
-- TODO This fucking event barely works. Bleeding seems to be the only thing that triggers it. use this to trigger something else and then do not let it keep going
-- TOC_DEBUG.print("Player got hit!") -- TOC_DEBUG.print("Player got hit!")
-- TOC_DEBUG.print(damageType) -- TOC_DEBUG.print(damageType)
if character ~= getPlayer() then return end if character ~= getPlayer() then return end
local bd = character:getBodyDamage() local bd = character:getBodyDamage()
local modDataHandler = ModDataHandler.GetInstance() local modDataHandler = ModDataHandler.GetInstance()
local modDataNeedsUpdate = false
for i=1, #StaticData.LIMBS_STR do for i=1, #StaticData.LIMBS_STR do
local limbName = StaticData.LIMBS_STR[i] local limbName = StaticData.LIMBS_STR[i]
local bptEnum = StaticData.BODYLOCS_IND_BPT[limbName] local bptEnum = StaticData.BODYLOCS_IND_BPT[limbName]
local bodyPart = bd:getBodyPart(bptEnum) local bodyPart = bd:getBodyPart(bptEnum)
if modDataHandler:getIsCut(limbName) then if modDataHandler:getIsCut(limbName) then
-- Generic injury, let's heal it since they already cut the limb off -- Generic injury, let's heal it since they already cut the limb off
--FIXME conflicts with the other thing... Ah fuck wait I'm retarded
if bodyPart:HasInjury() then if bodyPart:HasInjury() then
PlayerHandler.HealArea(bodyPart) PlayerHandler.HealArea(bodyPart)
end end
@@ -131,27 +129,52 @@ function PlayerHandler.CheckDamage(character, damageType, damageAmount)
else else
if bodyPart:bitten() or bodyPart:IsInfected() then if bodyPart:bitten() or bodyPart:IsInfected() then
modDataHandler:setIsInfected(limbName, true) modDataHandler:setIsInfected(limbName, true)
modDataHandler:apply() modDataNeedsUpdate = true
end end
end end
end end
-- Check other body parts that are not included in the mod, if there's a bite there then the player is fucked -- Check other body parts that are not included in the mod, if there's a bite there then the player is fucked
-- We can skip this loop if the player has been infected. The one before we kinda need it to handle correctly the bites in case the player wanna cut stuff off anyway -- We can skip this loop if the player has been infected. The one before we kinda need it to handle correctly the bites in case the player wanna cut stuff off anyway
if ModDataHandler.GetInstance():getIsIgnoredPartInfected() then return end if modDataHandler:getIsIgnoredPartInfected() then return end
for i=1, #StaticData.IGNORED_BODYLOCS_BPT do for i=1, #StaticData.IGNORED_BODYLOCS_BPT do
local bodyPartType = StaticData.IGNORED_BODYLOCS_BPT[i] local bodyPartType = StaticData.IGNORED_BODYLOCS_BPT[i]
local bodyPart = bd:getBodyPart(bodyPartType) local bodyPart = bd:getBodyPart(bodyPartType)
if bodyPart and (bodyPart:bitten() or bodyPart:IsInfected()) then if bodyPart and (bodyPart:bitten() or bodyPart:IsInfected()) then
ModDataHandler.GetInstance():setIsIgnoredPartInfected(true) modDataHandler:setIsIgnoredPartInfected(true)
modDataNeedsUpdate = true
end end
end end
-- TODO in theory we should sync modData, but it's gonna be expensive as fuck. Figure it out -- TODO in theory should sync modData, but it's gonna be expensive as fuck. Figure it out
if modDataNeedsUpdate then
modDataHandler:apply()
end
-- Disable the lock
PlayerHandler.hasBeenDamaged = false
end end
Events.OnPlayerGetDamage.Add(PlayerHandler.CheckDamage) ---Setup HandleDamage, triggered by OnPlayerGetDamage
---@param character IsoGameCharacter
---@param damageType string
---@param damageAmount number
function PlayerHandler.OnGetDamage(character, damageType, damageAmount)
-- TODO Check if other players in the online triggers this
if PlayerHandler.hasBeenDamaged == false then
-- Start checks
-- TODO Add a timer before we can re-enable this bool?
PlayerHandler.hasBeenDamaged = true
PlayerHandler.HandleDamage(character)
end
end
Events.OnPlayerGetDamage.Add(PlayerHandler.OnGetDamage)
---Updates the cicatrization process, run when a limb has been cut. Run it every 1 hour ---Updates the cicatrization process, run when a limb has been cut. Run it every 1 hour
function PlayerHandler.UpdateCicatrization() function PlayerHandler.UpdateCicatrization()

View File

@@ -144,6 +144,7 @@ Events.OnFillInventoryObjectContextMenu.Add(AddInventoryAmputationMenu)
---@class CutLimbHandler : BaseHandler ---@class CutLimbHandler : BaseHandler
---@field items table ---@field items table
---@field limbName string ---@field limbName string
---@field itemType string temporary
local CutLimbHandler = BaseHandler:derive("CutLimbHandler") local CutLimbHandler = BaseHandler:derive("CutLimbHandler")
@@ -155,14 +156,16 @@ function CutLimbHandler:new(panel, bodyPart)
local o = BaseHandler.new(self, panel, bodyPart) local o = BaseHandler.new(self, panel, bodyPart)
o.items.ITEMS = {} o.items.ITEMS = {}
o.limbName = BodyPartType.ToString(bodyPart:getType()) o.limbName = BodyPartType.ToString(bodyPart:getType())
o.itemType = "Saw"
TOC_DEBUG.print("init CutLimbHandler") TOC_DEBUG.print("init CutLimbHandler")
return o return o
end end
---@param item InventoryItem ---@param item InventoryItem
function CutLimbHandler:checkItem(item) function CutLimbHandler:checkItem(item)
TOC_DEBUG.print("CutLimbHandler checkItem")
local itemType = item:getType() local itemType = item:getType()
TOC_DEBUG.print("checkItem: " .. tostring(itemType)) --TOC_DEBUG.print("checkItem: " .. tostring(itemType))
if CheckIfSaw(itemType) then if CheckIfSaw(itemType) then
TOC_DEBUG.print("added to list -> " .. itemType) TOC_DEBUG.print("added to list -> " .. itemType)
@@ -172,11 +175,12 @@ end
---@param context ISContextMenu ---@param context ISContextMenu
function CutLimbHandler:addToMenu(context) function CutLimbHandler:addToMenu(context)
TOC_DEBUG.print("CutLimbHandler addToMenu")
local types = self:getAllItemTypes(self.items.ITEMS) local types = self:getAllItemTypes(self.items.ITEMS)
if #types > 0 and StaticData.BODYLOCS_IND_BPT[self.limbName] then if #types > 0 and StaticData.BODYLOCS_IND_BPT[self.limbName] and not ModDataHandler.GetInstance():getIsCut(self.limbName) then
TOC_DEBUG.print("addToMenu, types > 0") TOC_DEBUG.print("addToMenu, types > 0")
if not ModDataHandler.GetInstance():getIsCut(self.limbName) then for i=1, #types do
context:addOption(getText("ContextMenu_Amputate"), self, self.onMenuOptionSelected) context:addOption(getText("ContextMenu_Amputate"), self, self.onMenuOptionSelected, types[i])
end end
end end
end end
@@ -190,8 +194,12 @@ function CutLimbHandler:dropItems(items)
return false return false
end end
function CutLimbHandler:isValid(itemType) ---Check if CutLimbHandler is valid, the limb must not be cut to be valid
return (not ModDataHandler.GetInstance():getIsCut(self.limbName)) and self:getItemOfType(self.items.ITEMS, itemType) ---@return boolean
function CutLimbHandler:isValid()
TOC_DEBUG.print("CutLimbHandler isValid")
self:checkItems()
return not ModDataHandler.GetInstance():getIsCut(self.limbName)
end end
function CutLimbHandler:perform(previousAction, itemType) function CutLimbHandler:perform(previousAction, itemType)