Client multiplayer: N-player targeting, placement zones, lobby creation, outcomes
Server: - BoardDto: add StartingZones (seat → coord list) so client knows valid placement tiles - GameEngine.ToBoardDto: serialize StartingZones into the DTO Client – Game.gd: - get_enemy_players(): returns all players not on the local player's team - get_all_enemy_units(): flat list of field + archSpirit from all enemies - game_over signal: adds player_outcomes: Array parameter - game.over push: extracts playerOutcomes array and passes to signal Client – game_screen.gd: - _valid_placement_tiles(): uses board.startingZones[seatIndex] when available; falls back to legacy row logic - _valid_attack_target_coords/ids: use Game.get_all_enemy_units() instead of single opponent - ability target picker: uses get_all_enemy_units() for enemy units - player-panel builder (zone abilities): iterates get_enemy_players() for N-player - _on_game_over: shows per-player rank deltas from playerOutcomes when present Client – CustomLobby.gd: - State: max_players, game_mode, team_count fields (cleared on clear_state) - create(): accepts p_max_players, p_game_mode, p_team_count params; sends to server - join(): stores max_players/game_mode/team_count from server response - game.custom.started: calls clear_state() before emitting game_starting Client – FreePlayScreen: - Create dialog: MaxPlayersSpinner (2-10), GameModeOption (FFA/Teams/MultiTeam), TeamCountRow (hidden for FFA) - GameModeOption.item_selected toggles team_count_row visibility - _on_create_confirmed: passes max_players, game_mode, team_count to CustomLobby.create() 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:
@@ -60,6 +60,9 @@ var is_host : bool = false
|
||||
var i_am_ready : bool = false
|
||||
var partner_ready : bool = false
|
||||
var first_turn_pref: String = "random"
|
||||
var max_players : int = 2
|
||||
var game_mode : String = "FFA"
|
||||
var team_count : int = 1
|
||||
|
||||
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -76,18 +79,29 @@ func clear_state() -> void:
|
||||
i_am_ready = false
|
||||
partner_ready = false
|
||||
first_turn_pref = "random"
|
||||
max_players = 2
|
||||
game_mode = "FFA"
|
||||
team_count = 1
|
||||
|
||||
# ── Public actions ────────────────────────────────────────────────────────────
|
||||
|
||||
## Create a new lobby. On success, lobby_id and is_host are set; navigate to LobbyRoomScreen.
|
||||
func create(lobby_name: String, deck_id: String, password: String,
|
||||
rules_override: Dictionary, on_success: Callable = Callable(),
|
||||
rules_override: Dictionary,
|
||||
p_max_players: int = 2, p_game_mode: String = "FFA", p_team_count: int = 1,
|
||||
on_success: Callable = Callable(),
|
||||
on_error: Callable = Callable()) -> void:
|
||||
clear_state()
|
||||
my_deck_id = deck_id
|
||||
max_players = p_max_players
|
||||
game_mode = p_game_mode
|
||||
team_count = p_team_count
|
||||
var payload := {
|
||||
"lobbyName": lobby_name,
|
||||
"deckId": deck_id,
|
||||
"lobbyName": lobby_name,
|
||||
"deckId": deck_id,
|
||||
"maxPlayers": p_max_players,
|
||||
"gameMode": p_game_mode,
|
||||
"teamCount": p_team_count,
|
||||
}
|
||||
if password != "":
|
||||
payload["password"] = password
|
||||
@@ -96,9 +110,13 @@ func create(lobby_name: String, deck_id: String, password: String,
|
||||
Network.request("game.custom.create", payload,
|
||||
func(_t: String, p: Variant) -> void:
|
||||
var d := p as Dictionary
|
||||
lobby_id = str(d.get("lobbyId", ""))
|
||||
lobby = d
|
||||
is_host = true
|
||||
lobby_id = str(d.get("lobbyId", ""))
|
||||
lobby = d
|
||||
is_host = true
|
||||
# Extract server-confirmed values (server may adjust/clamp).
|
||||
max_players = int(d.get("maxPlayers", p_max_players))
|
||||
game_mode = str(d.get("gameMode", p_game_mode))
|
||||
team_count = int(d.get("teamCount", p_team_count))
|
||||
if on_success.is_valid(): on_success.call(d),
|
||||
func(code: String, msg: String) -> void:
|
||||
print("[CustomLobby] ERR create ", code, " ", msg)
|
||||
@@ -117,9 +135,12 @@ func join(lid: String, deck_id: String, password: String,
|
||||
Network.request("game.custom.join", payload,
|
||||
func(_t: String, p: Variant) -> void:
|
||||
var d := p as Dictionary
|
||||
lobby_id = str(d.get("lobbyId", ""))
|
||||
lobby = d
|
||||
is_host = false
|
||||
lobby_id = str(d.get("lobbyId", ""))
|
||||
lobby = d
|
||||
is_host = false
|
||||
max_players = int(d.get("maxPlayers", 2))
|
||||
game_mode = str(d.get("gameMode", "FFA"))
|
||||
team_count = int(d.get("teamCount", 1))
|
||||
# Ensure the lobby dict has the fields _refresh_display needs.
|
||||
lobby["guestAccountId"] = str(d.get("guestAccountId", ""))
|
||||
lobby["guestDisplayName"] = str(d.get("guestDisplayName", ""))
|
||||
@@ -296,6 +317,7 @@ func _on_server_push(type: String, payload: Variant) -> void:
|
||||
Game.session_id = sid
|
||||
Game.opponent_name = oname
|
||||
Game.state = {}
|
||||
clear_state()
|
||||
game_starting.emit(sid, opp, oname)
|
||||
|
||||
"game.custom.preset.vote_requested":
|
||||
|
||||
@@ -20,7 +20,8 @@ signal state_updated(state: Dictionary)
|
||||
|
||||
## Emitted when the game ends.
|
||||
signal game_over(winner_account_id: String, win_condition: String,
|
||||
winner_rank_delta: int, loser_rank_delta: int)
|
||||
winner_rank_delta: int, loser_rank_delta: int,
|
||||
player_outcomes: Array)
|
||||
|
||||
## Emitted when the server abandons an Initializing session (e.g. server restart).
|
||||
signal session_abandoned(reason: String)
|
||||
@@ -147,6 +148,28 @@ func get_opponent_field() -> Array:
|
||||
return get_opponent().get("field", [])
|
||||
|
||||
|
||||
## Returns all enemy PlayerStateDto dicts (players not on the same team as the local player).
|
||||
func get_enemy_players() -> Array:
|
||||
var my_team : int = int(get_my_player().get("teamIndex", -1))
|
||||
var result : Array = []
|
||||
for p: Dictionary in state.get("players", []):
|
||||
var pid : String = str(p.get("accountId", ""))
|
||||
if pid == Auth.user_id: continue
|
||||
if int(p.get("teamIndex", -2)) != my_team:
|
||||
result.append(p)
|
||||
return result
|
||||
|
||||
|
||||
## Returns all units (field + archSpirit) belonging to enemy players, as a flat Array.
|
||||
func get_all_enemy_units() -> Array:
|
||||
var units : Array = []
|
||||
for p: Dictionary in get_enemy_players():
|
||||
units.append_array(p.get("field", []))
|
||||
var arch : Dictionary = p.get("archSpirit", {})
|
||||
if not arch.is_empty(): units.append(arch)
|
||||
return units
|
||||
|
||||
|
||||
## Returns a TileDto dict by coord, or {}.
|
||||
func get_tile(x: int, y: int) -> Dictionary:
|
||||
for t: Dictionary in get_tiles():
|
||||
@@ -546,13 +569,14 @@ func _on_server_push(type: String, payload: Variant) -> void:
|
||||
_apply_delta(delta)
|
||||
|
||||
"game.over":
|
||||
var d := payload as Dictionary
|
||||
var winner : String = str(d.get("winnerAccountId", ""))
|
||||
var wc : String = str(d.get("winCondition", ""))
|
||||
var wd : int = int(d.get("winnerRankDelta", 0))
|
||||
var ld : int = int(d.get("loserRankDelta", 0))
|
||||
var d := payload as Dictionary
|
||||
var winner : String = str(d.get("winnerAccountId", ""))
|
||||
var wc : String = str(d.get("winCondition", ""))
|
||||
var wd : int = int(d.get("winnerRankDelta", 0))
|
||||
var ld : int = int(d.get("loserRankDelta", 0))
|
||||
var outcomes : Array = d.get("playerOutcomes", []) as Array
|
||||
state = {} # Clear stale state so a new GameScreen calls send_ready() on the next match
|
||||
game_over.emit(winner, wc, wd, ld)
|
||||
game_over.emit(winner, wc, wd, ld, outcomes)
|
||||
|
||||
"game.session_abandoned":
|
||||
var d := payload as Dictionary
|
||||
|
||||
Reference in New Issue
Block a user