Phase 2+7: GameEngine rule enforcement + extended lobby handlers

Phase 2 — GameEngine:
- Draw(): now draws DrawPerTurn+DrawPerTurnBonus cards per call (was always 1);
  enforces HandSizeCap with block-draw or auto-discard (DiscardOnMaxHand)
- EndTurn(): returns (GameState, bool gameOver); applies MpBuff to all next-player
  units at turn start; checks TurnLimit and sets GameOver phase if exceeded
- GetTurnLimitWinner(): helper returning winner/loser by ArchSpirit HP (P1 on tie)
- ValidateDeck(): new public method checking MinDeckSize, MaxDeckSize, MaxArchTier1
- GameRules note: new fields are already in place from Phase 1

Phase 7 — Handlers + Messages:
- CustomRulesOverride: +9 new nullable fields (HandSizeCap, DiscardOnMaxHand,
  MaxDeckSize, MinDeckSize, MaxArchTier1, TurnTimerSeconds, TimeLimitMinutes,
  TurnLimit, MpBuff)
- CustomRulesDto: +9 matching fields + HasPassword bool
- CreateCustomLobbyRequest: +Password field
- JoinCustomLobbyRequest: +Password field; handler now validates password
- ListCustomLobbiesRequest: +NameSearch, ShowPasswordProtected filters
- GameCreateCustomLobbyHandler: full rule merge + ToDto covers all new fields
- GameJoinCustomLobbyHandler: password check + full rules construction incl. new fields
- GameListCustomLobbiesHandler: full DTO mapping + NameSearch/password filters
- GameEndTurnHandler: injected identityDb+eventBus; handles TurnLimit game-over
  using same pattern as GameAttackHandler (set session fields before SaveStateAsync)
- GameDrawHandler: update deconstruct to discard unused drawn list (_)
- CustomLobbyGuestJoinedPush: new push type (used in Phase 6)

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:
dingo
2026-03-18 23:01:09 -04:00
co-authored by Claude Happy
parent 71947f785e
commit 93d27e9270
7 changed files with 289 additions and 75 deletions
+38 -8
View File
@@ -90,9 +90,10 @@ public sealed record GameForceConcedeRequest(Guid SessionId);
/// <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);
string LobbyName,
Guid DeckId,
string? Password = null,
CustomRulesOverride? Rules = null);
/// <summary>
/// Per-field rule overrides for a custom lobby. Null fields inherit from the
@@ -106,16 +107,29 @@ public sealed record CustomRulesOverride(
bool? SpHasCap = null,
int? SpCap = null,
int? BoardWidth = null,
int? BoardHeight = null);
int? BoardHeight = null,
int? HandSizeCap = null,
bool? DiscardOnMaxHand = null,
int? MaxDeckSize = null,
int? MinDeckSize = null,
int? MaxArchTier1 = null,
int? TurnTimerSeconds = null,
int? TimeLimitMinutes = null,
int? TurnLimit = null,
int? MpBuff = null);
/// <summary>Join an open custom lobby with the specified deck.</summary>
public sealed record JoinCustomLobbyRequest(Guid LobbyId, Guid DeckId);
public sealed record JoinCustomLobbyRequest(Guid LobbyId, Guid DeckId, string? Password = null);
/// <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);
/// <summary>List open custom lobbies. NameSearch filters by lobby name (case-insensitive contains).</summary>
public sealed record ListCustomLobbiesRequest(
int Page = 1,
int PageSize = 20,
string? NameSearch = null,
bool ShowPasswordProtected = true);
// ── Responses ─────────────────────────────────────────────────────────────────
@@ -221,6 +235,12 @@ public sealed record CustomLobbyGameStartedPush(
Guid SessionId,
Guid OpponentAccountId);
/// <summary>Pushed to the host when a guest joins their open lobby.</summary>
public sealed record CustomLobbyGuestJoinedPush(
Guid LobbyId,
Guid GuestAccountId,
string LobbyName);
// ── DTOs ─────────────────────────────────────────────────────────────────────
/// <summary>
@@ -320,7 +340,17 @@ public sealed record CustomRulesDto(
bool SpHasCap,
int SpCap,
int BoardWidth,
int BoardHeight);
int BoardHeight,
int HandSizeCap,
bool DiscardOnMaxHand,
int MaxDeckSize,
int MinDeckSize,
int MaxArchTier1,
int TurnTimerSeconds,
int TimeLimitMinutes,
int TurnLimit,
int MpBuff,
bool HasPassword);
/// <summary>
/// A single client-provided target for one action in an ability.