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:
@@ -26,10 +26,39 @@ public sealed record GameEndTurnRequest(Guid SessionId);
|
||||
/// <summary>Concede the game (forfeit).</summary>
|
||||
public sealed record GameConcedeRequest(Guid SessionId);
|
||||
|
||||
// ── Custom lobby requests ─────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>Create a new custom lobby. Host provides their deck and optional rule overrides.</summary>
|
||||
public sealed record CreateCustomLobbyRequest(
|
||||
string LobbyName,
|
||||
Guid DeckId,
|
||||
CustomRulesOverride? Rules = null);
|
||||
|
||||
/// <summary>
|
||||
/// Per-field rule overrides for a custom lobby. Null fields inherit from the
|
||||
/// active custom-default GameRuleSet.
|
||||
/// </summary>
|
||||
public sealed record CustomRulesOverride(
|
||||
int? OpeningHandSize = null,
|
||||
bool? FirstPlayerSkipsDraw = null,
|
||||
int? SpAccumulationPerTurn = null,
|
||||
int? DrawPerTurn = null,
|
||||
bool? SpHasCap = null,
|
||||
int? SpCap = null);
|
||||
|
||||
/// <summary>Join an open custom lobby with the specified deck.</summary>
|
||||
public sealed record JoinCustomLobbyRequest(Guid LobbyId, Guid DeckId);
|
||||
|
||||
/// <summary>Leave or cancel a custom lobby.</summary>
|
||||
public sealed record LeaveCustomLobbyRequest(Guid LobbyId);
|
||||
|
||||
/// <summary>List open custom lobbies.</summary>
|
||||
public sealed record ListCustomLobbiesRequest(int Page = 1, int PageSize = 20);
|
||||
|
||||
// ── Responses ─────────────────────────────────────────────────────────────────
|
||||
|
||||
public sealed record GameReadyResponse(Guid SessionId, string Status);
|
||||
// Status: "WaitingForOpponent" | "Started"
|
||||
// Status: "WaitingForOpponent" | "AlreadyStarted" | "Started"
|
||||
|
||||
public sealed record GameGetStateResponse(GameStateDto State);
|
||||
|
||||
@@ -43,6 +72,26 @@ public sealed record GameEndTurnResponse(GameStateDto State);
|
||||
|
||||
public sealed record GameConcedeResponse(GameStateDto State);
|
||||
|
||||
// ── Custom lobby responses ─────────────────────────────────────────────────────
|
||||
|
||||
public sealed record CreateCustomLobbyResponse(
|
||||
Guid LobbyId,
|
||||
string LobbyName,
|
||||
CustomRulesDto ActiveRules);
|
||||
|
||||
public sealed record JoinCustomLobbyResponse(
|
||||
Guid LobbyId,
|
||||
string Status, // "WaitingForHost" | "GameCreated"
|
||||
Guid? GameSessionId); // set when Status == "GameCreated"
|
||||
|
||||
public sealed record LeaveCustomLobbyResponse(Guid LobbyId);
|
||||
|
||||
public sealed record ListCustomLobbiesResponse(
|
||||
IEnumerable<CustomLobbyDto> Lobbies,
|
||||
int TotalCount,
|
||||
int Page,
|
||||
int PageSize);
|
||||
|
||||
// ── Server Pushes ─────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
@@ -61,6 +110,14 @@ public sealed record GameOverPush(
|
||||
int WinnerRankDelta,
|
||||
int LoserRankDelta);
|
||||
|
||||
/// <summary>
|
||||
/// Pushed to both players when a custom lobby is full and a GameSession has been created.
|
||||
/// Players should navigate to the game screen and send game.ready.
|
||||
/// </summary>
|
||||
public sealed record CustomLobbyGameStartedPush(
|
||||
Guid SessionId,
|
||||
Guid OpponentAccountId);
|
||||
|
||||
// ── DTOs ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
@@ -68,23 +125,21 @@ public sealed record GameOverPush(
|
||||
/// </summary>
|
||||
public sealed record GameStateDto(
|
||||
Guid SessionId,
|
||||
string Phase, // Draw | Main | End | GameOver
|
||||
string Phase, // Draw | Main | End | GameOver
|
||||
string ActivePlayerAccountId,
|
||||
int TurnNumber,
|
||||
IEnumerable<PlayerStateDto> Players);
|
||||
|
||||
public sealed record PlayerStateDto(
|
||||
Guid AccountId,
|
||||
int HandCount, // always shown; actual cards visible only for self
|
||||
int HandCount, // always shown; actual cards visible only to self
|
||||
int DeckCount,
|
||||
IEnumerable<CardInstanceDto>? Hand, // null for opponent
|
||||
IEnumerable<CardInstanceDto> Field, // always visible
|
||||
IEnumerable<CardInstanceDto> Graveyard,
|
||||
CardInstanceDto? ArchSpirit, // leader card on field
|
||||
int CurrentSp, // spirit points this turn
|
||||
int MaxSp,
|
||||
int CurrentSt, // stone points this turn
|
||||
int MaxSt);
|
||||
IEnumerable<CardInstanceDto>? Hand, // null for opponent
|
||||
IEnumerable<CardInstanceDto> Field, // always visible
|
||||
IEnumerable<CardInstanceDto> Discard, // always visible
|
||||
CardInstanceDto? ArchSpirit,
|
||||
int CurrentSp,
|
||||
int CurrentSt);
|
||||
|
||||
public sealed record CardInstanceDto(
|
||||
string InstanceId,
|
||||
@@ -99,5 +154,20 @@ public sealed record CardInstanceDto(
|
||||
int? MaxDefense,
|
||||
int? Damage,
|
||||
bool IsExhausted,
|
||||
bool IsEntrySick,
|
||||
bool IsLeader); // true for the ArchSpirit
|
||||
|
||||
public sealed record CustomLobbyDto(
|
||||
Guid LobbyId,
|
||||
string LobbyName,
|
||||
Guid HostAccountId,
|
||||
bool HasGuest,
|
||||
CustomRulesDto Rules,
|
||||
DateTimeOffset CreatedAt);
|
||||
|
||||
public sealed record CustomRulesDto(
|
||||
int OpeningHandSize,
|
||||
bool FirstPlayerSkipsDraw,
|
||||
int SpAccumulationPerTurn,
|
||||
int DrawPerTurn,
|
||||
bool SpHasCap,
|
||||
int SpCap);
|
||||
|
||||
Reference in New Issue
Block a user