Cleaning, bandages handling

This commit is contained in:
ZioPao
2023-11-15 11:07:15 +01:00
parent 46bc6030fe
commit c9b41838be
8 changed files with 84 additions and 28 deletions

View File

@@ -7,10 +7,5 @@ function CommonMethods.GetSide(name)
if string.find(name, "_L") then return "L" else return "R" end if string.find(name, "_L") then return "L" else return "R" end
end end
---comment
---@param bodyPart BodyPart
function CommonMethods.GetLimbNameFromBodyPart(bodyPart)
local bodyPartType = bodyPart:getType()
end
return CommonMethods return CommonMethods

View File

@@ -56,6 +56,16 @@ function AmputationHandler.ApplyDamageDuringAmputation(player, limbName)
bodyDamagePart:setBleedingTime(ZombRand(10, 20)) bodyDamagePart:setBleedingTime(ZombRand(10, 20))
end end
function AmputationHandler.HandleBandages(prevAction, limbName, surgeonPl, patientPl, bandageItem)
-- TODO Will it work? Can we get bodyDamage for another player from here?
local bptEnum = StaticData.BODYLOCS_IND_BPT[limbName]
local bd = patientPl:getBodyDamage()
local bodyPart = bd:getBodyPart(bptEnum)
local bandageAction = ISApplyBandage:new(surgeonPl, patientPl, bandageItem, bodyPart, true)
ISTimedActionQueue.addAfter(prevAction, bandageAction)
end
--* Main methods *-- --* Main methods *--
@@ -73,6 +83,7 @@ end
---Set the damage to the amputated area ---Set the damage to the amputated area
---@param surgeonFactor number ---@param surgeonFactor number
function AmputationHandler:damageAfterAmputation(surgeonFactor) function AmputationHandler:damageAfterAmputation(surgeonFactor)
-- TODO Torniquet should reduce the damage in total, less blood loss
local patientStats = self.patientPl:getStats() local patientStats = self.patientPl:getStats()
local bd = self.patientPl:getBodyDamage() local bd = self.patientPl:getBodyDamage()
local bodyPart = bd:getBodyPart(self.bodyPartType) local bodyPart = bd:getBodyPart(self.bodyPartType)
@@ -95,9 +106,6 @@ function AmputationHandler:execute(damagePlayer)
-- TODO Calculate surgeonStats -- TODO Calculate surgeonStats
-- TODO Cap it to a certain amount, it shouldn't be more than ...? -- TODO Cap it to a certain amount, it shouldn't be more than ...?
local surgeonFactor = 1 local surgeonFactor = 1
if damagePlayer then
self:damageAfterAmputation(surgeonFactor)
end
-- Set the data in modData -- Set the data in modData
local modDataHandler = ModDataHandler.GetInstance() local modDataHandler = ModDataHandler.GetInstance()
@@ -112,6 +120,11 @@ function AmputationHandler:execute(damagePlayer)
local username = self.patientPl:getUsername() local username = self.patientPl:getUsername()
CachedDataHandler.AddAmputatedLimb(username, self.limbName) CachedDataHandler.AddAmputatedLimb(username, self.limbName)
CachedDataHandler.CalculateHighestAmputatedLimbs(username) CachedDataHandler.CalculateHighestAmputatedLimbs(username)
-- The last part is to handle the damage that the player will receive after the amputation
if not damagePlayer then return end
self:damageAfterAmputation(surgeonFactor)
end end
---Deletes the instance ---Deletes the instance

View File

@@ -6,7 +6,7 @@ local CommonMethods = require("TOC/CommonMethods")
---@class CachedDataHandler ---@class CachedDataHandler
local CachedDataHandler = {} local CachedDataHandler = {}
---comment ---Reset everything cache related for that specific user
---@param username string ---@param username string
function CachedDataHandler.Reset(username) function CachedDataHandler.Reset(username)
CachedDataHandler.amputatedLimbs[username] = {} CachedDataHandler.amputatedLimbs[username] = {}
@@ -17,7 +17,7 @@ end
CachedDataHandler.amputatedLimbs = {} CachedDataHandler.amputatedLimbs = {}
-- TODO Add an indexable table too! -- TODO Add an indexable table too!
---Calcualte the currently amputated limbs for a certain player ---Calculate the currently amputated limbs for a certain player
---@param username string ---@param username string
function CachedDataHandler.CalculateAmputatedLimbs(username) function CachedDataHandler.CalculateAmputatedLimbs(username)
CachedDataHandler.amputatedLimbs[username] = {} CachedDataHandler.amputatedLimbs[username] = {}
@@ -30,7 +30,7 @@ function CachedDataHandler.CalculateAmputatedLimbs(username)
end end
end end
---Add an amputated limb to the cached list ---Add an amputated limb to the cached list for that user
---@param username string ---@param username string
---@param limbName string ---@param limbName string
function CachedDataHandler.AddAmputatedLimb(username, limbName) function CachedDataHandler.AddAmputatedLimb(username, limbName)

View File

