Fix team play: correct team indices, team-aware unit colors and ownership
Server: - Add TeamCount, PlayerOneTeamIndex, PlayerTwoTeamIndex to GameSession so team assignments survive the lobby→game transition without recomputation - GameLobbyReadyHandler.StartGameAsync: apply TeamAssignmentsJson (host custom reassignments) for all seats; store P1/P2 team indices on the session - GameReadyHandler N-player path: use session.PlayerOneTeamIndex / PlayerTwoTeamIndex instead of hardcoded teamCount=1 (which put both P1 and P2 on team 0 in every non-FFA game) - EF migration: AddGameSessionTeamFields Client (game_screen.gd): - _rebuild_ownership: treat same-team allies as friendly instead of enemy - Unit color loop: use state.teamColors palette per team instead of hardcoded blue (self) / red (everyone else) - _on_game_over: derive i_won from player_outcomes[me].outcome == "Winner" so a teammate's final kill correctly shows "Victory!" for the whole team Also: skip absent hex tiles in BoardTemplateBuilder SVG render Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -211,11 +211,19 @@ internal sealed class GameLobbyReadyHandler : GameHandlerBase, IMessageHandler
|
||||
int playerCount = allPlayerIds.Count;
|
||||
int teamCount = Math.Max(1, lobby.TeamCount);
|
||||
|
||||
// Compute team indices based on game mode:
|
||||
// FFA → teamIndex = seatIndex (everyone on own team)
|
||||
// Teams (≥2) → teamIndex = seatIndex % teamCount (alternating assignment)
|
||||
static int ComputeTeamIndex(string gameMode, int seatIndex, int teamCount) =>
|
||||
gameMode == "FFA" ? seatIndex : seatIndex % teamCount;
|
||||
// Resolve the full seat → team mapping.
|
||||
// Uses host's custom reassignments if any, otherwise defaults to seat % teamCount.
|
||||
var seatTeams = GameReassignTeamHandler.DeserializeAssignments(
|
||||
lobby.TeamAssignmentsJson, lobby.MaxPlayers, teamCount);
|
||||
|
||||
// FFA: every seat is its own team (ignores seatTeams).
|
||||
// Teams/MultiTeam: use seatTeams keyed by lobby seat index.
|
||||
int ComputeTeamIndex(int gameSeat, int lobbySeat) =>
|
||||
lobby.GameMode == "FFA" ? gameSeat : seatTeams.GetValueOrDefault(lobbySeat, lobbySeat % teamCount);
|
||||
|
||||
// P1/P2 lobby seats (before the turn-order coin flip).
|
||||
int p1LobbySeat = playerOneId == lobby.HostAccountId ? 0 : 1;
|
||||
int p2LobbySeat = 1 - p1LobbySeat;
|
||||
|
||||
// Load the admin-configured custom-default ruleset.
|
||||
var dbDefaults = await _gameDb.GameRuleSets
|
||||
@@ -293,7 +301,7 @@ internal sealed class GameLobbyReadyHandler : GameHandlerBase, IMessageHandler
|
||||
accountId = ap.AccountId,
|
||||
deckId = ap.DeckId,
|
||||
seatIndex = i + 2,
|
||||
teamIndex = ComputeTeamIndex(lobby.GameMode, i + 2, teamCount),
|
||||
teamIndex = ComputeTeamIndex(i + 2, i + 2), // lobby seat == game seat for additional
|
||||
});
|
||||
sessionAdditionalJson = JsonSerializer.Serialize(sessionAddl);
|
||||
}
|
||||
@@ -306,6 +314,9 @@ internal sealed class GameLobbyReadyHandler : GameHandlerBase, IMessageHandler
|
||||
PlayerTwoDeckId = p2DeckId,
|
||||
PlayerCount = playerCount,
|
||||
GameMode = lobby.GameMode,
|
||||
TeamCount = teamCount,
|
||||
PlayerOneTeamIndex = ComputeTeamIndex(0, p1LobbySeat),
|
||||
PlayerTwoTeamIndex = ComputeTeamIndex(1, p2LobbySeat),
|
||||
AdditionalPlayersJson = sessionAdditionalJson,
|
||||
Status = GameSessionStatus.Initializing,
|
||||
CreatedAt = DateTimeOffset.UtcNow,
|
||||
|
||||
Reference in New Issue
Block a user