From 682a525193450cb1f7f52f5bbd12e710c7ee9bbd Mon Sep 17 00:00:00 2001 From: dingo Date: Thu, 26 Feb 2026 07:55:32 -0500 Subject: [PATCH] Fix gameplay engine rules + add RuleSet/CustomLobby system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Engine corrections (per gameplay.md + user spec): - Opening draw: both players draw 6 cards at game start - P1 skips Draw phase on turn 1 (already has opening hand); P2 draws once at start of their first turn → 7 cards total - SP: starts at 0, accumulates +3/turn (never resets, no cap by default) - ST: starts at 0, earned only through sacrifice (no per-turn grant) - No entry sickness: units can attack/move/ability the turn they are summoned - Defense restores to MaxDefense at start of each turn (§6.9.3) - Rename Graveyard → Discard throughout (GameState, GameEngine, GameMessages) - Remove IsEntrySick flag from CardInstance and CardInstanceDto GameRuleSet / CustomLobby infrastructure: - GameRuleSet DB entity: admin-configurable rules (IsRankedDefault, IsCustomDefault) - GameRules record (SOR.Game): in-memory config embedded in GameState.Rules - GameSession.RuleSnapshotJson: immutable per-session rule snapshot (jsonb) - MatchmakerService: loads ranked ruleset and snapshots it into each GameSession - GameReadyHandler: deserializes rule snapshot and passes rules to GameEngine.Initialize - CustomLobby DB entity: host+guest, rule overrides, GameSessionId link - CustomLobbyStatus enum: Open / Full / Started / Cancelled Custom game handlers (4): - game.custom.create — host creates lobby with optional rule overrides - game.custom.join — guest joins; when full, creates GameSession + pushes both players - game.custom.leave — host cancels or guest leaves - game.custom.list — paged list of Open lobbies Admin portal: - /game/ranked-rules — edit the ranked play ruleset (auto-seeds default on first visit) - /game/custom-lobbies — read-only view of active and recent custom lobbies - NavMenu: added Ranked Rules + Custom Lobbies links under Game Migration: AddGameRulesAndCustomLobby (game_rule_sets, custom_lobbies, rule_snapshot column on game_sessions) Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- .../SOR.Admin/Components/Layout/NavMenu.razor | 10 + .../Pages/Game/CustomLobbiesPage.razor | 162 ++++++++++++++++ .../Pages/Game/RankedRulesPage.razor | 183 ++++++++++++++++++ .../SOR.Database/Contexts/GameDbContext.cs | 31 ++- .../SOR.Database/Entities/Game/CustomLobby.cs | 48 +++++ .../SOR.Database/Entities/Game/GameRuleSet.cs | 50 +++++ .../SOR.Database/Entities/Game/GameSession.cs | 7 + Server/src/SOR.Database/Enums/GameEnums.cs | 15 ++ ...446_AddGameRulesAndCustomLobby.Designer.cs | 178 +++++++++++++++++ ...260226125446_AddGameRulesAndCustomLobby.cs | 146 ++++++++++++++ Server/src/SOR.Game/GameEngine.cs | 133 ++++++++----- Server/src/SOR.Game/GameMessages.cs | 94 +++++++-- Server/src/SOR.Game/GameRules.cs | 24 +++ Server/src/SOR.Game/GameState.cs | 46 +++-- .../Handlers/GameCreateCustomLobbyHandler.cs | 89 +++++++++ .../Handlers/GameJoinCustomLobbyHandler.cs | 106 ++++++++++ .../Handlers/GameLeaveCustomLobbyHandler.cs | 65 +++++++ .../Handlers/GameListCustomLobbiesHandler.cs | 68 +++++++ .../src/SOR.Game/Handlers/GameReadyHandler.cs | 16 +- Server/src/SOR.Game/ServiceRegistration.cs | 6 + .../src/SOR.Matchmaking/MatchmakerService.cs | 18 ++ 21 files changed, 1399 insertions(+), 96 deletions(-) create mode 100644 Server/src/SOR.Admin/Components/Pages/Game/CustomLobbiesPage.razor create mode 100644 Server/src/SOR.Admin/Components/Pages/Game/RankedRulesPage.razor create mode 100644 Server/src/SOR.Database/Entities/Game/CustomLobby.cs create mode 100644 Server/src/SOR.Database/Entities/Game/GameRuleSet.cs create mode 100644 Server/src/SOR.Database/Migrations/Game/20260226125446_AddGameRulesAndCustomLobby.Designer.cs create mode 100644 Server/src/SOR.Database/Migrations/Game/20260226125446_AddGameRulesAndCustomLobby.cs create mode 100644 Server/src/SOR.Game/GameRules.cs create mode 100644 Server/src/SOR.Game/Handlers/GameCreateCustomLobbyHandler.cs create mode 100644 Server/src/SOR.Game/Handlers/GameJoinCustomLobbyHandler.cs create mode 100644 Server/src/SOR.Game/Handlers/GameLeaveCustomLobbyHandler.cs create mode 100644 Server/src/SOR.Game/Handlers/GameListCustomLobbiesHandler.cs diff --git a/Server/src/SOR.Admin/Components/Layout/NavMenu.razor b/Server/src/SOR.Admin/Components/Layout/NavMenu.razor index 509abf8..df8ffbf 100644 --- a/Server/src/SOR.Admin/Components/Layout/NavMenu.razor +++ b/Server/src/SOR.Admin/Components/Layout/NavMenu.razor @@ -78,6 +78,16 @@ Sessions + +