@@ -24,7 +24,7 @@ function ModDataHandler:new(username, isResetForced)
ModData.request(key) ModData.request(key)
o.tocData = ModData.get(key) o.tocData = ModData.get(key)
if isResetForced or o.tocData == nil or o.tocData.limbs.Hand_L == nil or o.tocData.limbs.Hand_L.isCut == nil then if isResetForced or o.tocData == nil or o.tocData.limbs == nil or o.tocData.limbs.Hand_L == nil or o.tocData.limbs.Hand_L.isCut == nil then
TOC_DEBUG.print("tocData in ModDataHandler for " .. username .. " is nil, creating it now") TOC_DEBUG.print("tocData in ModDataHandler for " .. username .. " is nil, creating it now")
o:setup(key) o:setup(key)
end end

View File

@@ -1,10 +1,35 @@
local ModDataHandler = require("TOC/Handlers/ModDataHandler") local ModDataHandler = require("TOC/Handlers/ModDataHandler")
---@class SurgeryHandler
---@field type string
local SurgeryHandler = {} local SurgeryHandler = {}
function SurgeryHandler.InstallProsthesis() function SurgeryHandler:new(type)
-- TODO Set stuff in mod data local o = {}
setmetatable(o, self)
self.__index = self
-- TODO use getjob for this
o.type = type
return o
end end
function SurgeryHandler:execute()
if self.type == "needle" then
-- TODO
end
end
-- Cauterize
-- Needle and stitching (scrap surgery kits and crap like that)
return SurgeryHandler return SurgeryHandler

View File

@@ -1,6 +1,7 @@
require "TimedActions/ISBaseTimedAction" require "TimedActions/ISBaseTimedAction"
local AmputationHandler = require("TOC/Handlers/AmputationHandler") local AmputationHandler = require("TOC/Handlers/AmputationHandler")
local CommandsData = require("TOC/CommandsData") local CommandsData = require("TOC/CommandsData")
local StaticData = require("TOC/StaticData")
----------------------------- -----------------------------
---@class CutLimbAction : ISBaseTimedAction ---@class CutLimbAction : ISBaseTimedAction
@@ -52,21 +53,19 @@ function CutLimbAction:start()
sendClientCommand(CommandsData.modules.TOC_RELAY, CommandsData.server.Relay.RelayDamageDuringAmputation, params ) sendClientCommand(CommandsData.modules.TOC_RELAY, CommandsData.server.Relay.RelayDamageDuringAmputation, params )
end end
-- TODO Check bandages, if there are init a bandage process
local bandageItem = ""
local bptEnum = StaticData.BODYLOCS_IND_BPT[self.limbName]
local bd = self.character:getBodyDamage()
local bodyPart = bd:getBodyPart(bptEnum)
local bandageAction = ISApplyBandage:new(self.character, self.patient, bandageItem, bodyPart, true)
ISTimedActionQueue.addAfter(self, bandageAction)
-- Setup cosmetic stuff -- Setup cosmetic stuff
self:setActionAnim("SawLog") self:setActionAnim("SawLog")
self:setOverrideHandModels(self.item:getStaticModel()) self:setOverrideHandModels(self.item:getStaticModel())
-- if self.character:getPrimaryHandItem() then
-- ISTimedActionQueue.add(ISUnequipAction:new(self.character, self.character:getPrimaryHandItem(), 2))
-- end
-- if self.character:getSecondaryHandItem() and self.character:getSecondaryHandItem() ~= self.character:getPrimaryHandItem() then
-- ISTimedActionQueue.add(ISUnequipAction:new(self.character, self.surgeon:getSecondaryHandItem(), 2))
-- end
-- if sawItem then
-- self:setOverrideHandModels(sawItem:getStaticModel(), nil)
-- end
end end
@@ -90,6 +89,8 @@ function CutLimbAction:perform()
local params = {patientNum = self.patient:getOnlineID(), limbName = self.limbName} local params = {patientNum = self.patient:getOnlineID(), limbName = self.limbName}
sendClientCommand(CommandsData.modules.TOC_RELAY, CommandsData.server.Relay.RelayExecuteAmputationAction, params ) sendClientCommand(CommandsData.modules.TOC_RELAY, CommandsData.server.Relay.RelayExecuteAmputationAction, params )
end end
ISBaseTimedAction.perform(self) ISBaseTimedAction.perform(self)
end end

View File

@@ -28,8 +28,30 @@ function TOC_DEBUG.printTable(table, indent)
end end
end end
---------------------------------
--* Random debug commands *--
function TOC_DEBUG.TestBodyDamage(id)
local StaticData = require("TOC/StaticData")
local pl = getPlayerByOnlineID(id)
local bd = pl:getBodyDamage()
TOC_DEBUG.print(tostring(bd))
if bd then
TOC_DEBUG.print("bd for " .. pl:getUsername() .. " exists")
local bptEnum = StaticData.BODYLOCS_IND_BPT["Hand_L"]
local bodyPart = bd:getBodyPart(bptEnum)
bodyPart:setBleeding(true)
bodyPart:setCut(true)
TOC_DEBUG.print(tostring(bodyPart))
end
end
---------------------------------
--* Debug server commands *-- --* Debug server commands *--
local CommandsData = require("TOC/CommandsData") local CommandsData = require("TOC/CommandsData")