From 23dc7925e215f5c05550929733258cc4aa0558d0 Mon Sep 17 00:00:00 2001 From: dingo Date: Mon, 13 Apr 2026 08:29:41 -0400 Subject: [PATCH] fix: arch spirit placement field name, rules lock, and AI indicator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AiPlayerSession.ExecutePlacementAsync — NullReferenceException: Sent { Coord = ... } but GamePlaceArchSpiritRequest.Position is the field name. Changed to { Position = ... }. GameUpdateLobbyRulesHandler — rules locked after adding AI: GuestReady=true is set when AI joins so the game auto-starts when host readies, but that flag was also blocking rule edits via CANNOT_CHANGE_RULES_WHILE_READY. Fix: inject IAiAccountRegistry (optional) and only block when a HUMAN guest is ready. CustomLobby.gd — AI indicator not showing / rules reset on refresh: add_ai: populate ai_slots immediately from the game.ai.add ACK response so _refresh_display sees the AI before the push arrives. update_rules + lobby_updated push: keep lobby["rules"] in sync so _refresh_display() doesn't clobber _current_rules with stale data. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- Client/origin-client/autoloads/CustomLobby.gd | 16 ++++++++++++++++ Server/src/SOR.Ai/Core/AiPlayerSession.cs | 2 +- .../Handlers/GameUpdateLobbyRulesHandler.cs | 18 ++++++++++++++---- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Client/origin-client/autoloads/CustomLobby.gd b/Client/origin-client/autoloads/CustomLobby.gd index 759a165..5e5c27a 100644 --- a/Client/origin-client/autoloads/CustomLobby.gd +++ b/Client/origin-client/autoloads/CustomLobby.gd @@ -240,6 +240,7 @@ func update_rules(rules_override: Dictionary) -> void: var d := p as Dictionary var rules := d.get("rules", {}) as Dictionary if not rules.is_empty(): + lobby["rules"] = rules # keep lobby dict current for _refresh_display lobby_rules_updated.emit(rules), func(code: String, msg: String) -> void: print("[CustomLobby] ERR update_rules ", code, " ", msg)) @@ -335,6 +336,19 @@ func add_ai(difficulty: int, strategy: String, { "lobbyId": lobby_id, "difficulty": difficulty, "strategy": strategy }, func(_t: String, p: Variant) -> void: var d := p as Dictionary + # Update ai_slots immediately from the ACK so the display + # reflects the new AI before the push arrives. + var seat := int(d.get("seatIndex", 1)) + ai_slots = ai_slots.filter(func(s: Dictionary) -> bool: + return int(s.get("seatIndex", -1)) != seat) + ai_slots.append({ + "accountId": str(d.get("aiId", "")), + "displayName": str(d.get("displayName", "AI")), + "difficulty": difficulty, + "strategy": strategy, + "seatIndex": seat, + }) + ai_slots_changed.emit(ai_slots) if on_success.is_valid(): on_success.call(d), func(code: String, msg: String) -> void: print("[CustomLobby] ERR add_ai ", code, " ", msg) @@ -363,6 +377,8 @@ func _on_server_push(type: String, payload: Variant) -> void: "game.custom.lobby_updated": var d := payload as Dictionary var rules := d.get("newRules", {}) as Dictionary + if not rules.is_empty(): + lobby["rules"] = rules # keep lobby dict current for _refresh_display lobby_rules_updated.emit(rules) "game.custom.lobby.deck_changed": diff --git a/Server/src/SOR.Ai/Core/AiPlayerSession.cs b/Server/src/SOR.Ai/Core/AiPlayerSession.cs index d276acb..2447e18 100644 --- a/Server/src/SOR.Ai/Core/AiPlayerSession.cs +++ b/Server/src/SOR.Ai/Core/AiPlayerSession.cs @@ -168,7 +168,7 @@ internal sealed class AiPlayerSession : IAsyncDisposable AiAccountId, coord.X, coord.Y); await InvokeHandlerAsync("game.place_arch_spirit", - JsonSerializer.SerializeToUtf8Bytes(new { SessionId, Coord = new { coord.X, coord.Y } }), + JsonSerializer.SerializeToUtf8Bytes(new { SessionId, Position = new { coord.X, coord.Y } }), ct); } diff --git a/Server/src/SOR.Game/Handlers/GameUpdateLobbyRulesHandler.cs b/Server/src/SOR.Game/Handlers/GameUpdateLobbyRulesHandler.cs index 4ef0103..017d777 100644 --- a/Server/src/SOR.Game/Handlers/GameUpdateLobbyRulesHandler.cs +++ b/Server/src/SOR.Game/Handlers/GameUpdateLobbyRulesHandler.cs @@ -5,6 +5,7 @@ using SOR.Database.Enums; using SOR.Networking.Abstractions.Messaging; using SOR.Networking.Abstractions.Push; using SOR.Networking.Abstractions.Transport; +using SOR.Shared; using SOR.Shared.Networking; /// @@ -18,15 +19,19 @@ internal sealed class GameUpdateLobbyRulesHandler : GameHandlerBase, IMessageHan private readonly IMessageSerializer _serializer; private readonly GameDbContext _gameDb; private readonly IClientPush _clientPush; + // Optional: only present when SOR.Ai is loaded. + private readonly IAiAccountRegistry? _aiRegistry; public GameUpdateLobbyRulesHandler( - IMessageSerializer serializer, - GameDbContext gameDb, - IClientPush clientPush) + IMessageSerializer serializer, + GameDbContext gameDb, + IClientPush clientPush, + IAiAccountRegistry? aiRegistry = null) { _serializer = serializer; _gameDb = gameDb; _clientPush = clientPush; + _aiRegistry = aiRegistry; } public string MessageType => "game.custom.update_rules"; @@ -48,7 +53,12 @@ internal sealed class GameUpdateLobbyRulesHandler : GameHandlerBase, IMessageHan if (lobby.HostAccountId != accountId) throw new GameException("HOST_ONLY"); - if (lobby.HostReady || lobby.GuestReady) + // Allow rule changes as long as no HUMAN player has readied up. + // AI guests are auto-readied server-side; that flag must not block the host from editing. + bool humanGuestReady = lobby.GuestReady + && lobby.GuestAccountId.HasValue + && _aiRegistry?.IsAi(lobby.GuestAccountId.Value) != true; + if (lobby.HostReady || humanGuestReady) throw new GameException("CANNOT_CHANGE_RULES_WHILE_READY"); // Apply all overrides (null = revert to default).