This commit is contained in:
ZioPao
2023-11-13 03:15:37 +01:00
parent 980545a07e
commit deb6dcc056
9 changed files with 31 additions and 136 deletions

View File

@@ -1,36 +0,0 @@
local CommandsData = require("TOC/CommandsData")
local ModDataHandler = require("TOC/Handlers/ModDataHandler")
local ClientSyncCommands = {}
local moduleName = CommandsData.modules.TOC_SYNC
------------------------------
---Send the toc mod data to the server to relay it to someone else
---@param args sendPlayerDataParams
function ClientSyncCommands.SendPlayerData(args)
-- TODO get moddata and send it
---@type relayPlayerDataParams
local params = {surgeonNum = args.surgeonNum, tocData = {}}
sendClientCommand(moduleName, CommandsData.server.Sync.RelayPlayerData, params)
end
---Receives and store the toc mod data from another player
---@param args receivePlayerDataParams
function ClientSyncCommands.ReceivePlayerData(args)
local patientPl = getSpecificPlayer(args.patientNum)
local patientUsername patientPl:getUsername()
ModDataHandler.AddExternalTocData(patientUsername, args.tocData)
end
------------------------------
local function OnServerSyncCommand(module, command, args)
if module == moduleName and ClientSyncCommands[command] then
args = args or {}
ClientSyncCommands[command](args)
end
end
Events.OnServerCommand.Add(OnServerSyncCommand)

View File

@@ -5,9 +5,9 @@ local StaticData = require("TOC/StaticData")
---------------------------
-- TODO Add Bandages, Torniquet, etc.
--- This will be run EXCLUSIVELY on the client which is getting the amputation
--- Manages an amputation. Could be run on either clients
---@class AmputationHandler
---@field patient IsoPlayer
---@field patientPl IsoPlayer
---@field limbName string
---@field bodyPartType BodyPartType
---@field surgeonPl IsoPlayer?
@@ -22,13 +22,13 @@ function AmputationHandler:new(limbName, surgeonPl)
setmetatable(o, self)
self.__index = self
o.patient = getPlayer()
o.patientPl = getPlayer() -- TODO This isn't necessarily true anymore.
o.limbName = limbName
o.bodyPartType = BodyPartType[self.limbName]
if surgeonPl then
o.surgeonPl = surgeonPl
else
o.surgeonPl = o.patient
o.surgeonPl = o.patientPl
end
AmputationHandler.instance = o
@@ -41,7 +41,7 @@ end
---Starts bleeding from the point where the saw is being used
function AmputationHandler:damageDuringAmputation()
TOC_DEBUG.print("damage patient")
local bodyDamage = self.patient:getBodyDamage()
local bodyDamage = self.patientPl:getBodyDamage()
local bodyDamagePart = bodyDamage:getBodyPart(self.bodyPartType)
bodyDamagePart:setBleeding(true)
@@ -58,8 +58,8 @@ function AmputationHandler:execute(damagePlayer)
local surgeonFactor = 1
if damagePlayer == nil then damagePlayer = true end -- Default at true
if damagePlayer then
local patientStats = self.patient:getStats()
local bd = self.patient:getBodyDamage()
local patientStats = self.patientPl:getStats()
local bd = self.patientPl:getBodyDamage()
local bodyPart = bd:getBodyPart(self.bodyPartType)
local baseDamage = StaticData.LIMBS_BASE_DAMAGE[self.limbName]
@@ -76,20 +76,20 @@ function AmputationHandler:execute(damagePlayer)
-- Set the data in modData
-- TODO This could be run on another player!
local modDataHandler = ModDataHandler.GetInstance()
modDataHandler:setCutLimb(self.limbName, false, false, false, surgeonFactor)
modDataHandler:apply()
modDataHandler:apply() -- This will force rechecking the cached amputated limbs on the other client
-- Give the player the correct amputation item
ItemsHandler.DeleteOldAmputationItem(self.patient, self.limbName)
ItemsHandler.SpawnAmputationItem(self.patient, self.limbName)
-- Add it to the list of cut limbs
PlayerHandler.AddLocalAmputatedLimb(self.patient:getUsername(), self.limbName)
-- Set the highest amputation and caches them.
--ISHealthPanel.GetHighestAmputation()
-- 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
-- Add it to the list of cut limbs on this local client
PlayerHandler.AddLocalAmputatedLimb(self.patientPl:getUsername(), self.limbName)
end
---Deletes the instance

View File

@@ -3,7 +3,7 @@ local CommonMethods = require("TOC/CommonMethods")
---------------------------
--- Submodule to handle spawning the correct items after certain actions (ie: cutting a hand)
--- Submodule to handle spawning the correct items after certain actions (ie: cutting a hand). LOCAL ONLY!
---@class ItemsHandler
local ItemsHandler = {}

View File

@@ -70,7 +70,6 @@ end
---Cache the currently amputated limbs
---@param limbName string
---@private
function PlayerHandler.AddLocalAmputatedLimb(username, limbName)
TOC_DEBUG.print("added " .. limbName .. " to known amputated limbs for " .. username)
table.insert(PlayerHandler.amputatedLimbs[username], limbName) -- TODO This should be player specific, not generic

View File

@@ -42,7 +42,7 @@ function ISHealthPanel:doBodyPartContextMenu(bodyPart, x, y)
end
--* Modification to handle visible amputation on the health menu *--
--* Modifications to handle visible amputation on the health menu *--
function ISHealthPanel:setHighestAmputation()
@@ -90,8 +90,6 @@ function ISHealthPanel:initialise()
end
local og_ISHealthPanel_setOtherPlayer = ISHealthPanel.setOtherPlayer
---@param playerObj IsoPlayer
function ISHealthPanel:setOtherPlayer(playerObj)
og_ISHealthPanel_setOtherPlayer(self, playerObj)
@@ -141,10 +139,13 @@ function ISHealthPanel:prerender()
self.backgroundColor.a = 1
end
--- The medical check wrap the health panel into this. We need to override its color
local overrideBackgroundColor = true
local og_ISUIElement_wrapInCollapsableWindow = ISUIElement.wrapInCollapsableWindow
---@param title string
---@param resizable any
---@param subClass any
---@return any
function ISUIElement:wrapInCollapsableWindow(title, resizable, subClass)
local panel = og_ISUIElement_wrapInCollapsableWindow(self, title, resizable, subClass)
@@ -157,12 +158,6 @@ function ISUIElement:wrapInCollapsableWindow(title, resizable, subClass)
return panel
end
-- This is run when a player is trying the Medical Check action on another player
local og_ISMedicalCheckAction_perform = ISMedicalCheckAction.perform
function ISMedicalCheckAction:perform()