4#include <andromenda/ActionRegistry.h>
5#include <foundation/Collections.h>
6#include <foundation/Common.h>
7#include <game/Card/CardHelper.h>
8#include <game/Card/Deck.h>
9#include <phosphorus/GameBootstrapper.h>
10#include <phosphorus/GameSerializer.h>
11#include "GameRulesEngine.h"
20 enum class InteractionType : uint8
22 StockTakeNextCard = 0,
55 struct StockNextCardInteraction;
56 struct CardInteraction;
57 struct BulkCardInteraction;
65 friend class ReplaySystem;
70 inline static std::vector<IInteraction *> m_Motions;
75 inline static int32 m_AllowedReverts = 0;
80 static bool canRevert();
118 template<
typename T,
class... Args>
119 static T *
Push(InteractionType type, Args &&...args)
121 static_assert(std::is_base_of_v<IInteraction, T>,
"T must be derived from IInteraction");
126 m_Motions.push_back(im);
131 return static_cast<T *
>(im);
178 BulkCardInteraction() =
default;
211 BulkCardInteraction(
const std::vector<Card *> &cards,
CardStack *stack);
217 void Undo()
override;
222 void Serialize(nlohmann::json &obj)
override;
227 static BulkCardInteraction *
Load(nlohmann::json &obj);
236 CardInteraction() =
default;
275 void Undo()
override;
280 void Serialize(nlohmann::json &obj)
override;
285 static CardInteraction *
Load(nlohmann::json &obj);
308 StockNextCardInteraction();
314 void Undo()
override;
329 void Serialize(nlohmann::json &obj)
override;
Represent registry of Action objects.
Definition ActionRegistry.h:74
Represents a playing card in a game. This class defines a card with properties such as color,...
Definition Card.h:61
Represents a stack of cards in the game.
Definition Deck.h:14
static void CheckForWin()
Evaluates the game state and triggers win logic if necessary.
Definition GameRulesEngine.cpp:116
Handles logic for managing and performing card interactions.
Definition InteractionManager.h:63
static T * Push(InteractionType type, Args &&...args)
Pushes a new interaction to the history and executes it.
Definition InteractionManager.h:119
static void SetAllowedReverts(int32 allowedReverts)
Sets the allowed number of interaction reverts.
Definition InteractionManager.cpp:42
static int32 GetAvailableReverts()
Gets the number of reverts remaining.
Definition InteractionManager.cpp:238
static void SaveMovement(std::ostream &stream)
Saves the current interaction history to a stream.
Definition InteractionManager.cpp:21
static Deck * Deck
Pointer to the game deck used in interactions.
Definition InteractionManager.h:86
static void TakeStockNextCard()
Draws the next card from the stock.
Definition InteractionManager.cpp:195
static int32 GetMotionCount()
Returns the number of interactions in the motion stack.
Definition InteractionManager.cpp:44
static bool ProvideActions(Andromenda::ActionRegistry ®istry)
Registers actions in the provided action registry.
Definition InteractionManager.cpp:286
static void PlayIllegalSound()
Plays a sound for invalid interactions.
Definition InteractionManager.cpp:337
static void MoveCard(Card *card, CardStack *targetStack, bool authorizedMove=false)
Moves a single card to the given target stack.
Definition InteractionManager.cpp:197
static void Clear()
Clears all stored interaction history.
Definition InteractionManager.cpp:13
static void MoveCards(const std::vector< Card * > &cards, CardStack *targetStack)
Moves a group of cards to the given target stack.
Definition InteractionManager.cpp:213
static void LoadMovement(std::istream &stream)
Loads interaction history from a stream.
Definition InteractionManager.cpp:243
static std::function< void()> ReloadCallback
Callback triggered after any interaction is performed.
Definition InteractionManager.h:91
void Do() override
Executes the interaction.
Definition InteractionManager.cpp:78
int32 PreviousIndex
Index of the first moved card in the original stack.
Definition InteractionManager.h:204
void Undo() override
Reverts the interaction.
Definition InteractionManager.cpp:94
std::vector< Card * > Cards
Cards involved in the interaction.
Definition InteractionManager.h:189
void Serialize(nlohmann::json &obj) override
Serializes the bulk interaction to JSON.
Definition InteractionManager.cpp:106
CardStack * Stack
Destination stack.
Definition InteractionManager.h:194
static std::vector< Card * > GrabbedCards
Cards currently being moved (global state).
Definition InteractionManager.h:184
int32 FlippedCardIndex
Index of any card that was flipped due to this move.
Definition InteractionManager.h:209
CardStack * PreviousStack
Stack from which the cards originated.
Definition InteractionManager.h:199
static BulkCardInteraction * Load(nlohmann::json &obj)
Loads a bulk interaction from JSON.
Definition InteractionManager.cpp:121
static CardInteraction * Load(nlohmann::json &obj)
Loads a card interaction from JSON.
Definition InteractionManager.cpp:176
int32 FlippedCardIndex
Index of a card flipped during the move, if any.
Definition InteractionManager.h:267
void Do() override
Executes the interaction.
Definition InteractionManager.cpp:142
static Card * Grabbed
Currently selected card (global state).
Definition InteractionManager.h:242
Card * Card
The card involved in the interaction.
Definition InteractionManager.h:247
void Serialize(nlohmann::json &obj) override
Serializes the interaction to JSON.
Definition InteractionManager.cpp:167
int32 PreviousIndex
Original index of the card.
Definition InteractionManager.h:262
CardStack * Stack
Destination stack.
Definition InteractionManager.h:252
CardStack * PreviousStack
Original stack before the move.
Definition InteractionManager.h:257
void Undo() override
Reverts the interaction.
Definition InteractionManager.cpp:158
Base interface for all interaction types.
Definition InteractionManager.h:31
virtual void Serialize(nlohmann::json &obj)
Serializes the interaction to JSON.
Definition InteractionManager.h:52
virtual void Do()
Executes the interaction.
Definition InteractionManager.h:42
InteractionType Type
Type of the interaction.
Definition InteractionManager.h:37
virtual void Undo()
Reverts the interaction.
Definition InteractionManager.h:47
Represents drawing the next card from the stock pile.
Definition InteractionManager.h:292
static int32 GetStockSize()
Returns the current size of the stock stack.
Definition InteractionManager.cpp:53
int32 Index
Index of the card before the draw.
Definition InteractionManager.h:301
void Undo() override
Reverts the interaction.
Definition InteractionManager.cpp:345
int32 NewIndex
Index of the card after the draw.
Definition InteractionManager.h:306
void Serialize(nlohmann::json &obj) override
Serializes the stock interaction to JSON.
Definition InteractionManager.cpp:58
static Card * GetCard()
Gets the currently selected card from the stock.
Definition InteractionManager.h:319
void Do() override
Executes the interaction.
Definition InteractionManager.cpp:339
static int32 StackIndex
Current index in the stock pile.
Definition InteractionManager.h:296
static StockNextCardInteraction * Load(nlohmann::json &obj)
Loads a stock interaction from JSON.
Definition InteractionManager.cpp:64