diff --git a/Server/src/SOR.Database/Entities/Game/CustomLobby.cs b/Server/src/SOR.Database/Entities/Game/CustomLobby.cs index 1c6b9d9..f318780 100644 --- a/Server/src/SOR.Database/Entities/Game/CustomLobby.cs +++ b/Server/src/SOR.Database/Entities/Game/CustomLobby.cs @@ -78,7 +78,13 @@ public sealed class CustomLobby public int? BoardWidthOverride { get; set; } /// Board height override in rows. - public int? BoardHeightOverride { get; set; } + public int? BoardHeightOverride { get; set; } + + /// + /// Board shape override. Null or "Default" = use BoardShapeGenerator.AutoShape(playerCount). + /// Valid explicit values: "Rectangle" | "Cross" | "Triangular" | "RadialStar" | "HexRing". + /// + public string? BoardShapeOverride { get; set; } /// Percentage (0–100) of tiles that start with a random basic affinity. 0 = all void. public int? StartingRandomTilePctOverride { get; set; } diff --git a/Server/src/SOR.Database/Migrations/Game/20260326150147_AddBoardShapeOverride.Designer.cs b/Server/src/SOR.Database/Migrations/Game/20260326150147_AddBoardShapeOverride.Designer.cs new file mode 100644 index 0000000..1ed57af --- /dev/null +++ b/Server/src/SOR.Database/Migrations/Game/20260326150147_AddBoardShapeOverride.Designer.cs @@ -0,0 +1,460 @@ +// +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("20260326150147_AddBoardShapeOverride")] + partial class AddBoardShapeOverride + { + /// + 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.CustomLobby", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AdditionalPlayersJson") + .HasColumnType("text") + .HasColumnName("additional_players_json"); + + b.Property("BoardHeightOverride") + .HasColumnType("integer"); + + b.Property("BoardShapeOverride") + .HasColumnType("text"); + + b.Property("BoardWidthOverride") + .HasColumnType("integer"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DiscardOnMaxHandOverride") + .HasColumnType("boolean"); + + b.Property("DrawPerTurnOverride") + .HasColumnType("integer"); + + b.Property("FirstPlayerSkipsDrawOverride") + .HasColumnType("boolean"); + + b.Property("GameMode") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("text") + .HasDefaultValue("FFA") + .HasColumnName("game_mode"); + + b.Property("GameSessionId") + .HasColumnType("uuid"); + + b.Property("GuestAccountId") + .HasColumnType("uuid"); + + b.Property("GuestDeckId") + .HasColumnType("uuid"); + + b.Property("GuestFirstTurnPref") + .HasColumnType("text"); + + b.Property("GuestReady") + .HasColumnType("boolean"); + + b.Property("HandSizeCapOverride") + .HasColumnType("integer"); + + b.Property("HostAccountId") + .HasColumnType("uuid"); + + b.Property("HostDeckId") + .HasColumnType("uuid"); + + b.Property("HostFirstTurnPref") + .HasColumnType("text"); + + b.Property("HostReady") + .HasColumnType("boolean"); + + b.Property("MaxArchTier1Override") + .HasColumnType("integer"); + + b.Property("MaxDeckSizeOverride") + .HasColumnType("integer"); + + b.Property("MaxPlayers") + .HasColumnType("integer"); + + b.Property("MinDeckSizeOverride") + .HasColumnType("integer"); + + b.Property("MpBuffOverride") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("OpeningHandSizeOverride") + .HasColumnType("integer"); + + b.Property("Password") + .HasColumnType("text"); + + b.Property("SpAccumulationPerTurnOverride") + .HasColumnType("integer"); + + b.Property("SpCapOverride") + .HasColumnType("integer"); + + b.Property("SpHasCapOverride") + .HasColumnType("boolean"); + + b.Property("StartingRandomTilePctOverride") + .HasColumnType("integer"); + + b.Property("Status") + .IsRequired() + .HasColumnType("text"); + + b.Property("TeamCount") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasDefaultValue(1) + .HasColumnName("team_count"); + + b.Property("TimeLimitMinutesOverride") + .HasColumnType("integer"); + + b.Property("TurnLimitOverride") + .HasColumnType("integer"); + + b.Property("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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ActionType") + .IsRequired() + .HasColumnType("text"); + + b.Property("ActorAccountId") + .HasColumnType("uuid"); + + b.Property("GameSessionId") + .HasColumnType("uuid"); + + b.Property("OccurredAt") + .HasColumnType("timestamp with time zone"); + + b.Property("PayloadJson") + .HasColumnType("jsonb") + .HasColumnName("payload"); + + b.Property("ResultJson") + .HasColumnType("jsonb") + .HasColumnName("result"); + + b.Property("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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("BoardHeight") + .HasColumnType("integer"); + + b.Property("BoardWidth") + .HasColumnType("integer"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DiscardOnMaxHand") + .HasColumnType("boolean"); + + b.Property("DrawPerTurn") + .HasColumnType("integer"); + + b.Property("FirstPlayerSkipsDraw") + .HasColumnType("boolean"); + + b.Property("HandSizeCap") + .HasColumnType("integer"); + + b.Property("IsCustomDefault") + .HasColumnType("boolean"); + + b.Property("IsRankedDefault") + .HasColumnType("boolean"); + + b.Property("LoserOpReward") + .HasColumnType("integer"); + + b.Property("MaxArchTier1") + .HasColumnType("integer"); + + b.Property("MaxDeckSize") + .HasColumnType("integer"); + + b.Property("MinDeckSize") + .HasColumnType("integer"); + + b.Property("MpBuff") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("OpeningHandSize") + .HasColumnType("integer"); + + b.Property("RankDiffOpMultiplierPct") + .HasColumnType("integer"); + + b.Property("SpAccumulationPerTurn") + .HasColumnType("integer"); + + b.Property("SpCap") + .HasColumnType("integer"); + + b.Property("SpHasCap") + .HasColumnType("boolean"); + + b.Property("StartingRandomTilePct") + .HasColumnType("integer"); + + b.Property("TimeLimitMinutes") + .HasColumnType("integer"); + + b.Property("TurnLimit") + .HasColumnType("integer"); + + b.Property("TurnTimerSeconds") + .HasColumnType("integer"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AdditionalPlayersJson") + .HasColumnType("text") + .HasColumnName("additional_players_json"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("EndedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("GameMode") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("text") + .HasDefaultValue("FFA") + .HasColumnName("game_mode"); + + b.Property("LastActionAt") + .HasColumnType("timestamp with time zone"); + + b.Property("PlayerCount") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasDefaultValue(2) + .HasColumnName("player_count"); + + b.Property("PlayerOneAccountId") + .HasColumnType("uuid"); + + b.Property("PlayerOneDeckId") + .HasColumnType("uuid"); + + b.Property("PlayerOneReady") + .HasColumnType("boolean"); + + b.Property("PlayerTwoAccountId") + .HasColumnType("uuid"); + + b.Property("PlayerTwoDeckId") + .HasColumnType("uuid"); + + b.Property("PlayerTwoReady") + .HasColumnType("boolean"); + + b.Property("RuleSnapshotJson") + .HasColumnType("jsonb") + .HasColumnName("rule_snapshot"); + + b.Property("StartedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("StateJson") + .HasColumnType("jsonb") + .HasColumnName("state"); + + b.Property("Status") + .IsRequired() + .HasColumnType("text"); + + b.Property("WinCondition") + .HasColumnType("text"); + + b.Property("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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("OwnerAccountId") + .HasColumnType("uuid"); + + b.Property("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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AccountId") + .HasColumnType("uuid"); + + b.Property("DeckId") + .HasColumnType("uuid"); + + b.Property("JoinedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("MatchedGameSessionId") + .HasColumnType("uuid"); + + b.Property("RankScore") + .HasColumnType("integer"); + + b.Property("ResolvedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("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 + } + } +} diff --git a/Server/src/SOR.Database/Migrations/Game/20260326150147_AddBoardShapeOverride.cs b/Server/src/SOR.Database/Migrations/Game/20260326150147_AddBoardShapeOverride.cs new file mode 100644 index 0000000..e98d385 --- /dev/null +++ b/Server/src/SOR.Database/Migrations/Game/20260326150147_AddBoardShapeOverride.cs @@ -0,0 +1,30 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace SOR.Database.Migrations.Game +{ + /// + public partial class AddBoardShapeOverride : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "BoardShapeOverride", + schema: "game", + table: "custom_lobbies", + type: "text", + nullable: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "BoardShapeOverride", + schema: "game", + table: "custom_lobbies"); + } + } +} diff --git a/Server/src/SOR.Game/GameMessages.cs b/Server/src/SOR.Game/GameMessages.cs index feb1071..cda67b2 100644 --- a/Server/src/SOR.Game/GameMessages.cs +++ b/Server/src/SOR.Game/GameMessages.cs @@ -119,8 +119,13 @@ public sealed record CustomRulesOverride( int? TurnTimerSeconds = null, int? TimeLimitMinutes = null, int? TurnLimit = null, - int? MpBuff = null, - int? StartingRandomTilePct = null); + int? MpBuff = null, + int? StartingRandomTilePct = null, + /// + /// Board shape. Null or "Default" = auto-select by player count via BoardShapeGenerator.AutoShape. + /// Explicit values: "Rectangle" | "Cross" | "Triangular" | "RadialStar" | "HexRing". + /// + string? BoardShape = null); /// Join an open custom lobby with the specified deck. public sealed record JoinCustomLobbyRequest(Guid LobbyId, Guid DeckId, string? Password = null); @@ -672,9 +677,11 @@ public sealed record CustomRulesDto( int TurnTimerSeconds, int TimeLimitMinutes, int TurnLimit, - int MpBuff, - int StartingRandomTilePct, - bool HasPassword); + int MpBuff, + int StartingRandomTilePct, + /// "Default" = auto by player count; otherwise explicit shape name. + string BoardShape, + bool HasPassword); /// Client-facing lobby preset summary. public sealed record LobbyPresetDto( diff --git a/Server/src/SOR.Game/Handlers/GameCreateCustomLobbyHandler.cs b/Server/src/SOR.Game/Handlers/GameCreateCustomLobbyHandler.cs index 67ec46d..a94e721 100644 --- a/Server/src/SOR.Game/Handlers/GameCreateCustomLobbyHandler.cs +++ b/Server/src/SOR.Game/Handlers/GameCreateCustomLobbyHandler.cs @@ -94,6 +94,7 @@ internal sealed class GameCreateCustomLobbyHandler : GameHandlerBase, IMessageHa TurnLimitOverride = req.Rules?.TurnLimit, MpBuffOverride = req.Rules?.MpBuff, StartingRandomTilePctOverride = req.Rules?.StartingRandomTilePct, + BoardShapeOverride = req.Rules?.BoardShape, CreatedAt = DateTimeOffset.UtcNow, }; @@ -104,14 +105,15 @@ internal sealed class GameCreateCustomLobbyHandler : GameHandlerBase, IMessageHa new CreateCustomLobbyResponse( LobbyId : lobby.Id, LobbyName : lobby.Name, - ActiveRules : ToDto(effective, req.Password != null), + ActiveRules : ToDto(effective, req.Password != null, req.Rules?.BoardShape), MaxPlayers : lobby.MaxPlayers, GameMode : lobby.GameMode, TeamCount : lobby.TeamCount)); } // Shared helper used by list/join handlers as well. - internal static CustomRulesDto ToDto(GameRules r, bool hasPassword = false) => new( + // boardShape: the lobby's BoardShapeOverride string; null/"Default" → shown as "Default". + internal static CustomRulesDto ToDto(GameRules r, bool hasPassword = false, string? boardShape = null) => new( OpeningHandSize : r.OpeningHandSize, FirstPlayerSkipsDraw : r.FirstPlayerSkipsDraw, SpAccumulationPerTurn : r.SpAccumulationPerTurn, @@ -130,5 +132,8 @@ internal sealed class GameCreateCustomLobbyHandler : GameHandlerBase, IMessageHa TurnLimit : r.TurnLimit, MpBuff : r.MpBuff, StartingRandomTilePct : r.StartingRandomTilePct, + BoardShape : string.IsNullOrEmpty(boardShape) || boardShape == "Default" + ? "Default" + : boardShape, HasPassword : hasPassword); } diff --git a/Server/src/SOR.Game/Handlers/GameGetLobbyHandler.cs b/Server/src/SOR.Game/Handlers/GameGetLobbyHandler.cs index 34e9e77..e3584b7 100644 --- a/Server/src/SOR.Game/Handlers/GameGetLobbyHandler.cs +++ b/Server/src/SOR.Game/Handlers/GameGetLobbyHandler.cs @@ -56,7 +56,7 @@ internal sealed class GameGetLobbyHandler : GameHandlerBase, IMessageHandler TimeLimitMinutes = lobby.TimeLimitMinutesOverride ?? GameRules.Default.TimeLimitMinutes, TurnLimit = lobby.TurnLimitOverride ?? GameRules.Default.TurnLimit, MpBuff = lobby.MpBuffOverride ?? GameRules.Default.MpBuff, - }, lobby.Password != null); + }, lobby.Password != null, lobby.BoardShapeOverride); var dto = new CustomLobbyDetailDto( LobbyId : lobby.Id, diff --git a/Server/src/SOR.Game/Handlers/GameJoinCustomLobbyHandler.cs b/Server/src/SOR.Game/Handlers/GameJoinCustomLobbyHandler.cs index 82aa9be..e897dca 100644 --- a/Server/src/SOR.Game/Handlers/GameJoinCustomLobbyHandler.cs +++ b/Server/src/SOR.Game/Handlers/GameJoinCustomLobbyHandler.cs @@ -171,7 +171,7 @@ internal sealed class GameJoinCustomLobbyHandler : GameHandlerBase, IMessageHand new JoinCustomLobbyResponse( LobbyId : lobby.Id, Status : lobby.Status == CustomLobbyStatus.Full ? "WaitingForReady" : "WaitingForPlayers", - ActiveRules : GameCreateCustomLobbyHandler.ToDto(effective, lobby.Password != null), + ActiveRules : GameCreateCustomLobbyHandler.ToDto(effective, lobby.Password != null, lobby.BoardShapeOverride), GameSessionId : null, HostAccountId : lobby.HostAccountId, HostDisplayName : hostName, diff --git a/Server/src/SOR.Game/Handlers/GameListActiveLobbiesHandler.cs b/Server/src/SOR.Game/Handlers/GameListActiveLobbiesHandler.cs index 1331efb..6b4b81f 100644 --- a/Server/src/SOR.Game/Handlers/GameListActiveLobbiesHandler.cs +++ b/Server/src/SOR.Game/Handlers/GameListActiveLobbiesHandler.cs @@ -94,6 +94,7 @@ internal sealed class GameListActiveLobbiesHandler : GameHandlerBase, IMessageHa TurnLimit : l.TurnLimitOverride ?? GameRules.Default.TurnLimit, MpBuff : l.MpBuffOverride ?? GameRules.Default.MpBuff, StartingRandomTilePct : l.StartingRandomTilePctOverride ?? GameRules.Default.StartingRandomTilePct, + BoardShape : l.BoardShapeOverride ?? "Default", HasPassword : l.Password != null))); return ServerMessage.Reply("game.custom.list_active.ack", message.Seq, diff --git a/Server/src/SOR.Game/Handlers/GameListCustomLobbiesHandler.cs b/Server/src/SOR.Game/Handlers/GameListCustomLobbiesHandler.cs index 06d30c1..8876066 100644 --- a/Server/src/SOR.Game/Handlers/GameListCustomLobbiesHandler.cs +++ b/Server/src/SOR.Game/Handlers/GameListCustomLobbiesHandler.cs @@ -117,6 +117,7 @@ internal sealed class GameListCustomLobbiesHandler : GameHandlerBase, IMessageHa TurnLimit : l.TurnLimitOverride ?? GameRules.Default.TurnLimit, MpBuff : l.MpBuffOverride ?? GameRules.Default.MpBuff, StartingRandomTilePct : l.StartingRandomTilePctOverride ?? GameRules.Default.StartingRandomTilePct, + BoardShape : l.BoardShapeOverride ?? "Default", HasPassword : l.Password != null), CreatedAt : l.CreatedAt, MaxPlayers : l.MaxPlayers, diff --git a/Server/src/SOR.Game/Handlers/GameLobbyReadyHandler.cs b/Server/src/SOR.Game/Handlers/GameLobbyReadyHandler.cs index 0b12ee1..4189237 100644 --- a/Server/src/SOR.Game/Handlers/GameLobbyReadyHandler.cs +++ b/Server/src/SOR.Game/Handlers/GameLobbyReadyHandler.cs @@ -205,8 +205,12 @@ internal sealed class GameLobbyReadyHandler : GameHandlerBase, IMessageHandler .Where(r => r.IsCustomDefault) .FirstOrDefaultAsync(ct); - // Auto-select board shape when the lobby doesn't specify one explicitly. - var boardShape = BoardShapeGenerator.AutoShape(playerCount); + // Resolve board shape: use lobby override if explicitly set (not null/"Default"), + // otherwise auto-select based on player count. + var boardShape = !string.IsNullOrEmpty(lobby.BoardShapeOverride) + && lobby.BoardShapeOverride != "Default" + ? lobby.BoardShapeOverride + : BoardShapeGenerator.AutoShape(playerCount); // Build effective rules: lobby override → admin custom-default → hard-coded default. var rules = new GameRules diff --git a/Server/src/SOR.Game/Handlers/GameUpdateLobbyRulesHandler.cs b/Server/src/SOR.Game/Handlers/GameUpdateLobbyRulesHandler.cs index 0342aba..e194b05 100644 --- a/Server/src/SOR.Game/Handlers/GameUpdateLobbyRulesHandler.cs +++ b/Server/src/SOR.Game/Handlers/GameUpdateLobbyRulesHandler.cs @@ -71,6 +71,7 @@ internal sealed class GameUpdateLobbyRulesHandler : GameHandlerBase, IMessageHan lobby.TurnLimitOverride = r.TurnLimit; lobby.MpBuffOverride = r.MpBuff; lobby.StartingRandomTilePctOverride = r.StartingRandomTilePct; + lobby.BoardShapeOverride = r.BoardShape; await _gameDb.SaveChangesAsync(ct); @@ -94,7 +95,7 @@ internal sealed class GameUpdateLobbyRulesHandler : GameHandlerBase, IMessageHan TurnLimit = r.TurnLimit ?? GameRules.Default.TurnLimit, MpBuff = r.MpBuff ?? GameRules.Default.MpBuff, StartingRandomTilePct = r.StartingRandomTilePct ?? GameRules.Default.StartingRandomTilePct, - }, lobby.Password != null); + }, lobby.Password != null, r.BoardShape); var updatedPush = ServerMessage.Push("game.custom.lobby_updated", new LobbyUpdatedPush(lobby.Id, effective));