CLAUDE: Fix batter not advancing after plays
Root cause: WebSocket handler had stale state reference after resolve_manual_play() completed. The handler's state object still had the old batter index, and calling state_manager.update_state() overwrote the game engine's updated state. Fix: Re-fetch state from state_manager AFTER resolve_manual_play() returns, ensuring we get the state with the advanced batter index. Also improved logging in _prepare_next_play() to show batting_order for easier debugging. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
364c5149a4
commit
450ef830dc
@ -989,11 +989,10 @@ class GameEngine:
|
|||||||
if state.on_third:
|
if state.on_third:
|
||||||
state.current_on_base_code |= 4 # Bit 2: third base
|
state.current_on_base_code |= 4 # Bit 2: third base
|
||||||
|
|
||||||
logger.debug(
|
logger.info(
|
||||||
f"Prepared next play: batter={state.current_batter.lineup_id}, "
|
f"Prepared next play: batter lineup_id={state.current_batter.lineup_id}, "
|
||||||
f"pitcher={state.current_pitcher.lineup_id if state.current_pitcher else None}, "
|
f"batting_order={state.current_batter.batting_order}, "
|
||||||
f"catcher={state.current_catcher.lineup_id if state.current_catcher else None}, "
|
f"pitcher={state.current_pitcher.lineup_id if state.current_pitcher else None}"
|
||||||
f"on_base_code={state.current_on_base_code}"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _batch_save_inning_rolls(self, game_id: UUID) -> None:
|
async def _batch_save_inning_rolls(self, game_id: UUID) -> None:
|
||||||
|
|||||||
@ -546,9 +546,14 @@ def register_handlers(sio: AsyncServer, manager: ConnectionManager) -> None:
|
|||||||
hit_location=submission.hit_location,
|
hit_location=submission.hit_location,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Clear pending roll only AFTER successful validation (one-time use)
|
# CRITICAL: Re-fetch state AFTER resolve_manual_play completes
|
||||||
state.pending_manual_roll = None
|
# The game engine updates state (advances batter, etc.) during resolution.
|
||||||
state_manager.update_state(game_id, state)
|
# Using the old state reference would overwrite those updates!
|
||||||
|
state = state_manager.get_state(game_id)
|
||||||
|
if state:
|
||||||
|
# Clear pending roll only AFTER successful validation (one-time use)
|
||||||
|
state.pending_manual_roll = None
|
||||||
|
state_manager.update_state(game_id, state)
|
||||||
except GameValidationError as e:
|
except GameValidationError as e:
|
||||||
# Game engine validation error (e.g., missing hit location)
|
# Game engine validation error (e.g., missing hit location)
|
||||||
await manager.emit_to_user(
|
await manager.emit_to_user(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user