diff --git a/src/Koogle.Web/Store/GameState/GameEffects.cs b/src/Koogle.Web/Store/GameState/GameEffects.cs index 260754e..3133c0d 100644 --- a/src/Koogle.Web/Store/GameState/GameEffects.cs +++ b/src/Koogle.Web/Store/GameState/GameEffects.cs @@ -275,12 +275,7 @@ public class GameEffects _logger.LogWarning(ex, "Could not resolve game logic service for {GameType}", gameTypeName); } - // Create AfterThrowState for game logic - var beforeSnapshot = CreateThrowPanelSnapshot(action.BeforeThrowState); - var afterSnapshot = CreateThrowPanelSnapshot(action.AfterThrowState); - var afterThrowState = afterSnapshot.CreateAfterThrowState(beforeSnapshot, currentPlayerId.Value); - - // Calculate new throw panel state with standard lane behavior + // Calculate new throw panel state with incremented counters var newThrowPanel = action.AfterThrowState with { ThrowCounterPerRound = action.AfterThrowState.ThrowCounterPerRound + 1, @@ -288,6 +283,14 @@ public class GameEffects BellValue = false // Reset bell after throw }; + // Check if round is complete BEFORE applying pin reset + bool isRoundComplete = newThrowPanel.ThrowCounterPerRound >= newThrowPanel.ThrowsPerRound; + + // Create AfterThrowState for game logic with updated counters + var beforeSnapshot = CreateThrowPanelSnapshot(action.BeforeThrowState); + var afterSnapshot = CreateThrowPanelSnapshot(newThrowPanel); + var afterThrowState = afterSnapshot.CreateAfterThrowState(beforeSnapshot, currentPlayerId.Value); + // Default values bool shouldRotatePlayer = false; Guid? nextPlayerId = null; @@ -339,19 +342,14 @@ public class GameEffects _logger.LogError(ex, "Error in ProcessThrow for game type {GameType}", gameTypeName); // Continue with standard behavior on error newThrowPanel = ApplyStandardPinReset(newThrowPanel); + shouldRotatePlayer = isRoundComplete; } } else { // No game logic service - use standard behavior newThrowPanel = ApplyStandardPinReset(newThrowPanel); - - // Standard rotation: rotate after round is complete - shouldRotatePlayer = newThrowPanel.ThrowCounterPerRound >= newThrowPanel.ThrowsPerRound; - if (shouldRotatePlayer) - { - newThrowPanel = newThrowPanel with { ThrowCounterPerRound = 0 }; - } + shouldRotatePlayer = isRoundComplete; } // Dispatch result action