Restoring stat tables WIP

This commit is contained in:
2026-03-20 09:49:44 -05:00
parent 68449e1a78
commit a5fb7e950a
6 changed files with 437 additions and 30 deletions

View File

@@ -8,6 +8,7 @@ require("GameManager/TutorialTextFeed")
---@field StartTime integer The start time.
---@field Players PlayerClass[] The combatant players in this game.
---@field CombatFeed TutorialTextFeed Text feed for unit builds and kills.
---@field BuildStatsTable table The engine-owned TacticalBuildStatsTable reference, set from GameScoring.lua.
---@field KillStatsTable table The engine-owned TacticalKillStatsTable reference, set from GameScoring.lua.
TacticalGameClass = {}
TacticalGameClass.__index = TacticalGameClass
@@ -83,15 +84,17 @@ end
-- ==================================================
---Adds a built unit to the Unit table.
---@param objectType GameObjectType The FoC GameObjectTypeWrapper object type that was built.
---@param player PlayerObject The FoC PlayerWrapper object that owns the new Unit.
function TacticalGameClass:UnitBuilt(objectType, player)
---@param objectType GameObjectType The game object type that was built.
---@param player PlayerObject The player that owns the new game object.
---@param planet PlanetObject|nil The planet the game object type was built at.
function TacticalGameClass:UnitBuilt(objectType, player, planet)
local playerId = player.Get_ID()
local playerEntry = self.Players[playerId]
if playerEntry then
local unit = playerEntry:AddUnit(objectType)
self:UpdateTacticalBuildStatsTable(unit, planet)
self:CombatTextUnitBuilt(unit)
end
end
@@ -126,8 +129,8 @@ function TacticalGameClass:CombatTextUnitBuilt(unit)
end
---Sets a unit as killed.
---@param gameObject GameObject The FoC GameObjectWrapper object that was killed.
---@param killer PlayerObject The FoC PlayerWrapper object that killed the Unit.
---@param gameObject GameObject The game object that was killed.
---@param killer PlayerObject The player that killed the game object.
function TacticalGameClass:UnitKilled(gameObject, killer)
local ownerId = gameObject.Get_Owner().Get_ID()
local owner = self.Players[ownerId]
@@ -195,6 +198,49 @@ end
--- Stat tables
--- ==================================================
---Updates the Tactical Build Stats Table with the build object type.
---@param unit UnitClass The game object type that was built.
---@param planet PlanetObject|nil The planet the game object type was built at.
function TacticalGameClass:UpdateTacticalBuildStatsTable(unit, planet)
---@type GameObjectType|integer
local planetType = 1
if planet then
planetType = planet.Get_Type()
end
local playerEntry = self.BuildStatsTable[unit.OwnerId]
if not playerEntry then
playerEntry = {}
self.BuildStatsTable[unit.OwnerId] = playerEntry
end
local planetEntry = playerEntry[planetType]
if not planetEntry then
planetEntry = {}
playerEntry[planetType] = planetEntry
end
local typeEntry = planetEntry[unit.Name]
if not typeEntry then
typeEntry = {
build_count = 1,
combat_power = unit.CombatRating,
build_cost = unit.BuildCost,
score_value = unit.ScoreValue
}
planetEntry[unit.Name] = typeEntry
else
typeEntry.build_count = typeEntry.build_count + 1
typeEntry.combat_power = typeEntry.combat_power + unit.CombatRating
typeEntry.build_cost = typeEntry.build_cost + unit.BuildCost
typeEntry.score_value = typeEntry.score_value + unit.ScoreValue
end
end
---Updates the Tactical Kill Stats Table with the killed object.
---@param unit UnitClass The object that was killed.
---@param killer PlayerObject The player that killed the object.
@@ -274,9 +320,40 @@ end
-- ==================================================
---@private
---Finds all players of defined Factions via FoCAPI.
---@param gameMode string The current game mode.
---@return PlayerClass[]
function TacticalGameClass:_FindPlayers(gameMode)
local isSuccess, result = pcall(Get_All_Players)
if isSuccess then
local players = {}
for _, playerWrapper in pairs(result) do
local factionName = playerWrapper.Get_Faction_Name()
for _, faction in pairs(Factions) do
if faction.Name == factionName then
local player = PlayerClass:New(playerWrapper)
players[player.Id] = player
end
end
end
return players
end
return self:_FindPlayersFallback(gameMode)
end
---@private
---Finds all players of defined Factions via starting unit.
---Note: this will not work when starting units are disabled.
---For the spectator team, it will only ever find the player in seat 1.
---@param gameMode string The current game mode.
---@return PlayerClass[]
function TacticalGameClass:_FindPlayersFallback(gameMode)
---@type PlayerClass[]
local players = {}