#include <BattleSystem.hpp>
Definition at line 40 of file BattleSystem.hpp.
◆ BattleSystem()
| BattleSystem::BattleSystem |
( |
| ) |
|
|
inlineprivate |
◆ advanceTurn()
| void BattleSystem::advanceTurn |
( |
| ) |
|
|
private |
Progresses the battle state machine to the next logical step.
Evaluates the board state after an action resolves. Responsibilities include:
- Checking for win/loss conditions via handleDeadParticipants().
- Intercepting the turn flow to prompt an All-Out Attack if all enemies are knocked down.
- Granting an immediate follow-up turn if the current participant earned a "1 More".
- Cycling to the next living participant's turn if the current actor is finished, clearing their knockdown and Persona switch states in the process.
Definition at line 448 of file BattleSystem.cpp.
◆ allEnemiesKnockedDown()
| bool BattleSystem::allEnemiesKnockedDown |
( |
| ) |
|
|
private |
Evaluates if an All-Out Attack condition is met.
- Returns
- true if every living enemy is currently in the knocked-down state, false otherwise.
Definition at line 632 of file BattleSystem.cpp.
◆ applyResult()
Resolves the mathematical and state changes of a combat action against a target.
Parses a generated TurnResult struct to apply HP modifications, clamp healing to the target's maximum HP, and buffer damage/healing numbers into pendingAlert for UI feedback. Also checks for and triggers the "1 More" state if the hit warrants it.
- Parameters
-
| r | The mathematical result of the action (damage delta, hit flag, 1-More flag). |
| target | The participant receiving the action (can be null for non-targeted actions). |
Definition at line 407 of file BattleSystem.cpp.
◆ calculateTurnOrder()
| void BattleSystem::calculateTurnOrder |
( |
| ) |
|
|
private |
Calculates the initial turn queue at the start of an encounter.
Applies a random agility boost (1.2x to 1.4x) to all participants to prevent static turn orders, sorts the party and enemies individually, and then merges them based on the BattleStartCondition (forcing Party Advantage or Enemy Advantage).
- Note
- TODO: This function currently assumes it is only called once per encounter. Calling it mid-battle could result in a participant taking a double turn.
Definition at line 531 of file BattleSystem.cpp.
◆ getAliveEnemies()
Filters the enemy roster for living combatants.
- Returns
- A vector containing pointers to all enemies currently above 0 HP.
Definition at line 619 of file BattleSystem.cpp.
◆ getParticipantByHigherAgility()
Sorting predicate used to order combatants by agility.
- Parameters
-
| a | The first participant to compare. |
| b | The second participant to compare. |
- Returns
- true if participant 'a' should act before participant 'b'.
Definition at line 236 of file BattleSystem.hpp.
◆ handleDeadParticipants()
| void BattleSystem::handleDeadParticipants |
( |
| ) |
|
|
private |
Sweeps the field for dead participants and evaluates encounter end conditions.
Iterates through all combatants to check if HP has reached 0. Triggers the individual onDead() callbacks to populate the battleResult. Immediately halts and shuts down the battle if the main player dies, or if the entire enemy side is wiped out.
Don't display any battle results
Display battle results
Definition at line 579 of file BattleSystem.cpp.
◆ init()
| void BattleSystem::init |
( |
| ) |
|
|
override |
◆ isSingleTarget()
| bool BattleSystem::isSingleTarget |
( |
SkillType | type | ) |
|
|
private |
Determines if a skill targets a single entity.
- Parameters
-
| type | The enumerated type classification of the skill. |
- Returns
- true if the skill is a single-target action (e.g., Attack, single Heal/Buff), false if it is multi-target.
Definition at line 656 of file BattleSystem.cpp.
◆ on_receive()
ETL message handler that initializes and starts a new battle.
Acts as the initialization routine for the BattleSystem when an ExecuteBattle event is fired over the message bus.
This function dynamically allocates the active combat entities (Player, PartyMember, and Enemy objects) based on the profiles provided in the message payload. It then resets all internal state machine variables, clears any pending UI alerts
Finally, it calculates the initial turn order based on the battleStartCondition and advances the state machine to the first participant's initial phase.
- Parameters
-
| msg | The event payload containing the character/enemy profiles and encounter conditions. |
Definition at line 10 of file BattleSystem.cpp.
◆ on_receive_unknown()
| void BattleSystem::on_receive_unknown |
( |
const etl::imessage & | msg | ) |
|
|
inline |
Fallback handler for unhandled ETL messages.
Required by the ETL message router interface. Safely ignores any messages routed to the BattleSystem that do not have a specific handler.
- Parameters
-
| msg | The unhandled incoming message (unused). |
Definition at line 96 of file BattleSystem.hpp.
◆ setMusicComponent()
◆ setNextPhase()
| void BattleSystem::setNextPhase |
( |
BattlePhase | nextPhase | ) |
|
|
private |
Safely transitions the state machine to a new BattlePhase.
Acts as a router to ensure UI alerts are displayed before phase changes. If there is text buffered in pendingAlert, it intercepts the transition, forcing the system into the ShowAlert phase and saving the intended next phase into alertReturnPhase.
- Parameters
-
| nextPhase | The phase the state machine should enter after all alerts are cleared. |
Definition at line 516 of file BattleSystem.cpp.
◆ shutdown()
| void BattleSystem::shutdown |
( |
| ) |
|
|
override |
◆ update()
| void BattleSystem::update |
( |
ae::q20_12_t | | ) |
|
|
override |
Core update loop that processes the battle state machine and turn resolution.
Executes every engine tick to advance the current BattlePhase. This state machine governs both the user interface flow (via battleMenuCmpt) and the underlying combat mechanics. Key responsibilities include:
- Menu Navigation: Handling hardware input for base actions, skill selection, and target filtering (e.g., preventing healing on max-HP targets, skipping dead entities).
- Persona Mechanics: Managing mid-turn Persona switching and validating SP/HP resource costs before skill execution.
- Combat Flow: Resolving attacks, evaluating "1 More" states to trigger All-Out Attack confirmations, and routing enemy AI behavior.
- UI Alerts: Temporarily overriding the menu to display asynchronous combat messages using the pendingAlert buffer during the ShowAlert phase.
- Parameters
-
| dt | Fixed-point delta time passed from the aegis engine loop (currently unused). |
Definition at line 72 of file BattleSystem.cpp.
◆ Singleton< BattleSystem >
◆ ACTION_ATTACK
| u32 BattleSystem::ACTION_ATTACK = 0 |
|
staticconstexprprivate |
◆ ACTION_GUARD
| u32 BattleSystem::ACTION_GUARD = 1 |
|
staticconstexprprivate |
◆ ACTION_PERSONA
| u32 BattleSystem::ACTION_PERSONA = 2 |
|
staticconstexprprivate |
◆ ACTION_SWITCH
| u32 BattleSystem::ACTION_SWITCH = 3 |
|
staticconstexprprivate |
◆ actions
◆ alertReturnPhase
◆ allOutAttackWasPossibleThisKnockDown
| bool BattleSystem::allOutAttackWasPossibleThisKnockDown = false |
|
private |
◆ attack
◆ battleMenuCmpt
| BattleMenu* BattleSystem::battleMenuCmpt = nullptr |
|
private |
◆ battleParticipants
◆ battleResult
◆ battleStartCondition
◆ currentParticipantIndex
| u32 BattleSystem::currentParticipantIndex = 0 |
|
private |
◆ currentParticipantTurn
◆ enemies
| etl::vector<Enemy*, 8> BattleSystem::enemies |
|
private |
◆ guard
| Guard BattleSystem::guard |
|
private |
◆ musicCmpt
◆ partyMembers
| etl::vector<PartyMember*, 4> BattleSystem::partyMembers |
|
private |
◆ pendingAlert
| std::string BattleSystem::pendingAlert |
|
private |
◆ pendingPersonaSwitch
| bool BattleSystem::pendingPersonaSwitch = false |
|
private |
◆ persona
◆ personaBeforeSwitch
| PersonaBase* BattleSystem::personaBeforeSwitch = nullptr |
|
private |
◆ phase
◆ player
| Player* BattleSystem::player = nullptr |
|
private |
◆ selectedBattleOption
| int BattleSystem::selectedBattleOption = -1 |
|
private |
◆ selectedSkill
| Skill* BattleSystem::selectedSkill = nullptr |
|
private |
◆ switchedPersonaThisTurn
| bool BattleSystem::switchedPersonaThisTurn = false |
|
private |
◆ switchPersona
◆ turnsTaken
| u32 BattleSystem::turnsTaken = 0 |
|
private |
The documentation for this class was generated from the following files: