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" % [
|
||||
|
||||
@@ -297,6 +297,9 @@ else
|
||||
@for (int col = 0; col < hexDim; col++)
|
||||
{
|
||||
if (!IsHexInBounds(col, row, hexN)) continue;
|
||||
// Absent tiles are outside the polygon shape — don't render them.
|
||||
// (CSS repeating-linear-gradient is not a valid SVG fill value.)
|
||||
if (_tiles.TryGetValue(TileKey(col, row), out var svgTd) && svgTd.IsAbsent) continue;
|
||||
var hr = row; var hc = col;
|
||||
double cx = HexCellX(hc, hr, hexN, HexR, HexPad);
|
||||
double cy = HexCellY(hr, hexN, HexR, HexPad);
|
||||
|
||||
@@ -56,6 +56,17 @@ public sealed class GameSession
|
||||
/// <summary>"FFA" | "Teams" | "MultiTeam".</summary>
|
||||
public string GameMode { get; set; } = "FFA";
|
||||
|
||||
/// <summary>
|
||||
/// Number of distinct teams. 0 = unset (treated as 2 for Teams/MultiTeam, or PlayerCount for FFA).
|
||||
/// </summary>
|
||||
public int TeamCount { get; set; } = 0;
|
||||
|
||||
/// <summary>Team index for the player in seat 0 (PlayerOne in game turn order).</summary>
|
||||
public int PlayerOneTeamIndex { get; set; } = 0;
|
||||
|
||||
/// <summary>Team index for the player in seat 1 (PlayerTwo in game turn order).</summary>
|
||||
public int PlayerTwoTeamIndex { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// JSON array of additional player slots beyond P1/P2.
|
||||
/// Each element: { "accountId": "...", "deckId": "...", "seatIndex": N, "teamIndex": N }.
|
||||
|
||||
Generated
+550
@@ -0,0 +1,550 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using SOR.Database.Contexts;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SOR.Database.Migrations.Game
|
||||
{
|
||||
[DbContext(typeof(GameDbContext))]
|
||||
[Migration("20260402121607_AddGameSessionTeamFields")]
|
||||
partial class AddGameSessionTeamFields
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasDefaultSchema("game")
|
||||
.HasAnnotation("ProductVersion", "8.0.0")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Game.BoardTemplate", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("GridType")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Height")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("HexPolygonSides")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("HexSides")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<bool>("IsAvailableForCustom")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool>("IsAvailableForRanked")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int>("MaxPlayers")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("MinPlayers")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("StartingZonesJson")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
b.Property<string>("TilesJson")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("Width")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("IsEnabled");
|
||||
|
||||
b.ToTable("board_templates", "game");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Game.CustomLobby", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("AdditionalPlayersJson")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("additional_players_json");
|
||||
|
||||
b.Property<int?>("BoardHeightOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("BoardShapeOverride")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Guid?>("BoardTemplateIdOverride")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<int?>("BoardWidthOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<bool?>("DiscardOnMaxHandOverride")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int?>("DrawPerTurnOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<bool?>("FirstPlayerSkipsDrawOverride")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("GameMode")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("text")
|
||||
.HasDefaultValue("FFA")
|
||||
.HasColumnName("game_mode");
|
||||
|
||||
b.Property<Guid?>("GameSessionId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid?>("GuestAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid?>("GuestDeckId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("GuestFirstTurnPref")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("GuestReady")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int?>("HandSizeCapOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("HexSidesOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<Guid>("HostAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("HostDeckId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("HostFirstTurnPref")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("HostReady")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int?>("MaxArchTier1Override")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("MaxDeckSizeOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("MaxPlayers")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("MinDeckSizeOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("MpBuffOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int?>("OpeningHandSizeOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int?>("SpAccumulationPerTurnOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("SpCapOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<bool?>("SpHasCapOverride")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int?>("StartingRandomTilePctOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("TeamAssignmentsJson")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("TeamCount")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasDefaultValue(1)
|
||||
.HasColumnName("team_count");
|
||||
|
||||
b.Property<int?>("TimeLimitMinutesOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("TurnLimitOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("TurnTimerSecondsOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("HostAccountId");
|
||||
|
||||
b.HasIndex("Status", "CreatedAt");
|
||||
|
||||
b.ToTable("custom_lobbies", "game");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Game.GameActionLog", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("ActionType")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Guid>("ActorAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("GameSessionId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("OccurredAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("PayloadJson")
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("payload");
|
||||
|
||||
b.Property<string>("ResultJson")
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("result");
|
||||
|
||||
b.Property<int>("SequenceNumber")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ActorAccountId");
|
||||
|
||||
b.HasIndex("GameSessionId", "SequenceNumber")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("action_logs", "game");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Game.GameRuleSet", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<int>("BoardHeight")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<Guid?>("BoardTemplateId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<int>("BoardWidth")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<bool>("DiscardOnMaxHand")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int>("DrawPerTurn")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<bool>("FirstPlayerSkipsDraw")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("GridType")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("HandSizeCap")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("HexSides")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<bool>("IsCustomDefault")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool>("IsRankedDefault")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int>("LoserOpReward")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("MaxArchTier1")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("MaxDeckSize")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("MinDeckSize")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("MpBuff")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("OpeningHandSize")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("RankDiffOpMultiplierPct")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("SpAccumulationPerTurn")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("SpCap")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<bool>("SpHasCap")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int>("StartingRandomTilePct")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("TimeLimitMinutes")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("TurnLimit")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("TurnTimerSeconds")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("WinnerOpReward")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("IsCustomDefault");
|
||||
|
||||
b.HasIndex("IsRankedDefault");
|
||||
|
||||
b.ToTable("game_rule_sets", "game");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Game.GameSession", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("AdditionalPlayersJson")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("additional_players_json");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTimeOffset?>("EndedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("GameMode")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("text")
|
||||
.HasDefaultValue("FFA")
|
||||
.HasColumnName("game_mode");
|
||||
|
||||
b.Property<DateTimeOffset?>("LastActionAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("PlayerCount")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasDefaultValue(2)
|
||||
.HasColumnName("player_count");
|
||||
|
||||
b.Property<Guid>("PlayerOneAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("PlayerOneDeckId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<bool>("PlayerOneReady")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int>("PlayerOneTeamIndex")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<Guid>("PlayerTwoAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("PlayerTwoDeckId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<bool>("PlayerTwoReady")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int>("PlayerTwoTeamIndex")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("RuleSnapshotJson")
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("rule_snapshot");
|
||||
|
||||
b.Property<DateTimeOffset?>("StartedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("StateJson")
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("state");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("TeamCount")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("WinCondition")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Guid?>("WinnerAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PlayerOneAccountId");
|
||||
|
||||
b.HasIndex("PlayerTwoAccountId");
|
||||
|
||||
b.HasIndex("Status", "CreatedAt");
|
||||
|
||||
b.ToTable("game_sessions", "game");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Game.LobbyPreset", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Guid>("OwnerAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("RulesJson")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("OwnerAccountId");
|
||||
|
||||
b.ToTable("lobby_presets", "game");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Game.MatchmakingEntry", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("AccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("DeckId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("JoinedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid?>("MatchedGameSessionId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<int>("RankScore")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTimeOffset?>("ResolvedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AccountId", "Status");
|
||||
|
||||
b.HasIndex("Status", "RankScore");
|
||||
|
||||
b.ToTable("matchmaking_entries", "game");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Game.GameActionLog", b =>
|
||||
{
|
||||
b.HasOne("SOR.Database.Entities.Game.GameSession", "Session")
|
||||
.WithMany("ActionLog")
|
||||
.HasForeignKey("GameSessionId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Session");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Game.GameSession", b =>
|
||||
{
|
||||
b.Navigation("ActionLog");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SOR.Database.Migrations.Game
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddGameSessionTeamFields : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "PlayerOneTeamIndex",
|
||||
schema: "game",
|
||||
table: "game_sessions",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "PlayerTwoTeamIndex",
|
||||
schema: "game",
|
||||
table: "game_sessions",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "TeamCount",
|
||||
schema: "game",
|
||||
table: "game_sessions",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "PlayerOneTeamIndex",
|
||||
schema: "game",
|
||||
table: "game_sessions");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "PlayerTwoTeamIndex",
|
||||
schema: "game",
|
||||
table: "game_sessions");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "TeamCount",
|
||||
schema: "game",
|
||||
table: "game_sessions");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -412,6 +412,9 @@ namespace SOR.Database.Migrations.Game
|
||||
b.Property<bool>("PlayerOneReady")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int>("PlayerOneTeamIndex")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<Guid>("PlayerTwoAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
@@ -421,6 +424,9 @@ namespace SOR.Database.Migrations.Game
|
||||
b.Property<bool>("PlayerTwoReady")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int>("PlayerTwoTeamIndex")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("RuleSnapshotJson")
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("rule_snapshot");
|
||||
@@ -436,6 +442,9 @@ namespace SOR.Database.Migrations.Game
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("TeamCount")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("WinCondition")
|
||||
.HasColumnType("text");
|
||||
|
||||
|
||||
@@ -211,11 +211,19 @@ internal sealed class GameLobbyReadyHandler : GameHandlerBase, IMessageHandler
|
||||
int playerCount = allPlayerIds.Count;
|
||||
int teamCount = Math.Max(1, lobby.TeamCount);
|
||||
|
||||
// Compute team indices based on game mode:
|
||||
// FFA → teamIndex = seatIndex (everyone on own team)
|
||||
// Teams (≥2) → teamIndex = seatIndex % teamCount (alternating assignment)
|
||||
static int ComputeTeamIndex(string gameMode, int seatIndex, int teamCount) =>
|
||||
gameMode == "FFA" ? seatIndex : seatIndex % teamCount;
|
||||
// Resolve the full seat → team mapping.
|
||||
// Uses host's custom reassignments if any, otherwise defaults to seat % teamCount.
|
||||
var seatTeams = GameReassignTeamHandler.DeserializeAssignments(
|
||||
lobby.TeamAssignmentsJson, lobby.MaxPlayers, teamCount);
|
||||
|
||||
// FFA: every seat is its own team (ignores seatTeams).
|
||||
// Teams/MultiTeam: use seatTeams keyed by lobby seat index.
|
||||
int ComputeTeamIndex(int gameSeat, int lobbySeat) =>
|
||||
lobby.GameMode == "FFA" ? gameSeat : seatTeams.GetValueOrDefault(lobbySeat, lobbySeat % teamCount);
|
||||
|
||||
// P1/P2 lobby seats (before the turn-order coin flip).
|
||||
int p1LobbySeat = playerOneId == lobby.HostAccountId ? 0 : 1;
|
||||
int p2LobbySeat = 1 - p1LobbySeat;
|
||||
|
||||
// Load the admin-configured custom-default ruleset.
|
||||
var dbDefaults = await _gameDb.GameRuleSets
|
||||
@@ -293,7 +301,7 @@ internal sealed class GameLobbyReadyHandler : GameHandlerBase, IMessageHandler
|
||||
accountId = ap.AccountId,
|
||||
deckId = ap.DeckId,
|
||||
seatIndex = i + 2,
|
||||
teamIndex = ComputeTeamIndex(lobby.GameMode, i + 2, teamCount),
|
||||
teamIndex = ComputeTeamIndex(i + 2, i + 2), // lobby seat == game seat for additional
|
||||
});
|
||||
sessionAdditionalJson = JsonSerializer.Serialize(sessionAddl);
|
||||
}
|
||||
@@ -306,6 +314,9 @@ internal sealed class GameLobbyReadyHandler : GameHandlerBase, IMessageHandler
|
||||
PlayerTwoDeckId = p2DeckId,
|
||||
PlayerCount = playerCount,
|
||||
GameMode = lobby.GameMode,
|
||||
TeamCount = teamCount,
|
||||
PlayerOneTeamIndex = ComputeTeamIndex(0, p1LobbySeat),
|
||||
PlayerTwoTeamIndex = ComputeTeamIndex(1, p2LobbySeat),
|
||||
AdditionalPlayersJson = sessionAdditionalJson,
|
||||
Status = GameSessionStatus.Initializing,
|
||||
CreatedAt = DateTimeOffset.UtcNow,
|
||||
|
||||
@@ -165,11 +165,8 @@ internal sealed class GameReadyHandler : GameHandlerBase, IMessageHandler
|
||||
?? new();
|
||||
|
||||
// Build player list with seat/team indices.
|
||||
// P1 and P2 always have seatIndex 0 and 1; teamIndex from GameMode.
|
||||
int teamCount = 1; // FFA default
|
||||
static int TeamIdx(string gameMode, int seat, int tc) =>
|
||||
gameMode == "FFA" ? seat : seat % tc;
|
||||
|
||||
// P1 (seat 0) and P2 (seat 1) have their team indices stored directly on the session
|
||||
// (set by GameLobbyReadyHandler when the lobby starts, respecting TeamAssignmentsJson).
|
||||
var playerList = new List<(Guid, IEnumerable<(SOR.Database.Entities.Catalog.CardDefinition, int)>,
|
||||
SOR.Database.Entities.Catalog.CardDefinition, int, int)>
|
||||
{
|
||||
@@ -177,12 +174,12 @@ internal sealed class GameReadyHandler : GameHandlerBase, IMessageHandler
|
||||
await LoadDeckCardsAsync(session.PlayerOneDeckId, ct),
|
||||
await LoadDeckArchSpiritAsync(session.PlayerOneDeckId, ct),
|
||||
0,
|
||||
TeamIdx(session.GameMode, 0, teamCount)),
|
||||
session.PlayerOneTeamIndex),
|
||||
(session.PlayerTwoAccountId,
|
||||
await LoadDeckCardsAsync(session.PlayerTwoDeckId, ct),
|
||||
await LoadDeckArchSpiritAsync(session.PlayerTwoDeckId, ct),
|
||||
1,
|
||||
TeamIdx(session.GameMode, 1, teamCount)),
|
||||
session.PlayerTwoTeamIndex),
|
||||
};
|
||||
|
||||
foreach (var entry in additionalEntries)
|
||||
|
||||
Reference in New Issue
Block a user