From c9b41838be1c870054997138872a525d5d2059d8 Mon Sep 17 00:00:00 2001 From: ZioPao Date: Wed, 15 Nov 2023 11:07:15 +0100 Subject: [PATCH] Cleaning, bandages handling --- media/lua/client/TOC/CommonMethods.lua | 7 +---- .../client/TOC/Handlers/AmputationHandler.lua | 19 ++++++++++-- .../client/TOC/Handlers/CachedDataHandler.lua | 6 ++-- .../client/TOC/Handlers/ModDataHandler.lua | 2 +- .../client/TOC/Handlers/SurgeryHandler.lua | 31 +++++++++++++++++-- .../client/TOC/TimedActions/CutLimbAction.lua | 25 ++++++++------- .../{OperateAction.lua => SurgeryAction.lua} | 0 media/lua/shared/TOC/Debug.lua | 22 +++++++++++++ 8 files changed, 84 insertions(+), 28 deletions(-) rename media/lua/client/TOC/TimedActions/{OperateAction.lua => SurgeryAction.lua} (100%) diff --git a/media/lua/client/TOC/CommonMethods.lua b/media/lua/client/TOC/CommonMethods.lua index 22f626e..6b4fdea 100644 --- a/media/lua/client/TOC/CommonMethods.lua +++ b/media/lua/client/TOC/CommonMethods.lua @@ -7,10 +7,5 @@ function CommonMethods.GetSide(name) if string.find(name, "_L") then return "L" else return "R" end end ----comment ----@param bodyPart BodyPart -function CommonMethods.GetLimbNameFromBodyPart(bodyPart) - local bodyPartType = bodyPart:getType() - -end + return CommonMethods \ No newline at end of file diff --git a/media/lua/client/TOC/Handlers/AmputationHandler.lua b/media/lua/client/TOC/Handlers/AmputationHandler.lua index 20f90a3..f2e4462 100644 --- a/media/lua/client/TOC/Handlers/AmputationHandler.lua +++ b/media/lua/client/TOC/Handlers/AmputationHandler.lua @@ -56,6 +56,16 @@ function AmputationHandler.ApplyDamageDuringAmputation(player, limbName) bodyDamagePart:setBleedingTime(ZombRand(10, 20)) 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 *-- @@ -73,6 +83,7 @@ end ---Set the damage to the amputated area ---@param surgeonFactor number function AmputationHandler:damageAfterAmputation(surgeonFactor) + -- TODO Torniquet should reduce the damage in total, less blood loss local patientStats = self.patientPl:getStats() local bd = self.patientPl:getBodyDamage() local bodyPart = bd:getBodyPart(self.bodyPartType) @@ -95,9 +106,6 @@ function AmputationHandler:execute(damagePlayer) -- TODO Calculate surgeonStats -- TODO Cap it to a certain amount, it shouldn't be more than ...? local surgeonFactor = 1 - if damagePlayer then - self:damageAfterAmputation(surgeonFactor) - end -- Set the data in modData local modDataHandler = ModDataHandler.GetInstance() @@ -112,6 +120,11 @@ function AmputationHandler:execute(damagePlayer) local username = self.patientPl:getUsername() CachedDataHandler.AddAmputatedLimb(username, self.limbName) 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 ---Deletes the instance diff --git a/media/lua/client/TOC/Handlers/CachedDataHandler.lua b/media/lua/client/TOC/Handlers/CachedDataHandler.lua index 95c37b1..9d9bec0 100644 --- a/media/lua/client/TOC/Handlers/CachedDataHandler.lua +++ b/media/lua/client/TOC/Handlers/CachedDataHandler.lua @@ -6,7 +6,7 @@ local CommonMethods = require("TOC/CommonMethods") ---@class CachedDataHandler local CachedDataHandler = {} ----comment +---Reset everything cache related for that specific user ---@param username string function CachedDataHandler.Reset(username) CachedDataHandler.amputatedLimbs[username] = {} @@ -17,7 +17,7 @@ end CachedDataHandler.amputatedLimbs = {} -- 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 function CachedDataHandler.CalculateAmputatedLimbs(username) CachedDataHandler.amputatedLimbs[username] = {} @@ -30,7 +30,7 @@ function CachedDataHandler.CalculateAmputatedLimbs(username) 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 limbName string function CachedDataHandler.AddAmputatedLimb(username, limbName) diff --git a/media/lua/client/TOC/Handlers/ModDataHandler.lua b/media/lua/client/TOC/Handlers/ModDataHandler.lua index 31a6ec4..8ccb967 100644 --- a/media/lua/client/TOC/Handlers/ModDataHandler.lua +++ b/media/lua/client/TOC/Handlers/ModDataHandler.lua @@ -24,7 +24,7 @@ function ModDataHandler:new(username, isResetForced) ModData.request(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") o:setup(key) end diff --git a/media/lua/client/TOC/Handlers/SurgeryHandler.lua b/media/lua/client/TOC/Handlers/SurgeryHandler.lua index 8877652..c53fef5 100644 --- a/media/lua/client/TOC/Handlers/SurgeryHandler.lua +++ b/media/lua/client/TOC/Handlers/SurgeryHandler.lua @@ -1,10 +1,35 @@ local ModDataHandler = require("TOC/Handlers/ModDataHandler") +---@class SurgeryHandler +---@field type string local SurgeryHandler = {} -function SurgeryHandler.InstallProsthesis() - -- TODO Set stuff in mod data - +function SurgeryHandler:new(type) + local o = {} + setmetatable(o, self) + self.__index = self + + + -- TODO use getjob for this + o.type = type + + return o 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 \ No newline at end of file diff --git a/media/lua/client/TOC/TimedActions/CutLimbAction.lua b/media/lua/client/TOC/TimedActions/CutLimbAction.lua index d264e6e..6621ef9 100644 --- a/media/lua/client/TOC/TimedActions/CutLimbAction.lua +++ b/media/lua/client/TOC/TimedActions/CutLimbAction.lua @@ -1,6 +1,7 @@ require "TimedActions/ISBaseTimedAction" local AmputationHandler = require("TOC/Handlers/AmputationHandler") local CommandsData = require("TOC/CommandsData") +local StaticData = require("TOC/StaticData") ----------------------------- ---@class CutLimbAction : ISBaseTimedAction @@ -52,21 +53,19 @@ function CutLimbAction:start() sendClientCommand(CommandsData.modules.TOC_RELAY, CommandsData.server.Relay.RelayDamageDuringAmputation, params ) 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 self:setActionAnim("SawLog") 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 @@ -90,6 +89,8 @@ function CutLimbAction:perform() local params = {patientNum = self.patient:getOnlineID(), limbName = self.limbName} sendClientCommand(CommandsData.modules.TOC_RELAY, CommandsData.server.Relay.RelayExecuteAmputationAction, params ) end + + ISBaseTimedAction.perform(self) end diff --git a/media/lua/client/TOC/TimedActions/OperateAction.lua b/media/lua/client/TOC/TimedActions/SurgeryAction.lua similarity index 100% rename from media/lua/client/TOC/TimedActions/OperateAction.lua rename to media/lua/client/TOC/TimedActions/SurgeryAction.lua diff --git a/media/lua/shared/TOC/Debug.lua b/media/lua/shared/TOC/Debug.lua index 5866ead..0d018c6 100644 --- a/media/lua/shared/TOC/Debug.lua +++ b/media/lua/shared/TOC/Debug.lua @@ -28,8 +28,30 @@ function TOC_DEBUG.printTable(table, indent) 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 *-- local CommandsData = require("TOC/CommandsData")