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:
@@ -29,3 +29,12 @@ const CreatureLib::Library::ItemLibrary* CreatureLib::Battling::BattleLibrary::G
|
||||
const CreatureLib::Library::AttackLibrary *CreatureLib::Battling::BattleLibrary::GetAttackLibrary() const {
|
||||
return _staticLib->GetAttackLibrary();
|
||||
}
|
||||
|
||||
const CreatureLib::Library::TypeLibrary *CreatureLib::Battling::BattleLibrary::GetTypeLibrary() const {
|
||||
return _staticLib->GetTypeLibrary();
|
||||
}
|
||||
|
||||
const CreatureLib::Battling::DamageLibrary *CreatureLib::Battling::BattleLibrary::GetDamageLibrary() const {
|
||||
return _damageLibrary;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
|
||||
#include "BattleStatCalculator.hpp"
|
||||
#include "../../Library/DataLibrary.hpp"
|
||||
#include "DamageLibrary.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class BattleLibrary {
|
||||
const Library::DataLibrary* _staticLib;
|
||||
BattleStatCalculator* _statCalculator;
|
||||
DamageLibrary* _damageLibrary;
|
||||
public:
|
||||
BattleLibrary(Library::DataLibrary* staticLib, BattleStatCalculator* statCalculator);
|
||||
~BattleLibrary();
|
||||
@@ -19,6 +21,7 @@ namespace CreatureLib::Battling {
|
||||
const Library::TypeLibrary* GetTypeLibrary() const;
|
||||
|
||||
const BattleStatCalculator* GetStatCalculator() const;
|
||||
const DamageLibrary* GetDamageLibrary() const;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
19
src/Battling/Library/DamageLibrary.hpp
Normal file
19
src/Battling/Library/DamageLibrary.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef CREATURELIB_DAMAGELIBRARY_HPP
|
||||
#define CREATURELIB_DAMAGELIBRARY_HPP
|
||||
|
||||
#include "../Models/Creature.hpp"
|
||||
#include "../Models/ExecutingAttack.hpp"
|
||||
|
||||
namespace CreatureLib::Battling{
|
||||
class DamageLibrary {
|
||||
public:
|
||||
virtual int GetDamage(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const;
|
||||
|
||||
virtual int GetBasePower(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const;
|
||||
virtual float GetStatModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const;
|
||||
virtual float GetDamageModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //CREATURELIB_DAMAGELIBRARY_HPP
|
||||
Reference in New Issue
Block a user