Implement multiplayer extension: 2-10 players FFA/Team/Multi-Team
Core engine: - Add SeatIndex, TeamIndex, IsEliminated to PlayerState - Add SeatOrder, GameMode to GameState with helpers: ActiveSeats(), GetNextActiveSeat(), GetEnemyIds(), AreAllies() - Add StartingZones to Board for per-seat placement validation - Add BoardShape, PlayerCount to GameRules - New BoardShapeGenerator: Rectangle (up to 4 seats) + Cross shapes - N-player Initialize() overload; old 2-player overload delegates to it - EndTurn uses GetNextActiveSeat() instead of hardcoded GetOpponentId() - Attack finds target across all enemy players; EliminatePlayer() helper allows multi-player elimination without immediate game over - PlaceArchSpirit validates via StartingZones (legacy row fallback preserved) - AbilitySystem.Own() uses AreAllies() for team-aware ownership checks Database: - GameSession: +player_count, +game_mode, +additional_players_json - CustomLobby: +game_mode, +team_count, +additional_players_json - EF migration: AddMultiplayerSlots (applied) Handlers: - GameCreateCustomLobbyHandler: honours MaxPlayers/GameMode/TeamCount from request - GameJoinCustomLobbyHandler: multi-slot join up to MaxPlayers - GameLobbyReadyHandler: N-player all-ready check; seats/team assignment by mode - GameReadyHandler: builds N-player list from AdditionalPlayersJson - GameHandlerBase.LoadActiveSessionAsync: recognises additional players Client: - Game.gd: get_opponents() returns all non-local players; get_opponent() kept as backward-compat alias returning first opponent 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:
@@ -23,6 +23,14 @@ public sealed class GameState
|
||||
/// <summary>Per-player state, keyed by AccountId.ToString().</summary>
|
||||
public Dictionary<string, PlayerState> Players { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Account IDs in seat / turn order. Empty for legacy 1v1 games (fall back to Players.Keys order).
|
||||
/// </summary>
|
||||
public List<string> SeatOrder { get; set; } = new();
|
||||
|
||||
/// <summary>"FFA" | "Teams" | "MultiTeam". Used for ability ownership resolution.</summary>
|
||||
public string GameMode { get; set; } = "FFA";
|
||||
|
||||
/// <summary>Running sequence number for action log / StateVersion.</summary>
|
||||
public int NextActionSequence { get; set; } = 1;
|
||||
|
||||
@@ -41,6 +49,39 @@ public sealed class GameState
|
||||
/// </summary>
|
||||
public List<ActiveEffect> ActiveEffects { get; set; } = new();
|
||||
|
||||
// ── Multi-player helpers ──────────────────────────────────────────────────
|
||||
|
||||
/// <summary>Seat IDs in order, skipping eliminated players.</summary>
|
||||
public IEnumerable<string> ActiveSeats()
|
||||
=> SeatOrder.Count > 0
|
||||
? SeatOrder.Where(id => Players.TryGetValue(id, out var p) && !p.IsEliminated)
|
||||
: Players.Keys.Where(id => !Players[id].IsEliminated);
|
||||
|
||||
/// <summary>Returns the next non-eliminated player in seat order after <paramref name="actorId"/>.</summary>
|
||||
public string GetNextActiveSeat(string actorId)
|
||||
{
|
||||
var active = ActiveSeats().ToList();
|
||||
if (active.Count == 0) return actorId;
|
||||
var idx = active.IndexOf(actorId);
|
||||
return active[(idx + 1) % active.Count];
|
||||
}
|
||||
|
||||
/// <summary>Returns account IDs of all non-eliminated players not on the same team as <paramref name="actorId"/>.</summary>
|
||||
public IEnumerable<string> GetEnemyIds(string actorId)
|
||||
{
|
||||
var myTeam = Players.TryGetValue(actorId, out var p) ? p.TeamIndex : -1;
|
||||
return Players.Values
|
||||
.Where(x => x.TeamIndex != myTeam && !x.IsEliminated)
|
||||
.Select(x => x.AccountId);
|
||||
}
|
||||
|
||||
/// <summary>True when both players are on the same team (or are the same player).</summary>
|
||||
public bool AreAllies(string a, string b)
|
||||
{
|
||||
if (!Players.TryGetValue(a, out var pa) || !Players.TryGetValue(b, out var pb)) return false;
|
||||
return pa.TeamIndex == pb.TeamIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deferred effects (from ApplyOnEventEffect) waiting to fire when their trigger occurs.
|
||||
/// Consumed on firing; cancelled when source unit leaves the battlefield.
|
||||
@@ -52,6 +93,15 @@ public sealed class PlayerState
|
||||
{
|
||||
public string AccountId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>0-based position in the turn order. Set during game initialization.</summary>
|
||||
public int SeatIndex { get; set; } = 0;
|
||||
|
||||
/// <summary>Team affiliation. FFA = same as SeatIndex (everyone on own team). Shared value = allies.</summary>
|
||||
public int TeamIndex { get; set; } = 0;
|
||||
|
||||
/// <summary>True when this player's ArchSpirit has been destroyed in a multi-player game.</summary>
|
||||
public bool IsEliminated { get; set; } = false;
|
||||
|
||||
// ── Zones ────────────────────────────────────────────────────────────────
|
||||
|
||||
public List<CardInstance> Hand { get; set; } = new();
|
||||
|
||||
Reference in New Issue
Block a user