Moved everything to common.
This commit is contained in:
32
common/media/lua/server/TOC/DebugCommands.lua
Normal file
32
common/media/lua/server/TOC/DebugCommands.lua
Normal file
@@ -0,0 +1,32 @@
|
||||
local CommandsData = require("TOC/CommandsData")
|
||||
local ServerDataHandler = require("TOC/ServerDataHandler")
|
||||
----------------------------
|
||||
|
||||
local DebugCommands = {}
|
||||
|
||||
---comment
|
||||
---@param playerObj IsoPlayer
|
||||
---@param args table
|
||||
function DebugCommands.PrintAllTocData(playerObj, args)
|
||||
TOC_DEBUG.printTable(ServerDataHandler.modData)
|
||||
end
|
||||
|
||||
---Print ALL TOC data
|
||||
---@param playerObj IsoPlayer
|
||||
---@param args printTocDataParams
|
||||
function DebugCommands.PrintTocData(playerObj, args)
|
||||
local key = CommandsData.GetKey(args.username)
|
||||
local tocData = ServerDataHandler.GetTable(key)
|
||||
TOC_DEBUG.printTable(tocData)
|
||||
end
|
||||
|
||||
--------------------
|
||||
|
||||
local function OnClientDebugCommand(module, command, playerObj, args)
|
||||
if module == CommandsData.modules.TOC_DEBUG and DebugCommands[command] then
|
||||
DebugCommands[command](playerObj, args)
|
||||
end
|
||||
end
|
||||
|
||||
Events.OnClientCommand.Add(OnClientDebugCommand)
|
||||
|
||||
31
common/media/lua/server/TOC/Distributions.lua
Normal file
31
common/media/lua/server/TOC/Distributions.lua
Normal file
@@ -0,0 +1,31 @@
|
||||
require('Items/Distributions')
|
||||
require('Items/SuburbsDistributions')
|
||||
|
||||
-- Insert Prosts and various items in the Medical Clinic loot table
|
||||
|
||||
local prosthesisLoot = {
|
||||
[1] = {
|
||||
name = "TOC.Prost_HookArm_L",
|
||||
chance = 3
|
||||
},
|
||||
|
||||
[2] = {
|
||||
name = "TOC.Prost_NormalArm_L",
|
||||
chance = 2
|
||||
},
|
||||
|
||||
[3] = {
|
||||
name = "TOC.Surg_Arm_Tourniquet_L",
|
||||
chance = 20
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for i=1, #prosthesisLoot do
|
||||
local tab = prosthesisLoot[i]
|
||||
table.insert(ProceduralDistributions.list.MedicalClinicTools.items, tab.name)
|
||||
table.insert(ProceduralDistributions.list.MedicalClinicTools.items, tab.chance)
|
||||
end
|
||||
|
||||
|
||||
|
||||
15
common/media/lua/server/TOC/LimitActionsController.lua
Normal file
15
common/media/lua/server/TOC/LimitActionsController.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
local CachedDataHandler = require("TOC/Handlers/CachedDataHandler")
|
||||
------------------------------
|
||||
|
||||
local og_ISObjectClickHandler_doClickSpecificObject = ISObjectClickHandler.doClickSpecificObject
|
||||
|
||||
---@param object IsoObject
|
||||
---@param playerNum any
|
||||
---@param playerObj IsoPlayer
|
||||
function ISObjectClickHandler.doClickSpecificObject(object, playerNum, playerObj)
|
||||
if CachedDataHandler.GetBothHandsFeasibility() then
|
||||
og_ISObjectClickHandler_doClickSpecificObject(object, playerNum, playerObj)
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
62
common/media/lua/server/TOC/ServerDataHandler.lua
Normal file
62
common/media/lua/server/TOC/ServerDataHandler.lua
Normal file
@@ -0,0 +1,62 @@
|
||||
if isClient() then return end -- The event makes this necessary to prevent clients from running this file
|
||||
local StaticData = require("TOC/StaticData")
|
||||
local CommandsData = require("TOC/CommandsData")
|
||||
------------------------
|
||||
|
||||
local ServerDataHandler = {}
|
||||
ServerDataHandler.modData = {}
|
||||
|
||||
---Get the server mod data table containing that player TOC data
|
||||
---@param key string
|
||||
---@return tocModDataType
|
||||
function ServerDataHandler.GetTable(key)
|
||||
return ServerDataHandler.modData[key]
|
||||
end
|
||||
|
||||
---Add table to the ModData and a local table
|
||||
---@param key string
|
||||
---@param table tocModDataType
|
||||
function ServerDataHandler.AddTable(key, table)
|
||||
-- Check if key is valid
|
||||
if not luautils.stringStarts(key, StaticData.MOD_NAME .. "_") then return end
|
||||
|
||||
TOC_DEBUG.print("Received TOC ModData: " .. tostring(key))
|
||||
--TOC_DEBUG.printTable(table)
|
||||
|
||||
-- Set that the data has been modified and it's updated on the server
|
||||
table.isUpdateFromServer = true -- FIX this is useless as of now
|
||||
|
||||
ModData.add(key, table) -- Add it to the server mod data
|
||||
ServerDataHandler.modData[key] = table
|
||||
|
||||
|
||||
-- Check integrity of table. if it doesn't contains toc data, it means that we received a reset
|
||||
if table.limbs == nil then return end
|
||||
|
||||
-- Since this could be triggered by a different client than the one referenced in the key, we're gonna
|
||||
-- apply the changes back to the key client again to be sure that everything is in sync
|
||||
local username = CommandsData.GetUsername(key)
|
||||
TOC_DEBUG.print("Reapplying to " .. username)
|
||||
|
||||
-- Since getPlayerFromUsername doesn't work in mp, we're gonna do this workaround. ew
|
||||
local onlinePlayers = getOnlinePlayers()
|
||||
local selectedPlayer
|
||||
for i=0, onlinePlayers:size() - 1 do
|
||||
|
||||
---@type IsoPlayer
|
||||
local player = onlinePlayers:get(i)
|
||||
if player:getUsername() == username then
|
||||
selectedPlayer = player
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
TOC_DEBUG.print("Player username from IsoPlayer: " .. selectedPlayer:getUsername())
|
||||
sendServerCommand(selectedPlayer, CommandsData.modules.TOC_RELAY, CommandsData.client.Relay.ReceiveApplyFromServer, {})
|
||||
|
||||
end
|
||||
|
||||
Events.OnReceiveGlobalModData.Add(ServerDataHandler.AddTable)
|
||||
|
||||
|
||||
return ServerDataHandler
|
||||
67
common/media/lua/server/TOC/ServerRelayCommands.lua
Normal file
67
common/media/lua/server/TOC/ServerRelayCommands.lua
Normal file
@@ -0,0 +1,67 @@
|
||||
require ("TOC/Debug")
|
||||
local CommandsData = require("TOC/CommandsData")
|
||||
--------------------------------------------
|
||||
|
||||
local ServerRelayCommands = {}
|
||||
|
||||
-- TODO We can easily make this a lot more simple without having functions
|
||||
|
||||
---Relay DamageDuringAmputation to another client
|
||||
---@param args relayDamageDuringAmputationParams
|
||||
function ServerRelayCommands.RelayDamageDuringAmputation(_, args)
|
||||
local patientPl = getPlayerByOnlineID(args.patientNum)
|
||||
|
||||
---@type receiveDamageDuringAmputationParams
|
||||
local params = {limbName = args.limbName}
|
||||
sendServerCommand(patientPl, CommandsData.modules.TOC_RELAY, CommandsData.client.Relay.ReceiveDamageDuringAmputation, params)
|
||||
end
|
||||
|
||||
---Relay ExecuteAmputationAction to another client
|
||||
---@param surgeonPl IsoPlayer
|
||||
---@param args relayExecuteAmputationActionParams
|
||||
function ServerRelayCommands.RelayExecuteAmputationAction(surgeonPl, args)
|
||||
local patientPl = getPlayerByOnlineID(args.patientNum)
|
||||
local surgeonNum = surgeonPl:getOnlineID()
|
||||
|
||||
---@type receiveDamageDuringAmputationParams
|
||||
local params = {surgeonNum = surgeonNum, limbName = args.limbName, damagePlayer = true}
|
||||
sendServerCommand(patientPl, CommandsData.modules.TOC_RELAY, CommandsData.client.Relay.ReceiveExecuteAmputationAction, params)
|
||||
end
|
||||
|
||||
--* ADMIN ONLY *--
|
||||
---Relay a local init from another client
|
||||
---@param adminObj IsoPlayer
|
||||
---@param args relayExecuteInitializationParams
|
||||
function ServerRelayCommands.RelayExecuteInitialization(adminObj, args)
|
||||
local patientPl = getPlayerByOnlineID(args.patientNum)
|
||||
sendServerCommand(patientPl, CommandsData.modules.TOC_RELAY, CommandsData.client.Relay.ReceiveExecuteInitialization, {})
|
||||
|
||||
end
|
||||
|
||||
---Relay a forced amputation to another client.
|
||||
---@param adminObj IsoPlayer
|
||||
---@param args relayForcedAmputationParams
|
||||
function ServerRelayCommands.RelayForcedAmputation(adminObj, args)
|
||||
local patientPl = getPlayerByOnlineID(args.patientNum)
|
||||
local adminNum = adminObj:getOnlineID()
|
||||
|
||||
---@type receiveDamageDuringAmputationParams
|
||||
local ampParams = {surgeonNum = adminNum, limbName = args.limbName, damagePlayer = false} -- the only difference between relayExecuteAmputationAction and this is the damage
|
||||
sendServerCommand(patientPl, CommandsData.modules.TOC_RELAY, CommandsData.client.Relay.ReceiveExecuteAmputationAction, ampParams)
|
||||
|
||||
-- Automatic cicatrization
|
||||
sendServerCommand(patientPl, CommandsData.modules.TOC_RELAY, CommandsData.client.Relay.ReceiveForcedCicatrization, {limbName = args.limbName})
|
||||
end
|
||||
|
||||
|
||||
|
||||
-------------------------
|
||||
|
||||
local function OnClientRelayCommand(module, command, playerObj, args)
|
||||
if module == CommandsData.modules.TOC_RELAY and ServerRelayCommands[command] then
|
||||
TOC_DEBUG.print("Received Client Relay command - " .. tostring(command))
|
||||
ServerRelayCommands[command](playerObj, args)
|
||||
end
|
||||
end
|
||||
|
||||
Events.OnClientCommand.Add(OnClientRelayCommand)
|
||||
Reference in New Issue
Block a user