KoogleApp/src/Koogle.Web/Store/GameState/GameActions.cs

268 lines
7.3 KiB
C#

using Koogle.Application.Games;
using Koogle.Domain.Enums;
namespace Koogle.Web.Store.GameState;
// Game Lifecycle Actions
/// <summary>
/// Action to start a new game.
/// </summary>
public record StartGameAction(
Guid DayId,
string GameTypeName,
Guid[] PlayerIds,
ThrowMode ThrowMode,
int ThrowsPerRound,
ParticipantsMode ParticipantsMode,
object? InitialGameModel,
IGameSetupModel? Setup);
/// <summary>
/// Action dispatched when game is started successfully.
/// </summary>
public record StartGameSuccessAction(
Guid GameId,
string GameTypeName,
ThrowPanelState ThrowPanel,
ParticipantsState Participants,
object? GameModel,
IGameSetupModel? Setup);
/// <summary>
/// Action dispatched when starting game fails.
/// </summary>
public record StartGameFailureAction(string Error);
/// <summary>
/// Action to end the current game.
/// </summary>
/// <param name="FinalStatus">Final game status.</param>
/// <param name="WinnerId">Optional winner ID.</param>
/// <param name="WinnerName">Optional winner display name.</param>
/// <param name="FinalScores">Optional final scores per player.</param>
public record EndGameAction(
GameStatus FinalStatus = GameStatus.Completed,
Guid? WinnerId = null,
string? WinnerName = null,
Dictionary<Guid, int>? FinalScores = null);
/// <summary>
/// Action dispatched when game is ended successfully.
/// </summary>
public record EndGameSuccessAction(GameSummaryDto Summary);
/// <summary>
/// Action dispatched when ending game fails.
/// </summary>
public record EndGameFailureAction(string Error);
/// <summary>
/// Action to load an active game from database (recovery).
/// </summary>
public record LoadActiveGameAction(Guid DayId);
/// <summary>
/// Action dispatched when active game is loaded successfully.
/// </summary>
public record LoadActiveGameSuccessAction(
Guid GameId,
string GameTypeName,
ThrowPanelState ThrowPanelBefore,
ThrowPanelState ThrowPanelAfter,
ParticipantsState Participants,
object? GameModel,
IReadOnlyList<GameSnapshot> UndoStack,
IReadOnlyList<GameSnapshot> RedoStack,
IGameSetupModel? Setup);
/// <summary>
/// Action dispatched when no active game exists.
/// </summary>
public record NoActiveGameAction;
/// <summary>
/// Action dispatched when loading active game fails.
/// </summary>
public record LoadActiveGameFailureAction(string Error);
/// <summary>
/// Action to load completed games for a day.
/// </summary>
public record LoadCompletedGamesAction(Guid DayId);
/// <summary>
/// Action dispatched when completed games are loaded successfully.
/// </summary>
public record LoadCompletedGamesSuccessAction(IReadOnlyList<GameSummaryDto> Games);
/// <summary>
/// Action dispatched when loading completed games fails.
/// </summary>
public record LoadCompletedGamesFailureAction(string Error);
// Throw Actions
/// <summary>
/// Action to record a throw with pin results.
/// </summary>
/// <param name="BeforeThrowState">State before the throw was made.</param>
/// <param name="AfterThrowState">State after the throw was made.</param>
/// <param name="IsGutter">Whether the throw went into the gutter.</param>
/// <param name="IsLeftGutter">Whether it was the left gutter.</param>
public record RecordThrowAction(ThrowPanelState BeforeThrowState, ThrowPanelState AfterThrowState, bool IsGutter = false, bool IsLeftGutter = false);
/// <summary>
/// Action dispatched after ProcessThrow completes with game logic result.
/// </summary>
/// <param name="NewThrowPanelState">Updated throw panel state.</param>
/// <param name="UpdatedGameModel">Updated game model from ProcessThrow.</param>
/// <param name="ShouldRotatePlayer">Whether to rotate to next player.</param>
/// <param name="NextPlayerId">Override: specific player to set as current.</param>
/// <param name="PinPattern">Override: custom pin pattern for next throw.</param>
/// <param name="IsGameOver">Whether the game has ended.</param>
/// <param name="WinnerId">Winner if game is over.</param>
public record ProcessThrowResultAction(
ThrowPanelState NewThrowPanelState,
object? UpdatedGameModel,
bool ShouldRotatePlayer,
Guid? NextPlayerId,
PinStatus[]? PinPattern,
bool IsGameOver,
Guid? WinnerId);
/// <summary>
/// Action dispatched when throw is recorded successfully.
/// </summary>
public record RecordThrowSuccessAction;
/// <summary>
/// Action dispatched when recording throw fails.
/// </summary>
public record RecordThrowFailureAction(string Error);
/// <summary>
/// Action to set a single pin status.
/// </summary>
public record SetPinStatusAction(int PinNumber, PinStatus Status);
/// <summary>
/// Action to reset all pins to standing.
/// </summary>
public record ResetPinsAction;
/// <summary>
/// Action to set the bell value.
/// </summary>
public record SetBellValueAction(bool Value);
// Player Actions
/// <summary>
/// Action to advance to the next player.
/// </summary>
public record NextPlayerAction;
/// <summary>
/// Action to set the current player.
/// </summary>
public record SetCurrentPlayerAction(Guid PlayerId);
// Undo Actions
/// <summary>
/// Action to undo the last throw.
/// </summary>
public record UndoThrowAction;
/// <summary>
/// Action dispatched when undo is successful.
/// </summary>
public record UndoThrowSuccessAction(
ThrowPanelState ThrowPanel,
ParticipantsState Participants,
object? GameModel,
bool IsSaving);
/// <summary>
/// Action dispatched when undo fails (e.g., empty stack).
/// </summary>
public record UndoThrowFailureAction(string Error);
// Redo Actions
/// <summary>
/// Action to redo a previously undone throw.
/// </summary>
public record RedoThrowAction;
/// <summary>
/// Action dispatched when redo is successful.
/// </summary>
public record RedoThrowSuccessAction(
ThrowPanelState ThrowPanel,
ParticipantsState Participants,
object? GameModel,
bool IsSaving);
/// <summary>
/// Action dispatched when redo fails (e.g., empty stack).
/// </summary>
public record RedoThrowFailureAction(string Error);
// Persistence Actions
/// <summary>
/// Action to save current game state to database.
/// </summary>
public record SaveGameStateAction;
/// <summary>
/// Action dispatched when game state is saved successfully.
/// </summary>
public record SaveGameStateSuccessAction;
/// <summary>
/// Action dispatched when saving game state fails.
/// </summary>
public record SaveGameStateFailureAction(string Error);
/// <summary>
/// Action dispatched when a concurrency conflict occurs.
/// </summary>
public record ConcurrencyConflictAction(Guid GameId);
/// <summary>
/// Action to clear the concurrency conflict flag.
/// </summary>
public record ClearConcurrencyConflictAction;
// SignalR Actions
/// <summary>
/// Action dispatched when game state update is received from SignalR.
/// </summary>
public record GameStateUpdatedFromHubAction(
ThrowPanelState ThrowPanel,
ParticipantsState Participants,
object? GameModel);
/// <summary>
/// Action dispatched when game ended notification is received from SignalR.
/// </summary>
public record GameEndedFromHubAction(GameSummaryDto Summary);
// Error Actions
/// <summary>
/// Action to clear game error state.
/// </summary>
public record ClearGameErrorAction;
// Game Model Update Action
/// <summary>
/// Action to update the game-specific model.
/// </summary>
public record UpdateGameModelAction(object? GameModel);