Reworked some stuff for MP
This commit is contained in:
@@ -1,24 +1,27 @@
|
|||||||
local CommandsData = require("TOC/CommandsData")
|
local CommandsData = require("TOC/CommandsData")
|
||||||
|
local ModDataHandler = require("TOC/Handlers/ModDataHandler")
|
||||||
|
|
||||||
local ClientSyncCommands = {}
|
local ClientSyncCommands = {}
|
||||||
local moduleName = CommandsData.modules.TOC_SYNC
|
local moduleName = CommandsData.modules.TOC_SYNC
|
||||||
|
|
||||||
------------------------------
|
------------------------------
|
||||||
|
|
||||||
---Send the toc mod data to the server to relay it to someone else
|
---Send the toc mod data to the server to relay it to someone else
|
||||||
---@param args {surgeonNum : number}
|
---@param args sendPlayerDataParams
|
||||||
function ClientSyncCommands.SendPlayerData(args)
|
function ClientSyncCommands.SendPlayerData(args)
|
||||||
-- TODO get moddata and send it
|
-- TODO get moddata and send it
|
||||||
sendClientCommand(moduleName, CommandsData.server.Sync.RelayPlayerData, {surgeonNum = args.surgeonNum, tocData = {}})
|
|
||||||
|
---@type relayPlayerDataParams
|
||||||
|
local params = {surgeonNum = args.surgeonNum, tocData = {}}
|
||||||
|
sendClientCommand(moduleName, CommandsData.server.Sync.RelayPlayerData, params)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Receives and store the toc mod data from another player
|
---Receives and store the toc mod data from another player
|
||||||
---@param args {patientNum : number}
|
---@param args receivePlayerDataParams
|
||||||
function ClientSyncCommands.ReceivePlayerData(args)
|
function ClientSyncCommands.ReceivePlayerData(args)
|
||||||
local patientPl = getSpecificPlayer(args.patientNum)
|
local patientPl = getSpecificPlayer(args.patientNum)
|
||||||
local patientUsername patientPl:getUsername()
|
local patientUsername patientPl:getUsername()
|
||||||
|
ModDataHandler.AddExternalTocData(patientUsername, args.tocData)
|
||||||
|
|
||||||
-- TODO Save the data somewhere that makes sense.
|
|
||||||
end
|
end
|
||||||
|
|
||||||
------------------------------
|
------------------------------
|
||||||
|
|||||||
@@ -76,7 +76,10 @@ function AmputationHandler:execute(damagePlayer)
|
|||||||
|
|
||||||
|
|
||||||
-- Set the data in modData
|
-- Set the data in modData
|
||||||
ModDataHandler.GetInstance():setCutLimb(self.limbName, false, false, false, surgeonFactor)
|
-- TODO This could be run on another player!
|
||||||
|
local modDataHandler = ModDataHandler.GetInstance()
|
||||||
|
modDataHandler:setCutLimb(self.limbName, false, false, false, surgeonFactor)
|
||||||
|
modDataHandler:apply()
|
||||||
|
|
||||||
-- Give the player the correct amputation item
|
-- Give the player the correct amputation item
|
||||||
ItemsHandler.DeleteOldAmputationItem(self.patient, self.limbName)
|
ItemsHandler.DeleteOldAmputationItem(self.patient, self.limbName)
|
||||||
@@ -86,7 +89,7 @@ function AmputationHandler:execute(damagePlayer)
|
|||||||
PlayerHandler.AddLocalAmputatedLimb(self.limbName)
|
PlayerHandler.AddLocalAmputatedLimb(self.limbName)
|
||||||
|
|
||||||
-- Set the highest amputation and caches them.
|
-- Set the highest amputation and caches them.
|
||||||
ISHealthPanel.GetHighestAmputation()
|
--ISHealthPanel.GetHighestAmputation()
|
||||||
end
|
end
|
||||||
|
|
||||||
---Deletes the instance
|
---Deletes the instance
|
||||||
@@ -98,7 +101,7 @@ end
|
|||||||
function AmputationHandler.UpdateCicatrization()
|
function AmputationHandler.UpdateCicatrization()
|
||||||
if ModDataHandler.GetInstance():getIsAnyLimbCut() == false then return end
|
if ModDataHandler.GetInstance():getIsAnyLimbCut() == false then return end
|
||||||
|
|
||||||
|
-- TODO Update cicatrization
|
||||||
end
|
end
|
||||||
|
|
||||||
return AmputationHandler
|
return AmputationHandler
|
||||||
@@ -109,7 +109,7 @@ function ISInventoryPane:refreshContainer()
|
|||||||
for i=1, #self.itemslist do
|
for i=1, #self.itemslist do
|
||||||
local cItem = self.itemslist[i]
|
local cItem = self.itemslist[i]
|
||||||
if cItem and cItem.cat == "Amputation" then
|
if cItem and cItem.cat == "Amputation" then
|
||||||
TOC_DEBUG.print("current item is an amputation, removing it from the list")
|
TOC_DEBUG.print("Refreshing container - current item is an amputation, removing it from the list of the container")
|
||||||
table.remove(self.itemslist, i)
|
table.remove(self.itemslist, i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,35 +1,67 @@
|
|||||||
|
local CommandsData = require("TOC/CommandsData")
|
||||||
local StaticData = require("TOC/StaticData")
|
local StaticData = require("TOC/StaticData")
|
||||||
|
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
--- Handle all mod data related stuff
|
--- Handle all mod data related stuff
|
||||||
---@class ModDataHandler
|
---@class ModDataHandler
|
||||||
---@field playerObj IsoPlayer
|
---@field username string
|
||||||
---@field tocData tocModData
|
---@field tocData tocModData
|
||||||
local ModDataHandler = {}
|
local ModDataHandler = {}
|
||||||
ModDataHandler.instances = {}
|
ModDataHandler.instances = {}
|
||||||
|
|
||||||
|
-- Instead of requiring a player, to make it compatible in a MP env, we should require the table containing the modData for the init
|
||||||
function ModDataHandler.AddExternalTocData(username, tocData)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
---@param username string
|
---@param username string
|
||||||
---@param tocData tocModData
|
---@param isResetForced boolean?
|
||||||
---@return ModDataHandler
|
---@return ModDataHandler
|
||||||
function ModDataHandler:new(username, tocData)
|
function ModDataHandler:new(username, isResetForced)
|
||||||
local o = {}
|
local o = {}
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
self.__index = self
|
self.__index = self
|
||||||
-- Instead of requiring a player, to make it compatible in a MP env, we should require the table containing the modData for the init
|
o.username = username
|
||||||
|
local key = CommandsData.GetKey(username)
|
||||||
|
|
||||||
|
ModData.request(key)
|
||||||
|
o.tocData = ModData.get(key)
|
||||||
|
|
||||||
|
if isResetForced or o.tocData == nil or o.tocData.Hand_L == nil or o.tocData.Hand_L.isCut == nil then
|
||||||
|
TOC_DEBUG.print("tocData in ModDataHandler for " .. username .. " is nil, creating it now")
|
||||||
|
self:setup(key)
|
||||||
|
end
|
||||||
|
|
||||||
o.tocData = tocData
|
|
||||||
ModDataHandler.instances[username] = o
|
ModDataHandler.instances[username] = o
|
||||||
|
|
||||||
return o
|
return o
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Setup a new toc mod data data class
|
||||||
|
---@param key string
|
||||||
|
function ModDataHandler:setup(key)
|
||||||
|
|
||||||
|
---@type tocModData
|
||||||
|
self.tocData = {
|
||||||
|
-- Generic stuff that does not belong anywhere else
|
||||||
|
isIgnoredPartInfected = false,
|
||||||
|
isAnyLimbCut = false
|
||||||
|
}
|
||||||
|
|
||||||
|
---@type partData
|
||||||
|
local defaultParams = {isCut = false, isInfected = false, isOperated = false, isCicatrized = false, isCauterized = false, isVisible = false}
|
||||||
|
|
||||||
|
-- Initialize limbs
|
||||||
|
for i=1, #StaticData.LIMBS_STRINGS do
|
||||||
|
local limbName = StaticData.LIMBS_STRINGS[i]
|
||||||
|
self.tocData[limbName] = {}
|
||||||
|
self:setLimbParams(StaticData.LIMBS_STRINGS[i], defaultParams, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Add it to global mod data
|
||||||
|
ModData.add(key, self.tocData)
|
||||||
|
|
||||||
|
-- Transmit it to the server
|
||||||
|
ModData.transmit(key)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-----------------
|
-----------------
|
||||||
@@ -137,17 +169,23 @@ function ModDataHandler:setLimbParams(limbName, ampStatus, cicatrizationTime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--* Global Mod Data Apply *--
|
||||||
|
|
||||||
|
function ModDataHandler:apply()
|
||||||
|
ModData.transmit(CommandsData.GetKey(self.username))
|
||||||
|
end
|
||||||
|
|
||||||
---@param username string?
|
---@param username string?
|
||||||
---@return ModDataHandler?
|
---@return ModDataHandler
|
||||||
function ModDataHandler.GetInstance(username)
|
function ModDataHandler.GetInstance(username)
|
||||||
|
if username == nil then
|
||||||
|
username = getPlayer():getUsername()
|
||||||
|
end
|
||||||
|
|
||||||
if username == nil then username = getPlayer():getUsername() end
|
if ModDataHandler.instances[username] == nil then
|
||||||
|
return ModDataHandler:new(username)
|
||||||
if ModDataHandler.instances[username] ~= nil then
|
|
||||||
return ModDataHandler.instances[username]
|
|
||||||
else
|
else
|
||||||
return nil -- TODO This isn't exactly good
|
return ModDataHandler.instances[username]
|
||||||
--return ModDataHandler:new(getPlayer())
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -15,61 +15,36 @@ local StaticData = require("TOC/StaticData")
|
|||||||
---@field playerObj IsoPlayer
|
---@field playerObj IsoPlayer
|
||||||
local PlayerHandler = {}
|
local PlayerHandler = {}
|
||||||
|
|
||||||
|
PlayerHandler.amputatedLimbs = {}
|
||||||
|
|
||||||
|
|
||||||
---Setup the Player Handler and modData
|
---Setup the Player Handler and modData
|
||||||
---@param _ nil
|
|
||||||
---@param playerObj IsoPlayer
|
---@param playerObj IsoPlayer
|
||||||
---@param isForced boolean?
|
---@param isForced boolean?
|
||||||
function PlayerHandler.InitializePlayer(_, playerObj, isForced)
|
function PlayerHandler.InitializePlayer(playerObj, isForced)
|
||||||
PlayerHandler.SetupModData(playerObj, isForced)
|
|
||||||
PlayerHandler.playerObj = playerObj
|
|
||||||
|
|
||||||
|
local username = playerObj:getUsername()
|
||||||
|
TOC_DEBUG.print("initializing " .. username)
|
||||||
|
local modDataHandler = ModDataHandler:new(username, isForced)
|
||||||
|
PlayerHandler.playerObj = playerObj
|
||||||
-- Calculate amputated limbs at startup
|
-- Calculate amputated limbs at startup
|
||||||
PlayerHandler.amputatedLimbs = {}
|
PlayerHandler.amputatedLimbs[username] = {}
|
||||||
|
|
||||||
for i=1, #StaticData.LIMBS_STRINGS do
|
for i=1, #StaticData.LIMBS_STRINGS do
|
||||||
local limbName = StaticData.LIMBS_STRINGS[i]
|
local limbName = StaticData.LIMBS_STRINGS[i]
|
||||||
if ModDataHandler.GetInstance():getIsCut(limbName) then
|
if modDataHandler:getIsCut(limbName) then
|
||||||
PlayerHandler.AddLocalAmputatedLimb(limbName)
|
PlayerHandler.AddLocalAmputatedLimb(username, limbName)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Since isForced is used to reset an existing player data, we're gonna clean their ISHealthPanel table too
|
-- Since isForced is used to reset an existing player data, we're gonna clean their ISHealthPanel table too
|
||||||
if isForced then
|
if isForced then
|
||||||
ISHealthPanel.highestAmputations = {}
|
--ISHealthPanel.highestAmputations = {}
|
||||||
local ItemsHandler = require("TOC/Handlers/ItemsHandler")
|
local ItemsHandler = require("TOC/Handlers/ItemsHandler")
|
||||||
ItemsHandler.DeleteAllOldAmputationItems(playerObj)
|
ItemsHandler.DeleteAllOldAmputationItems(playerObj)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---Setup TOC mod data to a local client
|
|
||||||
---@param playerObj IsoPlayer
|
|
||||||
---@param isForced boolean?
|
|
||||||
function PlayerHandler.SetupModData(playerObj, isForced)
|
|
||||||
local tocData = playerObj:getModData()[StaticData.MOD_NAME]
|
|
||||||
if isForced or tocData == nil or tocData.Hand_L == nil or tocData.Hand_L.isCut == nil then
|
|
||||||
local modData = playerObj:getModData()
|
|
||||||
modData[StaticData.MOD_NAME] = {
|
|
||||||
-- Generic stuff that does not belong anywhere else
|
|
||||||
isIgnoredPartInfected = false,
|
|
||||||
isAnyLimbCut = false
|
|
||||||
}
|
|
||||||
|
|
||||||
---@type partData
|
|
||||||
local defaultParams = {isCut = false, isInfected = false, isOperated = false, isCicatrized = false, isCauterized = false, isVisible = false}
|
|
||||||
|
|
||||||
-- We're gonna make a instance of ModDataHandler to setup this player
|
|
||||||
local plUsername = playerObj:getUsername()
|
|
||||||
local dataHandler = ModDataHandler:new(plUsername, modData[StaticData.MOD_NAME])
|
|
||||||
|
|
||||||
-- Initialize limbs
|
|
||||||
for i=1, #StaticData.LIMBS_STRINGS do
|
|
||||||
local limbName = StaticData.LIMBS_STRINGS[i]
|
|
||||||
modData[StaticData.MOD_NAME][limbName] = {}
|
|
||||||
dataHandler:setLimbParams(StaticData.LIMBS_STRINGS[i], defaultParams, 0)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
---Handles the traits
|
---Handles the traits
|
||||||
---@param playerObj IsoPlayer
|
---@param playerObj IsoPlayer
|
||||||
function PlayerHandler.ManageTraits(playerObj)
|
function PlayerHandler.ManageTraits(playerObj)
|
||||||
@@ -87,9 +62,9 @@ end
|
|||||||
|
|
||||||
---Cache the currently amputated limbs
|
---Cache the currently amputated limbs
|
||||||
---@param limbName string
|
---@param limbName string
|
||||||
function PlayerHandler.AddLocalAmputatedLimb(limbName)
|
function PlayerHandler.AddLocalAmputatedLimb(username, limbName)
|
||||||
TOC_DEBUG.print("added " .. limbName .. " to known amputated limbs")
|
TOC_DEBUG.print("added " .. limbName .. " to known amputated limbs for " .. username)
|
||||||
table.insert(PlayerHandler.amputatedLimbs, limbName) -- TODO This should be player specific, not generic
|
table.insert(PlayerHandler.amputatedLimbs[username], limbName) -- TODO This should be player specific, not generic
|
||||||
end
|
end
|
||||||
|
|
||||||
--* Getters *--
|
--* Getters *--
|
||||||
@@ -108,16 +83,18 @@ function PlayerHandler.CheckInfection(character)
|
|||||||
-- This fucking event barely works. Bleeding seems to be the only thing that triggers it
|
-- This fucking event barely works. Bleeding seems to be the only thing that triggers it
|
||||||
if character ~= getPlayer() then return end
|
if character ~= getPlayer() then return end
|
||||||
local bd = character:getBodyDamage()
|
local bd = character:getBodyDamage()
|
||||||
|
local modDataHandler = ModDataHandler.GetInstance()
|
||||||
|
|
||||||
for i=1, #StaticData.LIMBS_STRINGS do
|
for i=1, #StaticData.LIMBS_STRINGS do
|
||||||
local limbName = StaticData.LIMBS_STRINGS[i]
|
local limbName = StaticData.LIMBS_STRINGS[i]
|
||||||
local bptEnum = StaticData.BODYPARTSTYPES_ENUM[limbName]
|
local bptEnum = StaticData.BODYPARTSTYPES_ENUM[limbName]
|
||||||
local bodyPart = bd:getBodyPart(bptEnum)
|
local bodyPart = bd:getBodyPart(bptEnum)
|
||||||
|
|
||||||
if bodyPart:bitten() or bodyPart:IsInfected() then
|
if bodyPart:bitten() or bodyPart:IsInfected() then
|
||||||
if ModDataHandler.GetInstance():getIsCut(limbName) then
|
if modDataHandler:getIsCut(limbName) then
|
||||||
bodyPart:SetBitten(false)
|
bodyPart:SetBitten(false)
|
||||||
else
|
else
|
||||||
ModDataHandler.GetInstance():setIsInfected(limbName, true)
|
modDataHandler:setIsInfected(limbName, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -40,10 +40,17 @@ function Main.Start()
|
|||||||
Main.SetupTraits()
|
Main.SetupTraits()
|
||||||
|
|
||||||
-- Starts initialization for local client
|
-- Starts initialization for local client
|
||||||
Events.OnCreatePlayer.Add(PlayerHandler.InitializePlayer)
|
Events.OnGameStart.Add(Main.Initialize)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function Main.Initialize()
|
||||||
|
local pl = getPlayer()
|
||||||
|
PlayerHandler.InitializePlayer(pl, false)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--* Events *--
|
--* Events *--
|
||||||
|
|
||||||
Events.OnGameBoot.Add(Main.Start)
|
Events.OnGameBoot.Add(Main.Start)
|
||||||
@@ -11,7 +11,7 @@ TestFramework.registerTestModule("Functionality", "PlayerHandler", function()
|
|||||||
local Tests = {}
|
local Tests = {}
|
||||||
function Tests.InitializePlayer()
|
function Tests.InitializePlayer()
|
||||||
local pl = getPlayer()
|
local pl = getPlayer()
|
||||||
PlayerHandler.InitializePlayer(_, pl, true)
|
PlayerHandler.InitializePlayer(pl, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Tests.SetMaxPerks()
|
function Tests.SetMaxPerks()
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ local PlayerHandler = require("TOC/Handlers/PlayerHandler")
|
|||||||
local StaticData = require("TOC/StaticData")
|
local StaticData = require("TOC/StaticData")
|
||||||
local CommonMethods = require("TOC/CommonMethods")
|
local CommonMethods = require("TOC/CommonMethods")
|
||||||
local ModDataHandler = require("TOC/Handlers/ModDataHandler")
|
local ModDataHandler = require("TOC/Handlers/ModDataHandler")
|
||||||
|
local CommandsData = require("TOC/CommandsData")
|
||||||
|
|
||||||
---@diagnostic disable: duplicate-set-field
|
---@diagnostic disable: duplicate-set-field
|
||||||
local CutLimbHandler = require("TOC/UI/CutLimbInteractions")
|
local CutLimbHandler = require("TOC/UI/CutLimbInteractions")
|
||||||
@@ -44,23 +45,35 @@ end
|
|||||||
|
|
||||||
--* Modification to handle visible amputation on the health menu *--
|
--* Modification to handle visible amputation on the health menu *--
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function ISHealthPanel:setHighestAmputation()
|
function ISHealthPanel:setHighestAmputation()
|
||||||
|
|
||||||
|
--TOC_DEBUG.print("setHighestAmputation")
|
||||||
|
|
||||||
|
if PlayerHandler.amputatedLimbs == nil or PlayerHandler.amputatedLimbs[self.tocUsername] then
|
||||||
|
TOC_DEBUG.print("PlayerHandler.amputatedLimbs is still nil or wasn't initialized for that player")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if self.otherPlayer ~= nil then
|
if self.otherPlayer ~= nil then
|
||||||
self.tocUsername = self.otherPlayer:getUsername()
|
self.tocUsername = self.otherPlayer:getUsername()
|
||||||
else
|
else
|
||||||
self.tocUsername = self.character:getUsername()
|
self.tocUsername = self.character:getUsername()
|
||||||
end
|
end
|
||||||
|
|
||||||
ISHealthPanel.highestAmputations[self.tocUsername] = {}
|
self.highestAmputations[self.tocUsername] = {}
|
||||||
|
TOC_DEBUG.print("Searching highest amputations for " .. self.tocUsername)
|
||||||
local modDataHandler = ModDataHandler.GetInstance(self.tocUsername)
|
local modDataHandler = ModDataHandler.GetInstance(self.tocUsername)
|
||||||
if modDataHandler == nil then return end -- TODO Test this
|
if modDataHandler == nil then
|
||||||
|
TOC_DEBUG.print("ModDataHandler not found for " .. self.tocUsername)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
for i=1, #PlayerHandler.amputatedLimbs do
|
for i=1, #PlayerHandler.amputatedLimbs do
|
||||||
local limbName = PlayerHandler.amputatedLimbs[i]
|
local limbName = PlayerHandler.amputatedLimbs[i]
|
||||||
local index = CommonMethods.GetSide(limbName)
|
local index = CommonMethods.GetSide(limbName)
|
||||||
if modDataHandler:getIsCut(limbName) and modDataHandler:getIsVisible(limbName) then
|
if modDataHandler:getIsCut(limbName) and modDataHandler:getIsVisible(limbName) then
|
||||||
ISHealthPanel.highestAmputations[index] = limbName
|
TOC_DEBUG.print("found high amputation " .. limbName)
|
||||||
|
self.highestAmputations[self.tocUsername][index] = limbName
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -73,6 +86,7 @@ function ISHealthPanel:initialise()
|
|||||||
self.sexPl = "Male"
|
self.sexPl = "Male"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.highestAmputations = {}
|
||||||
self:setHighestAmputation()
|
self:setHighestAmputation()
|
||||||
|
|
||||||
og_ISHealthPanel_initialise(self)
|
og_ISHealthPanel_initialise(self)
|
||||||
@@ -87,6 +101,12 @@ function ISHealthPanel:setOtherPlayer(playerObj)
|
|||||||
|
|
||||||
-- Since setOtherPlayer may be run after initialise (or always), we need to recheck it after.
|
-- Since setOtherPlayer may be run after initialise (or always), we need to recheck it after.
|
||||||
self:setHighestAmputation()
|
self:setHighestAmputation()
|
||||||
|
|
||||||
|
-- TODO Request from server!
|
||||||
|
|
||||||
|
-----@type askPlayerDataParams
|
||||||
|
--local params = {patientNum = playerObj:getOnlineID()}
|
||||||
|
--sendClientCommand(CommandsData.modules.TOC_SYNC, CommandsData.server.Sync.AskPlayerData, params)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -96,20 +116,21 @@ function ISHealthPanel:render()
|
|||||||
|
|
||||||
-- TODO Handle another player health panel
|
-- TODO Handle another player health panel
|
||||||
|
|
||||||
if ISHealthPanel.highestAmputations[self.tocUsername] then
|
if self.highestAmputations ~= nil and self.highestAmputations[self.tocUsername] ~= nil then
|
||||||
-- Left Texture
|
-- Left Texture
|
||||||
if ISHealthPanel.highestAmputations[self.tocUsername]["L"] then
|
if self.highestAmputations[self.tocUsername]["L"] then
|
||||||
local textureL = StaticData.HEALTH_PANEL_TEXTURES[self.sexPl][ISHealthPanel.highestAmputations["L"]]
|
local textureL = StaticData.HEALTH_PANEL_TEXTURES[self.sexPl][self.highestAmputations[self.tocUsername]["L"]]
|
||||||
self:drawTexture(textureL, self.healthPanel.x/2 - 2, self.healthPanel.y/2, 1, 1, 0, 0)
|
self:drawTexture(textureL, self.healthPanel.x/2 - 2, self.healthPanel.y/2, 1, 1, 0, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Right Texture
|
-- Right Texture
|
||||||
if ISHealthPanel.highestAmputations[self.tocUsername]["R"] then
|
if self.highestAmputations["R"] then
|
||||||
local textureR = StaticData.HEALTH_PANEL_TEXTURES[self.sexPl][ISHealthPanel.highestAmputations["R"]]
|
local textureR = StaticData.HEALTH_PANEL_TEXTURES[self.sexPl][self.highestAmputations[self.tocUsername]["R"]]
|
||||||
self:drawTexture(textureR, self.healthPanel.x/2 + 2, self.healthPanel.y/2, 1, 1, 0, 0)
|
self:drawTexture(textureR, self.healthPanel.x/2 + 2, self.healthPanel.y/2, 1, 1, 0, 0)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
ISHealthPanel.GetHighestAmputation(self.tocUsername)
|
self:setHighestAmputation()
|
||||||
|
--ISHealthPanel.GetHighestAmputation(self.tocUsername)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
54
media/lua/server/TOC/ServerDataCommands.lua
Normal file
54
media/lua/server/TOC/ServerDataCommands.lua
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
-- TODO Switch EVERYTHING to global mod data
|
||||||
|
|
||||||
|
local CommandsData = require("TOC/CommandsData")
|
||||||
|
|
||||||
|
local ServerDataCommands = {}
|
||||||
|
local moduleName = "test_sync"
|
||||||
|
|
||||||
|
|
||||||
|
local function PrintModDataTable(key, table)
|
||||||
|
print("Received key: " .. key)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Events.OnReceiveGlobalModData.Add(PrintModDataTable)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- TODO Consider delays
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- TODO Use transmit from client
|
||||||
|
-- ---comment
|
||||||
|
-- ---@param playerObj IsoPlayer
|
||||||
|
-- ---@param args any
|
||||||
|
-- function ServerDataCommands.AddTable(playerObj, args)
|
||||||
|
-- ModData.add(GetKey(playerObj), args.tocData)
|
||||||
|
-- end
|
||||||
|
|
||||||
|
|
||||||
|
-- function ServerDataCommands.GetTable(playerObj, args)
|
||||||
|
-- local requestedPlayer = getSpecificPlayer(args.playerNum)
|
||||||
|
-- local data = ModData.get(CommandsData.GetKey(requestedPlayer))
|
||||||
|
|
||||||
|
-- -- TODO Request from that client again just to be sure that it's synced?
|
||||||
|
|
||||||
|
-- sendServerCommand()
|
||||||
|
-- end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
------------------------------
|
||||||
|
|
||||||
|
-- local function OnClientDataCommand(module, command, playerObj, args)
|
||||||
|
-- if module == moduleName and ServerDataCommands[command] then
|
||||||
|
-- ServerDataCommands[command](playerObj, args)
|
||||||
|
-- end
|
||||||
|
-- end
|
||||||
|
|
||||||
|
-- Events.OnClientCommand.Add(OnClientDataCommand)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -10,20 +10,25 @@ local moduleName = CommandsData.modules.TOC_SYNC
|
|||||||
|
|
||||||
---A client has asked the server to ask another client to send its toc mod data
|
---A client has asked the server to ask another client to send its toc mod data
|
||||||
---@param surgeonPl IsoPlayer
|
---@param surgeonPl IsoPlayer
|
||||||
---@param args {patientNum : number}
|
---@param args askPlayerDataParams
|
||||||
function ServerSyncCommands.AskPlayerData(surgeonPl, args)
|
function ServerSyncCommands.AskPlayerData(surgeonPl, args)
|
||||||
local patientPl = getSpecificPlayer(args.patientNum)
|
local patientPl = getSpecificPlayer(args.patientNum)
|
||||||
local surgeonNum = surgeonPl:getOnlineID()
|
|
||||||
sendServerCommand(patientPl, moduleName, CommandsData.client.Sync.SendPlayerData, {surgeonNum = surgeonNum})
|
---@type sendPlayerDataParams
|
||||||
|
local params = {surgeonNum = surgeonPl:getOnlineID()}
|
||||||
|
sendServerCommand(patientPl, moduleName, CommandsData.client.Sync.SendPlayerData, params)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Relay the toc mod data from a certain player to another one
|
---Relay the toc mod data from a certain player to another one
|
||||||
---@param patientPl IsoPlayer
|
---@param patientPl IsoPlayer
|
||||||
---@param args {surgeonNum : number, tocData : tocModData}
|
---@param args relayPlayerDataParams
|
||||||
function ServerSyncCommands.RelayPlayerData(patientPl, args)
|
function ServerSyncCommands.RelayPlayerData(patientPl, args)
|
||||||
local surgeonPl = getSpecificPlayer(args.surgeonNum)
|
local surgeonPl = getSpecificPlayer(args.surgeonNum)
|
||||||
local patientNum = patientPl:getOnlineID()
|
local patientNum = patientPl:getOnlineID()
|
||||||
sendServerCommand(surgeonPl, moduleName, CommandsData.client.Sync.ReceivePlayerData, {patientNum = patientNum, tocData = args.tocData})
|
|
||||||
|
---@type receivePlayerDataParams
|
||||||
|
local params = {patientNum = patientNum, tocData = args.tocData}
|
||||||
|
sendServerCommand(surgeonPl, moduleName, CommandsData.client.Sync.ReceivePlayerData, params)
|
||||||
end
|
end
|
||||||
|
|
||||||
------------------------------
|
------------------------------
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
-- TODO This part is still one of the weakest and we don't have a better solution yet
|
-- TODO This part is still one of the weakest and we don't have a better solution yet
|
||||||
|
require("TOC/Debug")
|
||||||
|
|
||||||
local function AddBodyLocationBefore(newLocation, moveToLocation)
|
local function AddBodyLocationBefore(newLocation, moveToLocation)
|
||||||
local group = BodyLocations.getGroup("Human")
|
local group = BodyLocations.getGroup("Human")
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
local StaticData = require("TOC/StaticData")
|
||||||
|
|
||||||
local CommandsData = {}
|
local CommandsData = {}
|
||||||
|
|
||||||
|
|
||||||
@@ -8,16 +10,23 @@ CommandsData.modules = {
|
|||||||
|
|
||||||
CommandsData.client = {
|
CommandsData.client = {
|
||||||
Sync = {
|
Sync = {
|
||||||
SendPlayerData = "SendPlayerData",
|
SendPlayerData = "SendPlayerData", ---@alias sendPlayerDataParams {surgeonNum : number}
|
||||||
ReceivePlayerData = "ReceivePlayerData"
|
ReceivePlayerData = "ReceivePlayerData" ---@alias receivePlayerDataParams {patientNum : number, tocData : tocModData}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandsData.server = {
|
CommandsData.server = {
|
||||||
Sync = {
|
Sync = {
|
||||||
AskPlayerData = "AskPlayerData",
|
AskPlayerData = "AskPlayerData", ---@alias askPlayerDataParams {patientNum : number}
|
||||||
RelayPlayerData = "RelayPlayerData"
|
RelayPlayerData = "RelayPlayerData" ---@alias relayPlayerDataParams {surgeonNum : number, tocData : tocModData}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
---Get the correct key for that particular player to be used in the global mod data table
|
||||||
|
---@param username string
|
||||||
|
---@return string
|
||||||
|
function CommandsData.GetKey(username)
|
||||||
|
return StaticData.MOD_NAME .. "_" .. username
|
||||||
|
end
|
||||||
|
|
||||||
return CommandsData
|
return CommandsData
|
||||||
Reference in New Issue
Block a user