Fix team play: correct team indices, team-aware unit colors and ownership
Server: - Add TeamCount, PlayerOneTeamIndex, PlayerTwoTeamIndex to GameSession so team assignments survive the lobby→game transition without recomputation - GameLobbyReadyHandler.StartGameAsync: apply TeamAssignmentsJson (host custom reassignments) for all seats; store P1/P2 team indices on the session - GameReadyHandler N-player path: use session.PlayerOneTeamIndex / PlayerTwoTeamIndex instead of hardcoded teamCount=1 (which put both P1 and P2 on team 0 in every non-FFA game) - EF migration: AddGameSessionTeamFields Client (game_screen.gd): - _rebuild_ownership: treat same-team allies as friendly instead of enemy - Unit color loop: use state.teamColors palette per team instead of hardcoded blue (self) / red (everyone else) - _on_game_over: derive i_won from player_outcomes[me].outcome == "Winner" so a teammate's final kill correctly shows "Victory!" for the whole team Also: skip absent hex tiles in BoardTemplateBuilder SVG render 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:
@@ -1163,9 +1163,19 @@ func _rebuild_ownership(state: Dictionary) -> void:
|
||||
_enemy_unit_ids.clear()
|
||||
_friendly_unit_ids.clear()
|
||||
var my_id := Auth.user_id
|
||||
# Find my team index so allies are treated as friendly too.
|
||||
var my_team_idx : int = -1
|
||||
for p: Dictionary in state.get("players", []):
|
||||
var is_mine : bool = str(p.get("accountId", "")).to_lower() == my_id.to_lower()
|
||||
var target : Dictionary = _enemy_unit_ids if not is_mine else _friendly_unit_ids
|
||||
if str(p.get("accountId", "")).to_lower() == my_id.to_lower():
|
||||
my_team_idx = int(p.get("teamIndex", -1))
|
||||
break
|
||||
for p: Dictionary in state.get("players", []):
|
||||
var pid : String = str(p.get("accountId", "")).to_lower()
|
||||
var is_mine : bool = pid == my_id.to_lower()
|
||||
var team_idx : int = int(p.get("teamIndex", -1))
|
||||
# In team games (teamIndex matches), treat allies as friendly.
|
||||
var is_ally : bool = (not is_mine) and (my_team_idx >= 0) and (team_idx == my_team_idx)
|
||||
var target : Dictionary = _friendly_unit_ids if (is_mine or is_ally) else _enemy_unit_ids
|
||||
for u: Dictionary in p.get("field", []):
|
||||
var iid : String = u.get("instanceId", "")
|
||||
if not iid.is_empty(): target[iid] = true
|
||||
@@ -1446,17 +1456,36 @@ func _rebuild_units(state: Dictionary) -> void:
|
||||
# causing a one-frame bind-pose flash on every state echo.
|
||||
|
||||
# 1. Collect the desired unit set from the new state.
|
||||
var my_id := Auth.user_id
|
||||
var desired : Dictionary = {} # iid → {unit, color, is_enemy}
|
||||
var my_id := Auth.user_id
|
||||
var team_colors : Dictionary = state.get("teamColors", {})
|
||||
var desired : Dictionary = {} # iid → {unit, color, is_enemy}
|
||||
# Find my team index for ally detection.
|
||||
var my_team_idx : int = -1
|
||||
for player: Dictionary in state.get("players", []):
|
||||
var is_mine : bool = str(player.get("accountId", "")).to_lower() == my_id.to_lower()
|
||||
var color : Color = Color(0.3, 0.5, 1.0) if is_mine else Color(1.0, 0.35, 0.35)
|
||||
if str(player.get("accountId", "")).to_lower() == my_id.to_lower():
|
||||
my_team_idx = int(player.get("teamIndex", -1))
|
||||
break
|
||||
for player: Dictionary in state.get("players", []):
|
||||
var pid : String = str(player.get("accountId", "")).to_lower()
|
||||
var is_mine : bool = pid == my_id.to_lower()
|
||||
var team_idx : int = int(player.get("teamIndex", -1))
|
||||
var is_ally : bool = (not is_mine) and (my_team_idx >= 0) and (team_idx == my_team_idx)
|
||||
var is_enemy : bool = not (is_mine or is_ally)
|
||||
# Use the team's palette color; fall back to blue (friendly) or red (enemy).
|
||||
var hex_str : String = str(team_colors.get(str(team_idx), ""))
|
||||
var color : Color
|
||||
if not hex_str.is_empty():
|
||||
color = Color.html("#" + hex_str)
|
||||
elif is_enemy:
|
||||
color = Color(1.0, 0.35, 0.35)
|
||||
else:
|
||||
color = Color(0.3, 0.5, 1.0)
|
||||
var arch : Dictionary = _safe_arch(player)
|
||||
for unit: Dictionary in ([arch] + player.get("field", [])):
|
||||
if unit.is_empty() or unit.get("position") == null: continue
|
||||
var iid : String = str(unit.get("instanceId", ""))
|
||||
if iid.is_empty(): continue
|
||||
desired[iid] = {"unit": unit, "color": color, "is_enemy": not is_mine}
|
||||
desired[iid] = {"unit": unit, "color": color, "is_enemy": is_enemy}
|
||||
|
||||
# 2. Remove units that are no longer on the board.
|
||||
var to_remove : Array[String] = []
|
||||
@@ -4219,7 +4248,19 @@ func _on_hold_timer_fired() -> void:
|
||||
func _on_game_over(winner_id: String, win_condition: String,
|
||||
winner_delta: int, loser_delta: int,
|
||||
player_outcomes: Array = []) -> void:
|
||||
var i_won : bool = (winner_id == Auth.user_id)
|
||||
# In N-player / team games, derive win from player_outcomes so a teammate
|
||||
# winning also counts as a local victory.
|
||||
var i_won : bool
|
||||
if not player_outcomes.is_empty():
|
||||
var my_outcome : String = ""
|
||||
for po: Dictionary in player_outcomes:
|
||||
if str(po.get("accountId", "")) == Auth.user_id:
|
||||
my_outcome = str(po.get("outcome", ""))
|
||||
break
|
||||
i_won = (my_outcome == "Winner")
|
||||
else:
|
||||
i_won = (winner_id == Auth.user_id)
|
||||
|
||||
_go_result_lbl.text = "Victory!" if i_won else "Defeat"
|
||||
_go_result_lbl.modulate = Color(0.4, 1.0, 0.5) if i_won else Color(1.0, 0.4, 0.4)
|
||||
|
||||
@@ -4233,9 +4274,7 @@ func _on_game_over(winner_id: String, win_condition: String,
|
||||
var sign : String = "+" if rd >= 0 else ""
|
||||
var label: String = "You" if pid == Auth.user_id else Game.get_display_name(pid)
|
||||
outcome_lines.append("%s: %s (%s%d)" % [label, oc, sign, rd])
|
||||
_go_rank_lbl.text = "[%s]
|
||||
" % win_condition + "
|
||||
".join(outcome_lines)
|
||||
_go_rank_lbl.text = "[%s]\n" % win_condition + "\n".join(outcome_lines)
|
||||
else:
|
||||
var my_delta : int = winner_delta if i_won else loser_delta
|
||||
_go_rank_lbl.text = "Win by %s | Rank %s%d" % [
|
||||
|
||||
Reference in New Issue
Block a user