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:
@@ -0,0 +1,48 @@
|
||||
namespace SOR.Database.Entities.Game;
|
||||
|
||||
using SOR.Database.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// A custom (non-matchmade) game lobby created by a player.
|
||||
///
|
||||
/// The host creates the lobby and invites one other player. Once both are present,
|
||||
/// a GameSession is created using the custom rules. Rule fields that are null inherit
|
||||
/// from the active custom-default GameRuleSet.
|
||||
///
|
||||
/// Cross-schema: all account and deck IDs are bare Guids — no EF foreign keys.
|
||||
/// </summary>
|
||||
public sealed class CustomLobby
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public CustomLobbyStatus Status { get; set; } = CustomLobbyStatus.Open;
|
||||
|
||||
// ── Host ─────────────────────────────────────────────────────────────────
|
||||
|
||||
public Guid HostAccountId { get; set; }
|
||||
public Guid HostDeckId { get; set; }
|
||||
|
||||
// ── Guest ────────────────────────────────────────────────────────────────
|
||||
|
||||
public Guid? GuestAccountId { get; set; }
|
||||
public Guid? GuestDeckId { get; set; }
|
||||
|
||||
// ── Linked game session ───────────────────────────────────────────────────
|
||||
|
||||
/// <summary>Set once the GameSession is created from this lobby.</summary>
|
||||
public Guid? GameSessionId { get; set; }
|
||||
|
||||
// ── Rule overrides (null = use custom-default ruleset value) ─────────────
|
||||
|
||||
public int? OpeningHandSizeOverride { get; set; }
|
||||
public bool? FirstPlayerSkipsDrawOverride { get; set; }
|
||||
public int? SpAccumulationPerTurnOverride { get; set; }
|
||||
public int? DrawPerTurnOverride { get; set; }
|
||||
public bool? SpHasCapOverride { get; set; }
|
||||
public int? SpCapOverride { get; set; }
|
||||
|
||||
// ── Timestamps ───────────────────────────────────────────────────────────
|
||||
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
namespace SOR.Database.Entities.Game;
|
||||
|
||||
/// <summary>
|
||||
/// Named ruleset for a game mode. Stored in the DB and managed via the admin portal.
|
||||
///
|
||||
/// The ranked default is loaded by MatchmakerService when creating a GameSession.
|
||||
/// The custom default is used as the base for custom lobby rule overrides.
|
||||
///
|
||||
/// Rules are snapshotted into GameSession.RuleSnapshotJson at session creation so
|
||||
/// that in-flight games are not affected by ruleset changes.
|
||||
/// </summary>
|
||||
public sealed class GameRuleSet
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>If true, this ruleset is applied to all ranked matchmaking games.</summary>
|
||||
public bool IsRankedDefault { get; set; }
|
||||
|
||||
/// <summary>If true, this ruleset is used as the base for custom lobby overrides.</summary>
|
||||
public bool IsCustomDefault { get; set; }
|
||||
|
||||
// ── Rules ─────────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>Cards drawn by all players at game start (before the first turn).</summary>
|
||||
public int OpeningHandSize { get; set; } = 6;
|
||||
|
||||
/// <summary>
|
||||
/// If true, the first player (P1) skips the Draw phase on their first turn.
|
||||
/// P2 still draws once at the start of their first turn, giving them 7 cards total.
|
||||
/// </summary>
|
||||
public bool FirstPlayerSkipsDraw { get; set; } = true;
|
||||
|
||||
/// <summary>SP gained at the start of each player's turn. Accumulates; never resets.</summary>
|
||||
public int SpAccumulationPerTurn { get; set; } = 3;
|
||||
|
||||
/// <summary>Cards drawn during the Draw phase each turn.</summary>
|
||||
public int DrawPerTurn { get; set; } = 1;
|
||||
|
||||
/// <summary>If true, SP is capped at SpCap.</summary>
|
||||
public bool SpHasCap { get; set; }
|
||||
|
||||
/// <summary>Maximum SP balance. Ignored if SpHasCap is false.</summary>
|
||||
public int SpCap { get; set; }
|
||||
|
||||
// ── Timestamps ───────────────────────────────────────────────────────────
|
||||
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
public DateTimeOffset UpdatedAt { get; set; }
|
||||
}
|
||||
@@ -57,6 +57,13 @@ public sealed class GameSession
|
||||
/// </summary>
|
||||
public string? StateJson { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// JSONB blob — snapshot of the GameRuleSet applied to this session at creation.
|
||||
/// Immutable once the session is created; in-flight games are not affected by
|
||||
/// admin changes to the live ruleset.
|
||||
/// </summary>
|
||||
public string? RuleSnapshotJson { get; set; }
|
||||
|
||||
// ── Navigation ───────────────────────────────────────────────────────────
|
||||
|
||||
public ICollection<GameActionLog> ActionLog { get; set; } = new List<GameActionLog>();
|
||||
|
||||
Reference in New Issue
Block a user