From 4fb19ae5a6054ece317f7d12abc6f93e1fa2ca1c Mon Sep 17 00:00:00 2001 From: ZioPao Date: Mon, 13 Nov 2023 21:12:36 +0100 Subject: [PATCH] Working MP :) --- media/lua/client/TOC/ClientRelayCommands.lua | 2 +- .../lua/client/TOC/TimedActions/CutLimbAction.lua | 15 +++++++++++++-- media/lua/client/TOC/UI/CutLimbInteractions.lua | 4 ++-- media/lua/server/TOC/ServerRelayCommands.lua | 11 ++++++----- media/lua/shared/TOC/Debug.lua | 6 ++++++ 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/media/lua/client/TOC/ClientRelayCommands.lua b/media/lua/client/TOC/ClientRelayCommands.lua index 773821a..d1645e1 100644 --- a/media/lua/client/TOC/ClientRelayCommands.lua +++ b/media/lua/client/TOC/ClientRelayCommands.lua @@ -31,7 +31,7 @@ end ------------------------- local function OnServerRelayCommand(module, command, args) - if module == CommandsData.modules.TOC_ACTION and ClientRelayCommands[command] then + if module == CommandsData.modules.TOC_RELAY and ClientRelayCommands[command] then ClientRelayCommands[command](args) end end diff --git a/media/lua/client/TOC/TimedActions/CutLimbAction.lua b/media/lua/client/TOC/TimedActions/CutLimbAction.lua index 1ad9f1a..51fb28b 100644 --- a/media/lua/client/TOC/TimedActions/CutLimbAction.lua +++ b/media/lua/client/TOC/TimedActions/CutLimbAction.lua @@ -45,14 +45,25 @@ function CutLimbAction:start() self.handler:damageDuringAmputation() else -- Other player - ---@type relayDamageDuringAmputationParams + ----@type relayDamageDuringAmputationParams + + local params = {patientNum = self.patient:getOnlineID(), limbName = self.limbName} sendClientCommand(CommandsData.modules.TOC_RELAY, CommandsData.server.Relay.RelayDamageDuringAmputation, params ) end end function CutLimbAction:perform() - self.handler:execute() + if self.patient == self.character then + TOC_DEBUG.print("patient and surgeon are the same, executing on the client") + self.handler:execute(true) + else + TOC_DEBUG.print("patient and surgeon not the same, sending relay to server") + -- Other player + ---@type relayExecuteAmputationActionParams + 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/UI/CutLimbInteractions.lua b/media/lua/client/TOC/UI/CutLimbInteractions.lua index 86ea36a..3fab4b7 100644 --- a/media/lua/client/TOC/UI/CutLimbInteractions.lua +++ b/media/lua/client/TOC/UI/CutLimbInteractions.lua @@ -103,10 +103,10 @@ end function CutLimbHandler:perform(previousAction, itemType) --local item = self:getItemOfType(self.items.ITEMS, itemType) --previousAction = self:toPlayerInventory(item, previousAction) - + -- TODO This is broken like this! local limbName = BodyPartType.ToString(self.bodyPart:getType()) TOC_DEBUG.print("perform CutLimbHandler on " .. limbName) - local action = CutLimbAction:new(self:getPatient(), self:getDoctor(), limbName) + local action = CutLimbAction:new(self:getDoctor(),self:getPatient(), limbName) ISTimedActionQueue.add(action) end diff --git a/media/lua/server/TOC/ServerRelayCommands.lua b/media/lua/server/TOC/ServerRelayCommands.lua index d2b1711..d337a20 100644 --- a/media/lua/server/TOC/ServerRelayCommands.lua +++ b/media/lua/server/TOC/ServerRelayCommands.lua @@ -1,3 +1,4 @@ +require ("TOC/Debug") local CommandsData = require("TOC/CommandsData") -------------------------------------------- @@ -9,11 +10,11 @@ local ServerRelayCommands = {} ---@param surgeonPl IsoPlayer ---@param args relayDamageDuringAmputationParams function ServerRelayCommands.RelayDamageDuringAmputation(surgeonPl, args) - local patientPl = getSpecificPlayer(args.patientNum) + local patientPl = getPlayerByOnlineID(args.patientNum) local surgeonNum = surgeonPl:getOnlineID() ---@type receiveDamageDuringAmputationParams - local params = {surgeonNum = surgeonNum, args.limbName} + local params = {surgeonNum = surgeonNum, limbName = args.limbName} sendServerCommand(patientPl, CommandsData.modules.TOC_RELAY, CommandsData.client.Relay.ReceiveDamageDuringAmputation, params) end @@ -21,11 +22,11 @@ end ---@param surgeonPl IsoPlayer ---@param args relayExecuteAmputationActionParams function ServerRelayCommands.RelayExecuteAmputationAction(surgeonPl, args) - local patientPl = getSpecificPlayer(args.patientNum) + local patientPl = getPlayerByOnlineID(args.patientNum) local surgeonNum = surgeonPl:getOnlineID() ---@type receiveDamageDuringAmputationParams - local params = {surgeonNum = surgeonNum, args.limbName} + local params = {surgeonNum = surgeonNum, limbName = args.limbName} sendServerCommand(patientPl, CommandsData.modules.TOC_RELAY, CommandsData.client.Relay.ReceiveExecuteAmputationAction, params) end @@ -34,7 +35,7 @@ end ------------------------- local function OnClientRelayCommand(module, command, playerObj, args) - if module == CommandsData.modules.TOC_ACTION and ServerRelayCommands[command] then + if module == CommandsData.modules.TOC_RELAY and ServerRelayCommands[command] then ServerRelayCommands[command](playerObj, args) end end diff --git a/media/lua/shared/TOC/Debug.lua b/media/lua/shared/TOC/Debug.lua index ff3d7b1..5866ead 100644 --- a/media/lua/shared/TOC/Debug.lua +++ b/media/lua/shared/TOC/Debug.lua @@ -40,4 +40,10 @@ end function TOC_DEBUG.printAllServerModData() sendClientCommand(CommandsData.modules.TOC_DEBUG, CommandsData.server.Debug.PrintAllTocData, {}) +end + +function TOC_DEBUG.testRelayDamage() + ---@type relayDamageDuringAmputationParams + local params = {limbName = "Hand_R", patientNum = getPlayer():getOnlineID()} + sendClientCommand(CommandsData.modules.TOC_RELAY, CommandsData.server.Relay.RelayDamageDuringAmputation, params) end \ No newline at end of file