Files
mtg-online-drafter/docs/development/devlog/2024-12-18-185000_fix_initial_draw.md
2025-12-18 20:26:42 +01:00

15 lines
1.2 KiB
Markdown

# 2024-12-18 - Fix Initial Draw Logic
## Problem
The user reported that upon entering the game and being prompted to Mulligan, their hand was empty. This prevented them from making an informed decision.
## Root Cause
The `GameManager` initialized the game state with `step: 'mulligan'`, but the `RulesEngine` was never invoked to perform the initial turn-based actions (specifically the initial draw). The cards were added to the `library` zone, but no logic moved them to the `hand` zone before the game start update was sent to the client.
## Solution
1. **Updated `RulesEngine.ts`**: Added a public `startGame()` method that logs the start and calls `performTurnBasedActions()`. `performTurnBasedActions()` already contained the logic to draw 7 cards if the step is 'mulligan' and the hand is empty.
2. **Updated `server/index.ts`**: Modified all game initialization flows (`player_ready`, `start_solo_test`, `start_game`, and the global timer loop) to instantiate a `RulesEngine` and call `startGame()` immediately after populating the deck cards.
## outcome
When a game starts, the server now proactively triggers the initial draw logic. Clients receive the initial game state with 7 cards in hand, allowing the Mulligan UI to display the cards correctly.