Fix AI opponents in FreePlay 3+ player lobbies

- Remove max_players == 2 gate; use per-seat Add AI buttons in the
  additional players panel instead of the guest-slot button
- Fix seat-indexed panel rendering: unified loop over all additional
  seats detects AI slots, human players, and empty seats correctly
- Add _ai_adding guard to prevent concurrent add-AI requests that
  caused the server race (second request overwrote first AI slot)
- Fix push handler reading wrong key ("slots" → "currentAiSlots")
  which wiped ai_slots on every push, leaving only the newest AI
- Fix ACK handler reading wrong keys ("aiId"/"displayName" →
  "aiAccountId"/"aiDisplayName")
- Server: fix all-ready check that required GuestAccountId.HasValue,
  blocking start for no-guest lobbies filled via AdditionalPlayersJson
- Server: fix StartGameAsync null-deref on GuestAccountId and add
  no-guest branch (host=P1, first additional=P2, rest=seats 2+)

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:
dingo
2026-05-26 16:51:01 -04:00
co-authored by Claude Happy
parent 32693d303b
commit dfccd091fd
5 changed files with 137 additions and 75 deletions
@@ -29,14 +29,14 @@ func valid_play_tiles(card: Dictionary, tile_bodies: Dictionary) -> Array:
return results
var ax: int = arch_pos.get("x", 0)
var ay: int = arch_pos.get("y", 0)
# Channel range is a property of the ArchSpirit.
# Channel range is validated by the server from the Spirit card being played.
# dict.get(key, default) only uses the default when the key is ABSENT.
# The server sends nullable ints (e.g. "minChannelRange": null), so the
# key EXISTS but its value is null — GDScript returns null, which silently
# coerces to 0 on a typed int variable, collapsing the range to nothing.
# Read as Variant first, then substitute the default explicitly.
var raw_min: Variant = arch.get("minChannelRange")
var raw_max: Variant = arch.get("maxChannelRange")
var raw_min: Variant = card.get("minChannelRange")
var raw_max: Variant = card.get("maxChannelRange")
var min_r: int = 1 if raw_min == null else int(raw_min)
var max_r: int = 1 if raw_max == null else int(raw_max)
var card_affinity: String = card.get("affinity", "")
@@ -50,7 +50,7 @@ func valid_play_tiles(card: Dictionary, tile_bodies: Dictionary) -> Array:
var tile: Dictionary = Game.get_tile(tx, ty)
print("tile", tile)
print("[GettingAff]", card_affinity)
if not unit_registry.tile_has_blocking_occupant(tile):
if unit_registry.tile_has_blocking_occupant(tile):
continue
if card_affinity != "" and not tile_matches_channel_affinity(tile, card_affinity):
continue
@@ -77,7 +77,7 @@ func is_ruin_instance(iid: String) -> bool:
## Returns true when the tile has an occupant that blocks movement (i.e. not a Ruin).
func tile_has_blocking_occupant(tile: Dictionary) -> bool:
var occupant_id: String = str(tile.get("occupantId", ""))
if occupant_id.is_empty() or occupant_id == "null":
if occupant_id.is_empty() or occupant_id == "<null>" or occupant_id == "null":
print("[TileBlock] failing out")
return false
print("[TileBlock] returning this: ", not is_ruin_instance(occupant_id))