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:
@@ -61,6 +61,10 @@ internal sealed class GameJoinCustomLobbyHandler : GameHandlerBase, IMessageHand
|
||||
if (lobby.HostAccountId == accountId)
|
||||
throw new GameException("CANNOT_JOIN_OWN_LOBBY");
|
||||
|
||||
// Password check.
|
||||
if (lobby.Password != null && lobby.Password != req.Password)
|
||||
throw new GameException("WRONG_PASSWORD");
|
||||
|
||||
lobby.GuestAccountId = accountId;
|
||||
lobby.GuestDeckId = req.DeckId;
|
||||
lobby.Status = CustomLobbyStatus.Full;
|
||||
@@ -69,13 +73,22 @@ internal sealed class GameJoinCustomLobbyHandler : GameHandlerBase, IMessageHand
|
||||
var rules = new GameRules
|
||||
{
|
||||
OpeningHandSize = lobby.OpeningHandSizeOverride ?? GameRules.Default.OpeningHandSize,
|
||||
FirstPlayerSkipsDraw = lobby.FirstPlayerSkipsDrawOverride ?? GameRules.Default.FirstPlayerSkipsDraw,
|
||||
SpAccumulationPerTurn = lobby.SpAccumulationPerTurnOverride ?? GameRules.Default.SpAccumulationPerTurn,
|
||||
DrawPerTurn = lobby.DrawPerTurnOverride ?? GameRules.Default.DrawPerTurn,
|
||||
SpHasCap = lobby.SpHasCapOverride ?? GameRules.Default.SpHasCap,
|
||||
SpCap = lobby.SpCapOverride ?? GameRules.Default.SpCap,
|
||||
BoardWidth = GameRules.Default.BoardWidth,
|
||||
BoardHeight = GameRules.Default.BoardHeight,
|
||||
FirstPlayerSkipsDraw = lobby.FirstPlayerSkipsDrawOverride ?? GameRules.Default.FirstPlayerSkipsDraw,
|
||||
SpAccumulationPerTurn = lobby.SpAccumulationPerTurnOverride ?? GameRules.Default.SpAccumulationPerTurn,
|
||||
DrawPerTurn = lobby.DrawPerTurnOverride ?? GameRules.Default.DrawPerTurn,
|
||||
SpHasCap = lobby.SpHasCapOverride ?? GameRules.Default.SpHasCap,
|
||||
SpCap = lobby.SpCapOverride ?? GameRules.Default.SpCap,
|
||||
BoardWidth = lobby.BoardWidthOverride ?? GameRules.Default.BoardWidth,
|
||||
BoardHeight = lobby.BoardHeightOverride ?? GameRules.Default.BoardHeight,
|
||||
HandSizeCap = lobby.HandSizeCapOverride ?? GameRules.Default.HandSizeCap,
|
||||
DiscardOnMaxHand = lobby.DiscardOnMaxHandOverride ?? GameRules.Default.DiscardOnMaxHand,
|
||||
MaxDeckSize = lobby.MaxDeckSizeOverride ?? GameRules.Default.MaxDeckSize,
|
||||
MinDeckSize = lobby.MinDeckSizeOverride ?? GameRules.Default.MinDeckSize,
|
||||
MaxArchTier1 = lobby.MaxArchTier1Override ?? GameRules.Default.MaxArchTier1,
|
||||
TurnTimerSeconds = lobby.TurnTimerSecondsOverride ?? GameRules.Default.TurnTimerSeconds,
|
||||
TimeLimitMinutes = lobby.TimeLimitMinutesOverride ?? GameRules.Default.TimeLimitMinutes,
|
||||
TurnLimit = lobby.TurnLimitOverride ?? GameRules.Default.TurnLimit,
|
||||
MpBuff = lobby.MpBuffOverride ?? GameRules.Default.MpBuff,
|
||||
};
|
||||
|
||||
// Create the game session with the rule snapshot.
|
||||
@@ -115,15 +128,13 @@ internal sealed class GameJoinCustomLobbyHandler : GameHandlerBase, IMessageHand
|
||||
}
|
||||
|
||||
// Push game-started notification to both players.
|
||||
var push = new CustomLobbyGameStartedPush(session.Id, accountId);
|
||||
var pushToHost = new CustomLobbyGameStartedPush(session.Id, accountId);
|
||||
var pushToGuest = new CustomLobbyGameStartedPush(session.Id, lobby.HostAccountId);
|
||||
|
||||
await Task.WhenAll(
|
||||
_clientPush.PushAsync(lobby.HostAccountId.ToString(),
|
||||
ServerMessage.Push("game.custom.started", pushToHost), ct),
|
||||
ServerMessage.Push("game.custom.started",
|
||||
new CustomLobbyGameStartedPush(session.Id, accountId)), ct),
|
||||
_clientPush.PushAsync(accountId.ToString(),
|
||||
ServerMessage.Push("game.custom.started", pushToGuest), ct));
|
||||
ServerMessage.Push("game.custom.started",
|
||||
new CustomLobbyGameStartedPush(session.Id, lobby.HostAccountId)), ct));
|
||||
|
||||
return ServerMessage.Reply("game.custom.join.ack", message.Seq,
|
||||
new JoinCustomLobbyResponse(
|
||||
|
||||
Reference in New Issue
Block a user