persona-3-dual
A DS demake of Persona 3
Loading...
Searching...
No Matches
BattleSystem.hpp
Go to the documentation of this file.
1
6
7#pragma once
8
10#include "core/routerIDs.hpp"
13#include <aegis/system.hpp>
14
17
18#include <algorithm>
19#include <array>
20#include <etl/vector.h>
21#include <nds.h>
22#include <string>
23
28
38
39// TODO: check for dead code/unfeasible paths
40class BattleSystem : public ae::SystemRouter<BattleSystem, Event::ExecuteBattle>, public ae::Singleton<BattleSystem>
41{
42 public:
43 void init() override;
44
63 void update(ae::q20_12_t /*dt*/) override;
64
65 void shutdown() override;
66
67 // TODO: replace with ae dependancy injection
69
86 void on_receive(const Event::ExecuteBattle& msg);
87
96 void on_receive_unknown(const etl::imessage& msg)
97 {
98 }
99
100 private:
101 friend class Singleton<BattleSystem>;
103 {
104 }
105
106 static constexpr u32 ACTION_ATTACK = 0;
107 static constexpr u32 ACTION_GUARD = 1;
108 static constexpr u32 ACTION_PERSONA = 2;
109 static constexpr u32 ACTION_SWITCH = 3;
110
111 u32 turnsTaken = 0;
112
115
118
121
125
126 std::string pendingAlert;
128
130
131 // Current battle data
132 etl::vector<BattleParticipant*, 13> battleParticipants;
133 etl::vector<Enemy*, 8> enemies;
134 etl::vector<PartyMember*, 4> partyMembers;
135 Player* player = nullptr;
136
138
139 // Actions
144
145 std::array<ActionBase*, 4> actions = {&attack, &guard, &persona, &switchPersona};
146
147 // Internal helpers
158 void applyResult(const TurnResult& r, BattleParticipant* target = nullptr);
159
170 void advanceTurn();
171
182 void setNextPhase(BattlePhase nextPhase);
183
194 void calculateTurnOrder();
195
205
211 etl::vector<BattleParticipant*, 13> getAliveEnemies();
212
219
227 bool isSingleTarget(SkillType type);
228
240
243};
Events for BattleSystem.
BattlePhase
BattleStartCondition
Describes how the Battle was started eg. PartyAdvantage if Player surprised the enemy.
Generic events used across multiple systems.
Orchestrates music.
SkillType
Definition SkillType.hpp:4
Orchestrates rendering text from a bitmap.
etl::vector< PartyMember *, 4 > partyMembers
void init() override
BattlePhase phase
PersonaBase * personaBeforeSwitch
SwitchPersona switchPersona
bool allEnemiesKnockedDown()
Evaluates if an All-Out Attack condition is met.
void calculateTurnOrder()
Calculates the initial turn queue at the start of an encounter.
void shutdown() override
bool allOutAttackWasPossibleThisKnockDown
static constexpr u32 ACTION_PERSONA
std::string pendingAlert
void on_receive_unknown(const etl::imessage &msg)
Fallback handler for unhandled ETL messages.
BattlePhase alertReturnPhase
etl::vector< BattleParticipant *, 13 > battleParticipants
void setMusicComponent(MusicComponent *music)
static bool getParticipantByHigherAgility(BattleParticipant *a, BattleParticipant *b)
Sorting predicate used to order combatants by agility.
bool isSingleTarget(SkillType type)
Determines if a skill targets a single entity.
static constexpr u32 ACTION_GUARD
Skill * selectedSkill
u32 currentParticipantIndex
void handleDeadParticipants()
Sweeps the field for dead participants and evaluates encounter end conditions.
void advanceTurn()
Progresses the battle state machine to the next logical step.
BattleStartCondition battleStartCondition
void on_receive(const Event::ExecuteBattle &msg)
ETL message handler that initializes and starts a new battle.
bool switchedPersonaThisTurn
void update(ae::q20_12_t) override
Core update loop that processes the battle state machine and turn resolution.
etl::vector< BattleParticipant *, 13 > getAliveEnemies()
Filters the enemy roster for living combatants.
PersonaAction persona
void setNextPhase(BattlePhase nextPhase)
Safely transitions the state machine to a new BattlePhase.
BattleParticipant * currentParticipantTurn
static constexpr u32 ACTION_SWITCH
std::array< ActionBase *, 4 > actions
AttackAction attack
bool pendingPersonaSwitch
static constexpr u32 ACTION_ATTACK
etl::vector< Enemy *, 8 > enemies
BattleMenu * battleMenuCmpt
Event::BattleResult battleResult
MusicComponent * musicCmpt
void applyResult(const TurnResult &r, BattleParticipant *target=nullptr)
Resolves the mathematical and state changes of a combat action against a target.
Holds routerIDs used for systems.
constexpr etl::message_router_id_t kBattleSystemRouterID
Definition routerIDs.hpp:9
Participant of battle.
ae::q20_12_t currentTurnOrderAgility
Holds data on how the battle concluded.
Event payload to start the BattleSystem.
Definition Guard.hpp:6
Result of a singular turn. Note that currently multi target skills do use a seperate turn result for ...