Files
FoC-GameManager/Data/Scripts/Miscellaneous/GameManager/GalacticGameClass.lua
2026-03-08 14:18:29 -05:00

74 lines
2.0 KiB
Lua

require("PGBase")
require("GameManager.PlayerClass")
require("GameManager.UnitClass")
---@class GalacticGameClass
---@field StartTime integer The start time.
---@field Players PlayerClass[] The combatant players in this game.
---@field Units UnitClass[] The units in this game.
GalacticGameClass = {}
GalacticGameClass.__index = GalacticGameClass
---Creates a new Galactic Game context.
---@return GalacticGameClass
function GalacticGameClass:New()
ScriptMessage("Initializing Galactic game...")
local self = setmetatable({}, GalacticGameClass)
---Finds all combatant players in the game.
---@return PlayerClass[]
local function FindPlayers()
return {}
end
self.StartTime = GetCurrentTime()
self.Players = FindPlayers()
self.Units = {}
ScriptMessage("Galactic Game initialized!")
return self
end
---Services the Galactic Game.
function GalacticGameClass:Service()
ScriptMessage("Servicing Galactic game...")
-- Service Players
for playerId, player in pairs(self.Players) do
player:Service()
end
end
---Gets the Player by ID.
---@param id integer Player ID
---@return PlayerClass|nil
function GalacticGameClass:GetPlayer(id)
for playerId, player in pairs(self.Players) do
if playerId == id then
return player
end
end
end
---Records the Player ID as having quit at the current time.
---@param id integer Player ID.
function GalacticGameClass:PlayerQuit(id)
for playerId, player in pairs(self.Players) do
if playerId == id then
player:Quit()
end
end
end
---Adds a built unit to the Unit table.
---@param objectType table The FoC GameObjectTypeWrapper object type that was built.
---@param player table The FoC PlayerWrapper object that owns the new Unit.
function GalacticGameClass:UnitBuilt(objectType, player)
local playerId = player.Get_ID()
local player = self.Players[playerId]
if player then
player:AddUnit(objectType)
end
end