Client: Add AI opponent support to custom lobby

- CustomLobby.gd: add add_ai(difficulty, strategy) method sending
  game.ai.add; add ai_slots: Array state; handle game.ai.slots_changed
  push updating ai_slots and emitting ai_slots_changed signal; clear
  ai_slots in clear_state()
- LobbyRoomScreen.tscn: add AddAiBtn (Button, hidden by default) between
  guest ready indicator and additional players container
- lobby_room_screen.gd: wire AddAiBtn (host-only, visible when guest slot
  is empty and host is not ready); _on_add_ai_pressed() opens a dialog
  with OptionButton for difficulty (D1 Novice - D10 Mythic) and strategy
  (Balanced/Aggressive/Control/Ramp/Swarm); guest slot display renders
  AI name + difficulty when an AI occupies seat 1; _ai_slot_for_seat()
  helper; connect/disconnect ai_slots_changed -> _refresh_display

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-04-12 21:57:46 -04:00
co-authored by Claude Happy
parent d5a0efdb77
commit 540fa7d601
3 changed files with 115 additions and 2 deletions
@@ -57,6 +57,9 @@ signal lobby_notice(message: String)
## Pushed (or acked) when the host changes a seat's team assignment.
signal team_assignment_changed(seat_teams: Dictionary)
## Emitted when the AI slot list for the current lobby changes (add / server push).
signal ai_slots_changed(ai_slots: Array)
# ── State ─────────────────────────────────────────────────────────────────────
var lobby_id : String = ""
@@ -72,6 +75,8 @@ var game_mode : String = "FFA"
var team_count : int = 1
## Seat index → team index overrides. Empty = use default (seat % team_count).
var seat_teams : Dictionary = {}
## Current AI slots in this lobby (array of dicts: accountId, displayName, difficulty, strategy, seatIndex).
var ai_slots : Array = []
# ── Lifecycle ─────────────────────────────────────────────────────────────────
@@ -93,6 +98,7 @@ func clear_state() -> void:
game_mode = "FFA"
team_count = 1
seat_teams = {}
ai_slots = []
# ── Public actions ────────────────────────────────────────────────────────────
@@ -320,6 +326,21 @@ func reassign_team(seat_index: int, team_index: int) -> void:
print("[CustomLobby] ERR reassign_team ", code, " ", msg))
## Host-only: add an AI player to the current open lobby.
## difficulty is 1-10, strategy is one of: Aggressive, Control, Balanced, Ramp, Swarm.
func add_ai(difficulty: int, strategy: String,
on_success: Callable = Callable(),
on_error: Callable = Callable()) -> void:
Network.request("game.ai.add",
{ "lobbyId": lobby_id, "difficulty": difficulty, "strategy": strategy },
func(_t: String, p: Variant) -> void:
var d := p as Dictionary
if on_success.is_valid(): on_success.call(d),
func(code: String, msg: String) -> void:
print("[CustomLobby] ERR add_ai ", code, " ", msg)
if on_error.is_valid(): on_error.call(code, msg))
# ── Private ───────────────────────────────────────────────────────────────────
func _on_server_push(type: String, payload: Variant) -> void:
@@ -412,6 +433,11 @@ func _on_server_push(type: String, payload: Variant) -> void:
"game.custom.lobby.rule_suggestion.rejected":
rule_suggestion_rejected.emit()
"game.ai.slots_changed":
var d := payload as Dictionary
ai_slots = d.get("slots", []) as Array
ai_slots_changed.emit(ai_slots)
"game.custom.lobby.team_reassigned":
var d := payload as Dictionary
var raw := d.get("seatTeams", {}) as Dictionary