diff --git a/Client/origin-client/scenes/free_play/components/rules_editor_dialog.gd b/Client/origin-client/scenes/free_play/components/rules_editor_dialog.gd index 5b5b4c7..f8c816f 100644 --- a/Client/origin-client/scenes/free_play/components/rules_editor_dialog.gd +++ b/Client/origin-client/scenes/free_play/components/rules_editor_dialog.gd @@ -197,5 +197,9 @@ func _on_confirm() -> void: if grid_type == "Hexagon": overrides["boardShape"] = "Hexagon" + # boardTemplateIdOverride: empty string is not a valid Guid — send null instead. + if overrides.get("boardTemplateIdOverride", null) == "": + overrides["boardTemplateIdOverride"] = null + confirmed.emit(overrides) queue_free() diff --git a/Server/src/SOR.Database/Entities/Game/CustomLobby.cs b/Server/src/SOR.Database/Entities/Game/CustomLobby.cs index 5964ce4..2aed341 100644 --- a/Server/src/SOR.Database/Entities/Game/CustomLobby.cs +++ b/Server/src/SOR.Database/Entities/Game/CustomLobby.cs @@ -89,6 +89,9 @@ public sealed class CustomLobby /// When set, use this BoardTemplate instead of generating a board algorithmically. public Guid? BoardTemplateIdOverride { get; set; } + /// Hex sides (N) when BoardShapeOverride is "Hexagon". Null = server default (5). + public int? HexSidesOverride { 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/20260401222603_AddCustomLobbyHexSides.Designer.cs b/Server/src/SOR.Database/Migrations/Game/20260401222603_AddCustomLobbyHexSides.Designer.cs new file mode 100644 index 0000000..e131852 --- /dev/null +++ b/Server/src/SOR.Database/Migrations/Game/20260401222603_AddCustomLobbyHexSides.Designer.cs @@ -0,0 +1,538 @@ +// +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("20260401222603_AddCustomLobbyHexSides")] + partial class AddCustomLobbyHexSides + { + /// + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("GridType") + .IsRequired() + .HasColumnType("text"); + + b.Property("Height") + .HasColumnType("integer"); + + b.Property("HexSides") + .HasColumnType("integer"); + + b.Property("IsAvailableForCustom") + .HasColumnType("boolean"); + + b.Property("IsAvailableForRanked") + .HasColumnType("boolean"); + + b.Property("IsEnabled") + .HasColumnType("boolean"); + + b.Property("MaxPlayers") + .HasColumnType("integer"); + + b.Property("MinPlayers") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("StartingZonesJson") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("TilesJson") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Width") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("IsEnabled"); + + b.ToTable("board_templates", "game"); + }); + + 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("BoardTemplateIdOverride") + .HasColumnType("uuid"); + + 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("HexSidesOverride") + .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("TeamAssignmentsJson") + .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("BoardTemplateId") + .HasColumnType("uuid"); + + 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("GridType") + .IsRequired() + .HasColumnType("text"); + + b.Property("HandSizeCap") + .HasColumnType("integer"); + + b.Property("HexSides") + .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/20260401222603_AddCustomLobbyHexSides.cs b/Server/src/SOR.Database/Migrations/Game/20260401222603_AddCustomLobbyHexSides.cs new file mode 100644 index 0000000..0c89879 --- /dev/null +++ b/Server/src/SOR.Database/Migrations/Game/20260401222603_AddCustomLobbyHexSides.cs @@ -0,0 +1,110 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace SOR.Database.Migrations.Game +{ + /// + public partial class AddCustomLobbyHexSides : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "HexSides", + schema: "game", + table: "game_rule_sets", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValue: 0); + + migrationBuilder.AlterColumn( + name: "GridType", + schema: "game", + table: "game_rule_sets", + type: "text", + nullable: false, + oldClrType: typeof(string), + oldType: "text", + oldDefaultValue: "Square"); + + migrationBuilder.AddColumn( + name: "HexSidesOverride", + schema: "game", + table: "custom_lobbies", + type: "integer", + nullable: true); + + migrationBuilder.AlterColumn( + name: "HexSides", + schema: "game", + table: "board_templates", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValue: 0); + + migrationBuilder.AlterColumn( + name: "GridType", + schema: "game", + table: "board_templates", + type: "text", + nullable: false, + oldClrType: typeof(string), + oldType: "text", + oldDefaultValue: "Square"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "HexSidesOverride", + schema: "game", + table: "custom_lobbies"); + + migrationBuilder.AlterColumn( + name: "HexSides", + schema: "game", + table: "game_rule_sets", + type: "integer", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "GridType", + schema: "game", + table: "game_rule_sets", + type: "text", + nullable: false, + defaultValue: "Square", + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "HexSides", + schema: "game", + table: "board_templates", + type: "integer", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "GridType", + schema: "game", + table: "board_templates", + type: "text", + nullable: false, + defaultValue: "Square", + oldClrType: typeof(string), + oldType: "text"); + } + } +} diff --git a/Server/src/SOR.Database/Migrations/Game/GameDbContextModelSnapshot.cs b/Server/src/SOR.Database/Migrations/Game/GameDbContextModelSnapshot.cs index ff39f48..17794bd 100644 --- a/Server/src/SOR.Database/Migrations/Game/GameDbContextModelSnapshot.cs +++ b/Server/src/SOR.Database/Migrations/Game/GameDbContextModelSnapshot.cs @@ -32,16 +32,14 @@ namespace SOR.Database.Migrations.Game b.Property("CreatedAt") .HasColumnType("timestamp with time zone"); + b.Property("GridType") + .IsRequired() + .HasColumnType("text"); + b.Property("Height") .HasColumnType("integer"); - b.Property("GridType") - .IsRequired() - .HasDefaultValue("Square") - .HasColumnType("text"); - b.Property("HexSides") - .HasDefaultValue(0) .HasColumnType("integer"); b.Property("IsAvailableForCustom") @@ -143,6 +141,9 @@ namespace SOR.Database.Migrations.Game b.Property("HandSizeCapOverride") .HasColumnType("integer"); + b.Property("HexSidesOverride") + .HasColumnType("integer"); + b.Property("HostAccountId") .HasColumnType("uuid"); @@ -292,14 +293,12 @@ namespace SOR.Database.Migrations.Game b.Property("GridType") .IsRequired() - .HasDefaultValue("Square") .HasColumnType("text"); b.Property("HandSizeCap") .HasColumnType("integer"); b.Property("HexSides") - .HasDefaultValue(0) .HasColumnType("integer"); b.Property("IsCustomDefault") diff --git a/Server/src/SOR.Game/GameMessages.cs b/Server/src/SOR.Game/GameMessages.cs index 5cbace3..d7f2161 100644 --- a/Server/src/SOR.Game/GameMessages.cs +++ b/Server/src/SOR.Game/GameMessages.cs @@ -130,7 +130,9 @@ public sealed record CustomRulesOverride( /// When set, use this board template instead of generating a board from BoardShape. /// Null or absent = no template (use shape generator). /// - Guid? BoardTemplateIdOverride = null); + Guid? BoardTemplateIdOverride = null, + /// Hex sides (N) when BoardShape is "Hexagon". 0 = server default (5). + int? HexSides = null); /// Join an open custom lobby with the specified deck. public sealed record JoinCustomLobbyRequest(Guid LobbyId, Guid DeckId, string? Password = null); diff --git a/Server/src/SOR.Game/Handlers/GameLobbyReadyHandler.cs b/Server/src/SOR.Game/Handlers/GameLobbyReadyHandler.cs index 0879e71..651d8f7 100644 --- a/Server/src/SOR.Game/Handlers/GameLobbyReadyHandler.cs +++ b/Server/src/SOR.Game/Handlers/GameLobbyReadyHandler.cs @@ -279,6 +279,7 @@ internal sealed class GameLobbyReadyHandler : GameHandlerBase, IMessageHandler MpBuff = lobby.MpBuffOverride ?? dbDefaults?.MpBuff ?? GameRules.Default.MpBuff, StartingRandomTilePct = lobby.StartingRandomTilePctOverride ?? dbDefaults?.StartingRandomTilePct ?? GameRules.Default.StartingRandomTilePct, BoardShape = boardShape, + HexSides = lobby.HexSidesOverride ?? GameRules.Default.HexSides, BoardTemplateJson = boardTemplateJson, PlayerCount = playerCount, }; diff --git a/Server/src/SOR.Game/Handlers/GameSavePresetHandler.cs b/Server/src/SOR.Game/Handlers/GameSavePresetHandler.cs index b3a950a..7b1099e 100644 --- a/Server/src/SOR.Game/Handlers/GameSavePresetHandler.cs +++ b/Server/src/SOR.Game/Handlers/GameSavePresetHandler.cs @@ -64,7 +64,9 @@ internal sealed class GameSavePresetHandler : GameHandlerBase, IMessageHandler TurnTimerSeconds : lobby.TurnTimerSecondsOverride, TimeLimitMinutes : lobby.TimeLimitMinutesOverride, TurnLimit : lobby.TurnLimitOverride, - MpBuff : lobby.MpBuffOverride); + MpBuff : lobby.MpBuffOverride, + BoardShape : lobby.BoardShapeOverride, + HexSides : lobby.HexSidesOverride); var preset = new LobbyPreset { diff --git a/Server/src/SOR.Game/Handlers/GameUpdateLobbyRulesHandler.cs b/Server/src/SOR.Game/Handlers/GameUpdateLobbyRulesHandler.cs index 2a8d9ef..4ef0103 100644 --- a/Server/src/SOR.Game/Handlers/GameUpdateLobbyRulesHandler.cs +++ b/Server/src/SOR.Game/Handlers/GameUpdateLobbyRulesHandler.cs @@ -73,6 +73,7 @@ internal sealed class GameUpdateLobbyRulesHandler : GameHandlerBase, IMessageHan lobby.StartingRandomTilePctOverride = r.StartingRandomTilePct; lobby.BoardShapeOverride = r.BoardShape; lobby.BoardTemplateIdOverride = r.BoardTemplateIdOverride; + lobby.HexSidesOverride = r.HexSides; await _gameDb.SaveChangesAsync(ct); @@ -96,6 +97,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, + HexSides = r.HexSides ?? GameRules.Default.HexSides, }, lobby.Password != null, r.BoardShape, r.BoardTemplateIdOverride); var updatedPush = ServerMessage.Push("game.custom.lobby_updated",