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()

View File

@@ -1,8 +1,4 @@
if isClient() then return end
if isClient() then return end -- The event makes this necessary to prevent clients from running this file
local ServerDataHandler = {}
ServerDataHandler.modData = {}
@@ -14,7 +10,9 @@ function ServerDataHandler.GetTable(key)
return ServerDataHandler.modData[key]
end
---Add table to the ModData and a local table
---@param key string
---@param table tocModData
function ServerDataHandler.AddTable(key, table)
ModData.add(key, table) -- Add it to the server mod data
ServerDataHandler.modData[key] = table

View File

@@ -1,42 +0,0 @@
local CommandsData = require("TOC/CommandsData")
local ServerSyncCommands = {}
local moduleName = CommandsData.modules.TOC_SYNC
------------------------------
-- TODO This is gonna be impossible to manage. We need Global Mod Data to keep track of this kind of stuff at this point
---A client has asked the server to ask another client to send its toc mod data
---@param surgeonPl IsoPlayer
---@param args askPlayerDataParams
function ServerSyncCommands.AskPlayerData(surgeonPl, args)
local patientPl = getSpecificPlayer(args.patientNum)
---@type sendPlayerDataParams
local params = {surgeonNum = surgeonPl:getOnlineID()}
sendServerCommand(patientPl, moduleName, CommandsData.client.Sync.SendPlayerData, params)
end
---Relay the toc mod data from a certain player to another one
---@param patientPl IsoPlayer
---@param args relayPlayerDataParams
function ServerSyncCommands.RelayPlayerData(patientPl, args)
local surgeonPl = getSpecificPlayer(args.surgeonNum)
local patientNum = patientPl:getOnlineID()
---@type receivePlayerDataParams
local params = {patientNum = patientNum, tocData = args.tocData}
sendServerCommand(surgeonPl, moduleName, CommandsData.client.Sync.ReceivePlayerData, params)
end
------------------------------
local function OnClientSyncCommand(module, command, playerObj, args)
if module == moduleName and ServerSyncCommands[command] then
ServerSyncCommands[command](playerObj, args)
end
end
Events.OnClientCommand.Add(OnClientSyncCommand)

View File

@@ -1,27 +1,17 @@
local StaticData = require("TOC/StaticData")
------------------------
local CommandsData = {}
CommandsData.modules = {
TOC_SYNC = "TOC_SYNC",
TOC_DEBUG = "TOC_DEBUG"
}
CommandsData.client = {
Sync = {
SendPlayerData = "SendPlayerData", ---@alias sendPlayerDataParams {surgeonNum : number}
ReceivePlayerData = "ReceivePlayerData" ---@alias receivePlayerDataParams {patientNum : number, tocData : tocModData}
}
}
CommandsData.client = {}
CommandsData.server = {
Sync = {
AskPlayerData = "AskPlayerData", ---@alias askPlayerDataParams {patientNum : number}
RelayPlayerData = "RelayPlayerData" ---@alias relayPlayerDataParams {surgeonNum : number, tocData : tocModData}
},
Debug = {
PrintTocData = "PrintTocData", ---@alias printTocDataParams {username : string}
PrintAllTocData = "PrintAllTocData"
@@ -35,13 +25,5 @@ function CommandsData.GetKey(username)
return StaticData.MOD_NAME .. "_" .. username
end
-- ---comment
-- ---@param key string
-- ---@return string
-- function CommandsData.GetUsernameFromKey(key)
-- local subSize = #StaticData.MOD_NAME + 1
-- local username = key:sub(subSize)
-- return username
-- end
return CommandsData
return CommandsData

View File

@@ -60,7 +60,6 @@ local function AssembleUpperarmData(assembledName, side)
StaticData.PARTS_STRINGS.ForeArm .. "_" .. side }
end
for side, _ in pairs(StaticData.SIDES_STRINGS) do
for part, _ in pairs(StaticData.PARTS_STRINGS) do
local assembledName = part .. "_" .. side