Events - bugladen/bga7s5s GitHub Wiki
An event bus is implemented in this framework. Events are used to allow cards in play and other mechanisms to contribute and react to the state of the game. Event handlers can create new events.
Events are handled thusly:
- Events are queued to the database and run when Theah::runEvents() is called.
- During Theah::runEvents(), events are pulled from the database until the events table is empty.
- Theah::runEvents() continues pulling events from the database and pushing them onto the event bus until the Events table is empty.
Events can be given priority values. During runEvent() the event with highest priority is pulled. If there are multiple highest priority events waiting, then the event is pulled in the order it was queued.
Event Checking
A mechanism is implemented that will allow the game and other cards in play to "stop" an event from occurring. This is called an eventCheck and is called automatically by Theah when you queue an event through Theah::queueEvent(). You can (and should) also call eventCheck in response to a user action before queuing the event. This will automatically create an exception that is bubbled back to the user, showing immediate effect that the action is not allowed. Likewise, any state changes or database modifications are rolled back after this exception is thrown.
Event List
The following are events that currently exist and how to use them:
EventTransition
A transition event is used when, during an event, a card needs to interrupt the state of the game to give a user a choice by moving the state machine to another state. Transition events are usually queued with a higher priority to allow the transition to interrupt any waiting events.