Fix N-player game.ready: per-player ready tracking and deck deserialization
- GameReadyHandler: change `else` → `else if (P2)` so Player 3+ no longer incorrectly marks PlayerTwoReady; additional players now track their own IsReady flag inside AdditionalPlayersJson on the session. All-ready check now waits for P1 + P2 + all additional players. - GameLobbyReadyHandler.StartGameAsync: add PropertyNameCaseInsensitive when deserializing AdditionalPlayersJson → prevents Guid.Empty deck IDs caused by camelCase/PascalCase mismatch between join and ready handlers. - SessionAdditionalPlayer: add IsReady property to support per-player ready tracking in the N-player game.ready flow. 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:
@@ -177,7 +177,9 @@ internal sealed class GameLobbyReadyHandler : GameHandlerBase, IMessageHandler
|
||||
// Additional players (seats 2+).
|
||||
var additionalPlayers = string.IsNullOrEmpty(lobby.AdditionalPlayersJson)
|
||||
? new List<AdditionalLobbyPlayer>()
|
||||
: JsonSerializer.Deserialize<List<AdditionalLobbyPlayer>>(lobby.AdditionalPlayersJson) ?? new();
|
||||
: JsonSerializer.Deserialize<List<AdditionalLobbyPlayer>>(
|
||||
lobby.AdditionalPlayersJson,
|
||||
new JsonSerializerOptions { PropertyNameCaseInsensitive = true }) ?? new();
|
||||
|
||||
// Build the full ordered player list: [P1, P2, P3, ...].
|
||||
var allPlayerIds = new List<Guid> { playerOneId, playerTwoId };
|
||||
|
||||
@@ -98,12 +98,35 @@ internal sealed class GameReadyHandler : GameHandlerBase, IMessageHandler
|
||||
throw new GameException("SESSION_NOT_INITIALIZING");
|
||||
|
||||
// Mark this player ready.
|
||||
if (session.PlayerOneAccountId == accountId) session.PlayerOneReady = true;
|
||||
else session.PlayerTwoReady = true;
|
||||
if (session.PlayerOneAccountId == accountId)
|
||||
session.PlayerOneReady = true;
|
||||
else if (session.PlayerTwoAccountId == accountId)
|
||||
session.PlayerTwoReady = true;
|
||||
else if (isAdditional && session.AdditionalPlayersJson != null)
|
||||
{
|
||||
// Additional players (seat 2+): track readiness in AdditionalPlayersJson.
|
||||
var addl = JsonSerializer.Deserialize<List<SessionAdditionalPlayer>>(
|
||||
session.AdditionalPlayersJson,
|
||||
new JsonSerializerOptions { PropertyNameCaseInsensitive = true })
|
||||
?? new();
|
||||
var entry = addl.FirstOrDefault(p => p.AccountId == accountId);
|
||||
if (entry != null) entry.IsReady = true;
|
||||
session.AdditionalPlayersJson = JsonSerializer.Serialize(addl);
|
||||
}
|
||||
|
||||
await _gameDb.SaveChangesAsync(ct);
|
||||
|
||||
if (!session.PlayerOneReady || !session.PlayerTwoReady)
|
||||
bool allReady = session.PlayerOneReady && session.PlayerTwoReady;
|
||||
if (allReady && !string.IsNullOrEmpty(session.AdditionalPlayersJson))
|
||||
{
|
||||
var addl = JsonSerializer.Deserialize<List<SessionAdditionalPlayer>>(
|
||||
session.AdditionalPlayersJson,
|
||||
new JsonSerializerOptions { PropertyNameCaseInsensitive = true })
|
||||
?? new();
|
||||
allReady = addl.All(p => p.IsReady);
|
||||
}
|
||||
|
||||
if (!allReady)
|
||||
{
|
||||
await _gameDb.Database.CommitTransactionAsync(ct);
|
||||
return ServerMessage.Reply("game.ready.ack", message.Seq,
|
||||
@@ -202,6 +225,7 @@ internal sealed class GameReadyHandler : GameHandlerBase, IMessageHandler
|
||||
public Guid DeckId { get; set; }
|
||||
public int SeatIndex { get; set; }
|
||||
public int TeamIndex { get; set; }
|
||||
public bool IsReady { get; set; }
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<(CardDefinition, int)>> LoadDeckCardsAsync(Guid deckId, CancellationToken ct)
|
||||
|
||||
Reference in New Issue
Block a user