Fix gameplay engine rules + add RuleSet/CustomLobby system
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 <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -74,15 +74,21 @@ internal sealed class GameReadyHandler : GameHandlerBase, IMessageHandler
|
||||
}
|
||||
|
||||
// Both ready — initialize game state.
|
||||
var p1DeckCards = await LoadDeckCardsAsync(session.PlayerOneDeckId, ct);
|
||||
var p2DeckCards = await LoadDeckCardsAsync(session.PlayerTwoDeckId, ct);
|
||||
var p1ArchSpirit = await LoadDeckArchSpiritAsync(session.PlayerOneDeckId, ct);
|
||||
var p2ArchSpirit = await LoadDeckArchSpiritAsync(session.PlayerTwoDeckId, ct);
|
||||
var p1DeckCards = await LoadDeckCardsAsync(session.PlayerOneDeckId, ct);
|
||||
var p2DeckCards = await LoadDeckCardsAsync(session.PlayerTwoDeckId, ct);
|
||||
var p1ArchSpirit = await LoadDeckArchSpiritAsync(session.PlayerOneDeckId, ct);
|
||||
var p2ArchSpirit = await LoadDeckArchSpiritAsync(session.PlayerTwoDeckId, ct);
|
||||
|
||||
// Deserialize rule snapshot (falls back to default if none stored).
|
||||
var rules = session.RuleSnapshotJson is not null
|
||||
? GameEngine.DeserializeRules(session.RuleSnapshotJson)
|
||||
: null;
|
||||
|
||||
var state = GameEngine.Initialize(
|
||||
session.Id,
|
||||
session.PlayerOneAccountId, p1DeckCards, session.PlayerOneDeckId, p1ArchSpirit,
|
||||
session.PlayerTwoAccountId, p2DeckCards, session.PlayerTwoDeckId, p2ArchSpirit);
|
||||
session.PlayerTwoAccountId, p2DeckCards, session.PlayerTwoDeckId, p2ArchSpirit,
|
||||
rules);
|
||||
|
||||
session.StateJson = GameEngine.Serialize(state);
|
||||
session.Status = GameSessionStatus.Active;
|
||||
|
||||
Reference in New Issue
Block a user