132 resource = &actor->
sp;
136 resource = &actor->
hp;
139 bool canAfford = *resource >= s->
cost;
142 *resource -= s->
cost;
211 etl::vector<BattleParticipant*, 13> targets;
216 targets.push_back(partyMember);
223 targets.push_back(enemy);
240 targets.push_back(selectedTarget);
247 bool canHealAnyTarget =
false;
250 if (target->hp < target->maxHp)
252 canHealAnyTarget =
true;
256 if (!canHealAnyTarget)
297 uint8_t participantCount = 0;
300 if (partyMember->canParticipateInAllOutAttack())
309 enemy->knockedDown =
false;
310 TurnResult turnResult = {
true, -(s32)damage,
false, enemy->name +
": "};
342 etl::vector<BattleParticipant*, 13> targets;
346 targets.push_back(partyMember);
409 if (!turnResult.
log.empty())
414 if (turnResult.
hit && target && turnResult.
hpDelta != 0)
416 s32 hpBefore = target->
hp;
417 s32 actuallyHealedHp = turnResult.
hpDelta;
420 if (target->
hp > target->
maxHp)
423 actuallyHealedHp = target->
maxHp - hpBefore;
429 std::sprintf(buf,
"Damage: %ld\n", (
long)-turnResult.
hpDelta);
433 std::sprintf(buf,
"HP healed: %ld\n", (
long)actuallyHealedHp);
437 std::sprintf(buf,
"%s HP: %ld\n", target->
name.c_str(), (
long)target->
hp);
534 ae::q20_12_t boost = ae::q20_12_t{1.2} + MathManager::getInstance().randFrac() * ae::q20_12_t{0.2};
538 battleParticipant->setCurrentTurnOrderAgility(boost);
600 bool enemiesAlive =
false;
621 etl::vector<BattleParticipant*, 13> alive;
626 alive.push_back(enemy);
634 uint8_t aliveCount = 0;
635 uint8_t knockedDownCount = 0;
641 if (enemy->knockedDown)
648 if (knockedDownCount >= aliveCount)
System for managing battle logic & states.
etl::vector< PartyMember *, 4 > partyMembers
PersonaBase * personaBeforeSwitch
bool allEnemiesKnockedDown()
Evaluates if an All-Out Attack condition is met.
void calculateTurnOrder()
Calculates the initial turn queue at the start of an encounter.
bool allOutAttackWasPossibleThisKnockDown
static constexpr u32 ACTION_PERSONA
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
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.
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
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.
void logMessage(LogSeverity severity, std::string_view message, std::source_location location)
Logs a diagnostic message and halts only for fatal messages.
Util to handle error logging.
static u32 allOutAttack(Player &attacker, BattleParticipant &defender, u32 participantCount)
Calculates damage of an All out attack.
virtual void onDead(Event::BattleResult &battleResult)=0
Holds character data which a battleParticipant is created from.
BattleParticipant * pickTarget(etl::vector< BattleParticipant *, 13 > &partyMembers)
TurnResult resolve(BattleParticipant *target, Skill *skill)
Holds data on how the battle concluded.
Event payload to start the BattleSystem.
etl::vector< CharacterProfile, 4 > & characterProfiles
All party members currently on the field.
CharacterProfile & player
The main player character. We need to specifically know them for some things all the time.
BattleStartCondition battleStartCondition
Condition like player advantage, enemy advantage, or even. Used to decide turn order.
etl::vector< EnemyProfile, 8 > & enemyProfiles
All enemies currently on the field.
etl::vector< PersonaBase *, 13 > personas
virtual bool actorCanUse(ActionBase *action)
Result of a singular turn. Note that currently multi target skills do use a seperate turn result for ...