Update to latest CreatureLib, improved DamageLibrary performance.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-04-25 16:59:27 +02:00
parent df802b561a
commit e23165d489
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 24 additions and 19 deletions

View File

@ -1,29 +1,31 @@
#include "DamageLibrary.hpp"
#include "../Pokemon/Pokemon.hpp"
using HitData = const CreatureLib::Battling::ExecutingAttack::HitData;
uint32_t PkmnLib::Battling::DamageLibrary::GetDamage(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target, uint8_t hitIndex) const {
CreatureLib::Battling::Creature* target, uint8_t hitIndex,
const HitData& hitData) 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);
auto bp = hitData.GetBasePower();
auto statMod = GetStatModifier(attack, target, hitIndex, hitData);
// HOOK: Modify stat modifier
int damage = static_cast<int>((((levelMod * static_cast<float>(bp) * statMod) / 50) + 2) *
GetDamageModifier(attack, target, hitIndex));
GetDamageModifier(attack, target, hitIndex, hitData));
// HOOK: Override damage
return damage;
}
uint8_t PkmnLib::Battling::DamageLibrary::GetBasePower(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target, uint8_t hitIndex) const {
CreatureLib::Battling::Creature* target, uint8_t hitIndex,
const HitData& hitData) const {
auto bp = attack->GetAttack()->GetAttack()->GetBasePower();
// HOOK: modify base power.
return bp;
}
float PkmnLib::Battling::DamageLibrary::GetStatModifier(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target,
uint8_t hitIndex) const {
CreatureLib::Battling::Creature* target, uint8_t hitIndex,
const HitData& hitData) const {
auto user = attack->GetUser();
// HOOK: allow overriding for which users stat we use.
auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex);
CreatureLib::Library::Statistic offensiveStat;
CreatureLib::Library::Statistic defensiveStat;
auto learnedMove = static_cast<LearnedMove*>(attack->GetAttack());
@ -36,9 +38,9 @@ float PkmnLib::Battling::DamageLibrary::GetStatModifier(CreatureLib::Battling::E
defensiveStat = Library::Statistic::SpecialDefense;
}
auto bypassDefensive = hit.IsCritical() && target->GetStatBoost(defensiveStat) > 0;
auto bypassDefensive = hitData.IsCritical() && target->GetStatBoost(defensiveStat) > 0;
// HOOK: allow bypassing defensive stat modifiers.
auto bypassOffensive = hit.IsCritical() && user->GetStatBoost(offensiveStat) < 0;
auto bypassOffensive = hitData.IsCritical() && user->GetStatBoost(offensiveStat) < 0;
// HOOK: Allow bypassing offensive stat modifiers.
float offensiveValue;
@ -58,11 +60,10 @@ float PkmnLib::Battling::DamageLibrary::GetStatModifier(CreatureLib::Battling::E
return offensiveValue / defensiveValue;
}
float PkmnLib::Battling::DamageLibrary::GetDamageModifier(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target,
uint8_t hitIndex) const {
CreatureLib::Battling::Creature* target, uint8_t hitIndex,
const HitData& hitData) const {
float mod = 1;
auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex);
mod *= hit.GetEffectiveness();
mod *= hitData.GetEffectiveness();
// HOOK: Modify damage modifier.
return mod;
}

View File

@ -6,14 +6,18 @@ namespace PkmnLib::Battling {
class DamageLibrary : public CreatureLib::Battling::DamageLibrary {
public:
uint32_t GetDamage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
uint8_t hitIndex) const override;
uint8_t hitIndex,
const CreatureLib::Battling::ExecutingAttack::HitData& hitData) const override;
uint8_t GetBasePower(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
uint8_t hitIndex) const override;
uint8_t hitIndex,
const CreatureLib::Battling::ExecutingAttack::HitData& hitData) const override;
float GetStatModifier(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
uint8_t hitIndex) const override;
uint8_t hitIndex,
const CreatureLib::Battling::ExecutingAttack::HitData& hitData) const override;
float GetDamageModifier(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
uint8_t hitIndex) const override;
uint8_t hitIndex,
const CreatureLib::Battling::ExecutingAttack::HitData& hitData) const override;
};
}