Implementation of damage calculation.
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
This commit is contained in:
66
src/Battling/Library/DamageLibrary.cpp
Normal file
66
src/Battling/Library/DamageLibrary.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include "DamageLibrary.hpp"
|
||||
|
||||
using namespace CreatureLib::Battling;
|
||||
int DamageLibrary::GetDamage(ExecutingAttack *attack, Creature *target, uint8_t hitIndex) const{
|
||||
auto levelMod = static_cast<float>(2 * attack->GetUser()->GetLevel());
|
||||
auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex);
|
||||
auto bp = hit.GetBasePower();
|
||||
auto statMod = GetStatModifier(attack, target, hitIndex);
|
||||
//HOOK: Modify stat modifier
|
||||
int damage = static_cast<int>((((levelMod * static_cast<float>(bp) * statMod) / 50) + 2)
|
||||
* GetDamageModifier(attack, target, hitIndex));
|
||||
//HOOK: Override damage
|
||||
return damage;
|
||||
}
|
||||
|
||||
int DamageLibrary::GetBasePower(ExecutingAttack *attack, Creature *target, uint8_t hitIndex) const{
|
||||
auto bp = attack->GetAttack()->GetAttack()->GetBasePower();
|
||||
//HOOK: modify base power.
|
||||
return bp;
|
||||
}
|
||||
|
||||
float DamageLibrary::GetStatModifier(ExecutingAttack *attack, Creature *target, uint8_t hitIndex) const{
|
||||
auto user = attack->GetUser();
|
||||
//HOOK: allow overriding for which users stat we use.
|
||||
auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex);
|
||||
Core::Statistic offensiveStat;
|
||||
Core::Statistic defensiveStat;
|
||||
if (attack->GetAttack()->GetAttack()->GetCategory() == Library::AttackCategory::Physical){
|
||||
offensiveStat = Core::Statistic::PhysicalAttack;
|
||||
defensiveStat = Core::Statistic::PhysicalDefense;
|
||||
}
|
||||
else{
|
||||
offensiveStat = Core::Statistic::MagicalAttack;
|
||||
defensiveStat = Core::Statistic::MagicalDefense;
|
||||
}
|
||||
|
||||
auto bypassDefensive = hit.IsCritical() && target->GetStatBoost(defensiveStat) > 0;
|
||||
//HOOK: allow bypassing defensive stat modifiers.
|
||||
auto bypassOffensive = hit.IsCritical() && user->GetStatBoost(offensiveStat) < 0;
|
||||
//HOOK: Allow bypassing offensive stat modifiers.
|
||||
|
||||
float offensiveValue;
|
||||
float defensiveValue;
|
||||
|
||||
if (bypassOffensive){
|
||||
offensiveValue = user->GetFlatStat(offensiveStat);
|
||||
} else{
|
||||
offensiveValue = user->GetBoostedStat(offensiveStat);
|
||||
}
|
||||
if (bypassDefensive){
|
||||
defensiveValue = target->GetFlatStat(defensiveStat);
|
||||
} else{
|
||||
defensiveValue = target->GetBoostedStat(defensiveStat);
|
||||
}
|
||||
|
||||
return offensiveValue / defensiveValue;
|
||||
}
|
||||
|
||||
float DamageLibrary::GetDamageModifier(ExecutingAttack *attack, Creature *target, uint8_t hitIndex) const{
|
||||
float mod = 1;
|
||||
auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex);
|
||||
mod *= hit.GetEffectiveness();
|
||||
//HOOK: Modify damage modifier.
|
||||
return mod;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user