Commit Graph
2 Commits
Author SHA1 Message Date
682a525193 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>
2026-02-26 07:55:32 -05:00
2058a47a92 Add matchmaking + gameplay services (SOR.Matchmaking + SOR.Game)
DB layer:
- Account.RankScore (int, default 1000) — ELO rank for matchmaking
- GameEnums: MatchmakingStatus, GameSessionStatus, GamePhase
- Entities: MatchmakingEntry, GameSession, GameActionLog
- GameDbContext (schema: game) + AddGameDatabase() registration
- Migrations: AddRankScore (Identity), InitialCreate (Game)

SOR.Matchmaking:
- MatchmakerService (BackgroundService) — 5s poll, ELO ±100→±500 range
- Handlers: matchmaking.join, matchmaking.leave, matchmaking.status
- Pushes MatchFoundPush to both players via IClientPush on match

SOR.Game:
- GameState / PlayerState / CardInstance / FieldCard JSONB model
- GameEngine (pure static): Init, Draw, PlayCard, Attack, EndTurn, Concede
- ELO delta (K=32) computed and applied on game end
- Handlers: game.ready, game.get_state, game.draw, game.play_card,
            game.attack, game.end_turn, game.concede
- State filtered per-viewer (opponent hand/deck hidden)
- GameOverPush with rank deltas to both players

Admin pages:
- /game/matchmaking — live queue stats, active entries, recent activity
- /game/sessions   — session stats, filterable by status/account

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>
2026-02-26 06:57:13 -05:00