persona-3-dual
A DS demake of Persona 3
Loading...
Searching...
No Matches
PersonaAction.cpp
Go to the documentation of this file.
1#include "PersonaAction.hpp"
3#include "core/logger.hpp"
4#include <stdlib.h>
5
7{
8 if (user == nullptr || skill == nullptr)
9 {
10 logMessage(LogSeverity::ERROR, "Called with null user or skill");
11 return {false, 0, false, "Miss"};
12 }
13
14 logMessage(LogSeverity::DEBUG, "PersonaAction " + skill->name + " resolving for user: " + user->name);
15
16 //TODO: same as attack actioon, get rid off in the futrue
18 {
19 if (target == nullptr)
20 {
21 logMessage(LogSeverity::ERROR, "Called with null target");
22 return {false, 0, false, "Miss"};
23 }
24
25 Enemy* enemy = static_cast<Enemy*>(target);
26
27 bool hit = BattleCalcs::hit(*user, *target, *skill);
28
29 if (!hit)
30 {
31 return {false, 0, false, "Miss"};
32 }
33
34 u32 damage = BattleCalcs::attack(*user, *target, *skill);
35 bool oneMore = false;
36
37 u32 affinity = enemy->battleStats.affinities[(u32)skill->element];
38 if (affinity == BattleStats::Affinity::Weak && !enemy->knockedDown)
39 {
40 oneMore = true;
41 enemy->knockedDown = true;
42 }
43
44 return {true, -(s32)damage, oneMore, skill->name};
45 }
46 else if (skill->skillType == SkillType::Heal || skill->skillType == SkillType::MultiHeal)
47 {
48 u32 healed = BattleCalcs::healing(*user, *skill);
49 return {true, (s32)healed, false, skill->name};
50 }
51
52 return {false, 0, false, skill->name};
53}
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.
static u32 healing(BattleParticipant &user, Skill &skill)
Calculates heal of a skill.
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
TurnResult resolve(PartyMember *user, BattleParticipant *target, Skill *skill) override
std::string name
Definition Skill.hpp:11
Element element
Definition Skill.hpp:13
SkillType skillType
Definition Skill.hpp:16
Result of a singular turn. Note that currently multi target skills do use a seperate turn result for ...