diff --git a/media/lua/client/TOC/ClientRelayCommands.lua b/media/lua/client/TOC/ClientRelayCommands.lua new file mode 100644 index 0000000..773821a --- /dev/null +++ b/media/lua/client/TOC/ClientRelayCommands.lua @@ -0,0 +1,39 @@ +local CommandsData = require("TOC/CommandsData") +local AmputationHandler = require("TOC/Handlers/AmputationHandler") +-------------------------------------------- + +local ClientRelayCommands = {} + +---comment +---@param limbName any +---@param surgeonNum any +---@return AmputationHandler +local function InitAmputationHandler(limbName, surgeonNum) + + -- TODO Pretty unclean + local surgeonPl = getSpecificPlayer(surgeonNum) + local handler = AmputationHandler:new(limbName, surgeonPl) + return handler +end + +---comment +---@param args receiveDamageDuringAmputationParams +function ClientRelayCommands.ReceiveDamageDuringAmputation(args) + local handler = InitAmputationHandler(args.limbName, args.surgeonNum) + handler:damageDuringAmputation() +end + +---@param args receiveExecuteAmputationActionParams +function ClientRelayCommands.ReceiveExecuteAmputationAction(args) + local handler = InitAmputationHandler(args.limbName, args.surgeonNum) + handler:execute(true) +end +------------------------- + +local function OnServerRelayCommand(module, command, args) + if module == CommandsData.modules.TOC_ACTION and ClientRelayCommands[command] then + ClientRelayCommands[command](args) + end +end + +Events.OnServerCommand.Add(OnServerRelayCommand) diff --git a/media/lua/client/TOC/Handlers/AmputationHandler.lua b/media/lua/client/TOC/Handlers/AmputationHandler.lua index 31f6cee..6787f6c 100644 --- a/media/lua/client/TOC/Handlers/AmputationHandler.lua +++ b/media/lua/client/TOC/Handlers/AmputationHandler.lua @@ -5,7 +5,7 @@ local StaticData = require("TOC/StaticData") --------------------------- -- TODO Add Bandages, Torniquet, etc. ---- Manages an amputation. Could be run on either clients +--- Manages an amputation. Will be run on the patient client ---@class AmputationHandler ---@field patientPl IsoPlayer ---@field limbName string @@ -22,7 +22,7 @@ function AmputationHandler:new(limbName, surgeonPl) setmetatable(o, self) self.__index = self - o.patientPl = getPlayer() -- TODO This isn't necessarily true anymore. + o.patientPl = getPlayer() o.limbName = limbName o.bodyPartType = BodyPartType[self.limbName] if surgeonPl then @@ -38,7 +38,22 @@ end --* Main methods *-- ----Starts bleeding from the point where the saw is being used +---Starts bleeding from the point where the saw is being used. Static since this could be used for online +---comment +---@param patientPl IsoPlayer +---@param bodyPartType BodyPartType +function AmputationHandler.DamageDuringAmputation(patientPl, bodyPartType) + TOC_DEBUG.print("damage patient") + local bodyDamage = patientPl:getBodyDamage() + local bodyDamagePart = bodyDamage:getBodyPart(bodyPartType) + + bodyDamagePart:setBleeding(true) + bodyDamagePart:setCut(true) + bodyDamagePart:setBleedingTime(ZombRand(10, 20)) + + + +end function AmputationHandler:damageDuringAmputation() TOC_DEBUG.print("damage patient") local bodyDamage = self.patientPl:getBodyDamage() @@ -81,13 +96,8 @@ function AmputationHandler:execute(damagePlayer) modDataHandler:apply() -- This will force rechecking the cached amputated limbs on the other client -- Give the player the correct amputation item - -- TODO We need to consider where this will be ran. - if self.patientPl == self.surgeonPl then - ItemsHandler.DeleteOldAmputationItem(self.patientPl, self.limbName) - ItemsHandler.SpawnAmputationItem(self.patientPl, self.limbName) - else - -- TODO Send server command to manage items and spawn on another player - end + ItemsHandler.DeleteOldAmputationItem(self.patientPl, self.limbName) + ItemsHandler.SpawnAmputationItem(self.patientPl, self.limbName) -- Add it to the list of cut limbs on this local client local username = self.patientPl:getUsername() diff --git a/media/lua/client/TOC/Handlers/CachedDataHandler.lua b/media/lua/client/TOC/Handlers/CachedDataHandler.lua index bdc29cc..fcee565 100644 --- a/media/lua/client/TOC/Handlers/CachedDataHandler.lua +++ b/media/lua/client/TOC/Handlers/CachedDataHandler.lua @@ -52,10 +52,10 @@ CachedDataHandler.highestAmputatedLimbs = {} function CachedDataHandler.CalculateHighestAmputatedLimbs(username) if CachedDataHandler.amputatedLimbs == nil or CachedDataHandler.amputatedLimbs[username] == nil then --- This function gets ran pretty early, we need to account for the Bob stuff - if username == "Bob" then - TOC_DEBUG.print("skip, Bob is default char") - return - end + -- if username == "Bob" then + -- TOC_DEBUG.print("skip, Bob is default char") + -- return + -- end TOC_DEBUG.print("Amputated limbs weren't calculated. Trying to calculate them now for " .. username) CachedDataHandler.CalculateAmputatedLimbs(username) diff --git a/media/lua/client/TOC/TimedActions/CutLimbAction.lua b/media/lua/client/TOC/TimedActions/CutLimbAction.lua index d8ff744..1ad9f1a 100644 --- a/media/lua/client/TOC/TimedActions/CutLimbAction.lua +++ b/media/lua/client/TOC/TimedActions/CutLimbAction.lua @@ -1,5 +1,6 @@ require "TimedActions/ISBaseTimedAction" local AmputationHandler = require("TOC/Handlers/AmputationHandler") +local CommandsData = require("TOC/CommandsData") ----------------------------- ---@class CutLimbAction : ISBaseTimedAction @@ -44,7 +45,9 @@ function CutLimbAction:start() self.handler:damageDuringAmputation() else -- Other player - -- TODO Send Damage + ---@type relayDamageDuringAmputationParams + local params = {patientNum = self.patient:getOnlineID(), limbName = self.limbName} + sendClientCommand(CommandsData.modules.TOC_RELAY, CommandsData.server.Relay.RelayDamageDuringAmputation, params ) end end diff --git a/media/lua/client/TOC/UI/HealthPanel.lua b/media/lua/client/TOC/UI/HealthPanel.lua index d76146f..d46e3bb 100644 --- a/media/lua/client/TOC/UI/HealthPanel.lua +++ b/media/lua/client/TOC/UI/HealthPanel.lua @@ -50,8 +50,11 @@ function ISHealthPanel:initialise() end local username = self.character:getUsername() - CachedDataHandler.CalculateHighestAmputatedLimbs(username) - self.highestAmputations = CachedDataHandler.GetHighestAmputatedLimbs(username) + if username ~= "Bob" then + CachedDataHandler.CalculateHighestAmputatedLimbs(username) + self.highestAmputations = CachedDataHandler.GetHighestAmputatedLimbs(username) + end + og_ISHealthPanel_initialise(self) end diff --git a/media/lua/server/TOC/ServerRelayCommands.lua b/media/lua/server/TOC/ServerRelayCommands.lua new file mode 100644 index 0000000..d2b1711 --- /dev/null +++ b/media/lua/server/TOC/ServerRelayCommands.lua @@ -0,0 +1,42 @@ +local CommandsData = require("TOC/CommandsData") +-------------------------------------------- + +local ServerRelayCommands = {} + +-- TODO We can easily make this a lot more simple without having functions + +---comment +---@param surgeonPl IsoPlayer +---@param args relayDamageDuringAmputationParams +function ServerRelayCommands.RelayDamageDuringAmputation(surgeonPl, args) + local patientPl = getSpecificPlayer(args.patientNum) + local surgeonNum = surgeonPl:getOnlineID() + + ---@type receiveDamageDuringAmputationParams + local params = {surgeonNum = surgeonNum, args.limbName} + sendServerCommand(patientPl, CommandsData.modules.TOC_RELAY, CommandsData.client.Relay.ReceiveDamageDuringAmputation, params) +end + +---comment +---@param surgeonPl IsoPlayer +---@param args relayExecuteAmputationActionParams +function ServerRelayCommands.RelayExecuteAmputationAction(surgeonPl, args) + local patientPl = getSpecificPlayer(args.patientNum) + local surgeonNum = surgeonPl:getOnlineID() + + ---@type receiveDamageDuringAmputationParams + local params = {surgeonNum = surgeonNum, args.limbName} + sendServerCommand(patientPl, CommandsData.modules.TOC_RELAY, CommandsData.client.Relay.ReceiveExecuteAmputationAction, params) +end + + + +------------------------- + +local function OnClientRelayCommand(module, command, playerObj, args) + if module == CommandsData.modules.TOC_ACTION and ServerRelayCommands[command] then + ServerRelayCommands[command](playerObj, args) + end +end + +Events.OnClientCommand.Add(OnClientRelayCommand) diff --git a/media/lua/shared/TOC/CommandsData.lua b/media/lua/shared/TOC/CommandsData.lua index a9ec89e..6b4a864 100644 --- a/media/lua/shared/TOC/CommandsData.lua +++ b/media/lua/shared/TOC/CommandsData.lua @@ -4,17 +4,27 @@ local StaticData = require("TOC/StaticData") local CommandsData = {} CommandsData.modules = { - TOC_DEBUG = "TOC_DEBUG" + TOC_DEBUG = "TOC_DEBUG", + TOC_RELAY = "TOC_RELAY" } CommandsData.client = { - + Relay = { + ReceiveDamageDuringAmputation = "ReceiveDamageDuringAmputation", ---@alias receiveDamageDuringAmputationParams {surgeonNum : number, limbName : string} + ReceiveExecuteAmputationAction = "ReceiveExecuteAmputationAction" ---@alias receiveExecuteAmputationActionParams {surgeonNum : number, limbName : string} + } } CommandsData.server = { Debug = { - PrintTocData = "PrintTocData", ---@alias printTocDataParams {username : string} + PrintTocData = "PrintTocData", ---@alias printTocDataParams {username : string} PrintAllTocData = "PrintAllTocData" + }, + + Relay = { + RelayDamageDuringAmputation = "RelayDamageDuringAmputation", ---@alias relayDamageDuringAmputationParams {patientNum : number, limbName : string} + RelayExecuteAmputationAction = "RelayExecuteAmputationAction" ---@alias relayExecuteAmputationActionParams {patientNum : number, limbName : string} + } }