persona-3-dual
A DS demake of Persona 3
Loading...
Searching...
No Matches
AttackAction.cpp
Go to the documentation of this file.
1#include "AttackAction.hpp"
3#include "core/logger.hpp"
4#include <stdlib.h>
5
6//ignore skill here
8{
9 if (user == nullptr || target == nullptr || user->baseAttackAction == nullptr)
10 {
11 logMessage(LogSeverity::ERROR, "Called with null user, target, or attack action");
12 return {false, 0, false, "Miss"};
13 }
14
15 logMessage(LogSeverity::DEBUG, "Attack action resolving: " + user->name + " attacking " + target->name);
16
17 Skill* atk = user->baseAttackAction;
18 Enemy* enemy = static_cast<Enemy*>(target);
19
20 bool hit = BattleCalcs::hit(*user, *target, *atk);
21
22 if (!hit)
23 {
24 return {false, 0, false, "Miss"};
25 }
26
27 u32 damage = BattleCalcs::attack(*user, *target, *atk);
28 bool oneMore = false;
29
30 u32 affinity = enemy->battleStats.affinities[(u32)atk->element];
31 if (affinity == BattleStats::Affinity::Weak && !enemy->knockedDown)
32 {
33 oneMore = true;
34 enemy->knockedDown = true;
35 }
36
37 return {true, -(s32)damage, oneMore, atk->name};
38}
void logMessage(LogSeverity severity, std::string_view message, std::source_location location)
Logs a diagnostic message and halts only for fatal messages.
Definition logger.cpp:110
Util to handle error logging.
TurnResult resolve(PartyMember *user, BattleParticipant *target, Skill *skill=nullptr) override
static bool hit(BattleParticipant &attacker, BattleParticipant &defender, Skill &skill)
Calculates if a skill hit the target.
static u32 attack(BattleParticipant &attacker, BattleParticipant &defender, Skill &skill)
Calculates damage of an attack.
Participant of battle.
Affinity affinities[11]
Definition Enemy.hpp:9
BattleStats battleStats
Definition Enemy.hpp:12
std::string name
Definition Skill.hpp:11
Element element
Definition Skill.hpp:13
Result of a singular turn. Note that currently multi target skills do use a seperate turn result for ...