Update to latest CreatureLib, improved DamageLibrary performance.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
df802b561a
commit
e23165d489
|
@ -1,29 +1,31 @@
|
||||||
#include "DamageLibrary.hpp"
|
#include "DamageLibrary.hpp"
|
||||||
#include "../Pokemon/Pokemon.hpp"
|
#include "../Pokemon/Pokemon.hpp"
|
||||||
|
using HitData = const CreatureLib::Battling::ExecutingAttack::HitData;
|
||||||
|
|
||||||
uint32_t PkmnLib::Battling::DamageLibrary::GetDamage(CreatureLib::Battling::ExecutingAttack* attack,
|
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 levelMod = static_cast<float>(2 * attack->GetUser()->GetLevel());
|
||||||
auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex);
|
auto bp = hitData.GetBasePower();
|
||||||
auto bp = hit.GetBasePower();
|
auto statMod = GetStatModifier(attack, target, hitIndex, hitData);
|
||||||
auto statMod = GetStatModifier(attack, target, hitIndex);
|
|
||||||
// HOOK: Modify stat modifier
|
// HOOK: Modify stat modifier
|
||||||
int damage = static_cast<int>((((levelMod * static_cast<float>(bp) * statMod) / 50) + 2) *
|
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
|
// HOOK: Override damage
|
||||||
return damage;
|
return damage;
|
||||||
}
|
}
|
||||||
uint8_t PkmnLib::Battling::DamageLibrary::GetBasePower(CreatureLib::Battling::ExecutingAttack* attack,
|
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();
|
auto bp = attack->GetAttack()->GetAttack()->GetBasePower();
|
||||||
// HOOK: modify base power.
|
// HOOK: modify base power.
|
||||||
return bp;
|
return bp;
|
||||||
}
|
}
|
||||||
float PkmnLib::Battling::DamageLibrary::GetStatModifier(CreatureLib::Battling::ExecutingAttack* attack,
|
float PkmnLib::Battling::DamageLibrary::GetStatModifier(CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
CreatureLib::Battling::Creature* target,
|
CreatureLib::Battling::Creature* target, uint8_t hitIndex,
|
||||||
uint8_t hitIndex) const {
|
const HitData& hitData) const {
|
||||||
auto user = attack->GetUser();
|
auto user = attack->GetUser();
|
||||||
// HOOK: allow overriding for which users stat we use.
|
// HOOK: allow overriding for which users stat we use.
|
||||||
auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex);
|
|
||||||
CreatureLib::Library::Statistic offensiveStat;
|
CreatureLib::Library::Statistic offensiveStat;
|
||||||
CreatureLib::Library::Statistic defensiveStat;
|
CreatureLib::Library::Statistic defensiveStat;
|
||||||
auto learnedMove = static_cast<LearnedMove*>(attack->GetAttack());
|
auto learnedMove = static_cast<LearnedMove*>(attack->GetAttack());
|
||||||
|
@ -36,9 +38,9 @@ float PkmnLib::Battling::DamageLibrary::GetStatModifier(CreatureLib::Battling::E
|
||||||
defensiveStat = Library::Statistic::SpecialDefense;
|
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.
|
// 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.
|
// HOOK: Allow bypassing offensive stat modifiers.
|
||||||
|
|
||||||
float offensiveValue;
|
float offensiveValue;
|
||||||
|
@ -58,11 +60,10 @@ float PkmnLib::Battling::DamageLibrary::GetStatModifier(CreatureLib::Battling::E
|
||||||
return offensiveValue / defensiveValue;
|
return offensiveValue / defensiveValue;
|
||||||
}
|
}
|
||||||
float PkmnLib::Battling::DamageLibrary::GetDamageModifier(CreatureLib::Battling::ExecutingAttack* attack,
|
float PkmnLib::Battling::DamageLibrary::GetDamageModifier(CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
CreatureLib::Battling::Creature* target,
|
CreatureLib::Battling::Creature* target, uint8_t hitIndex,
|
||||||
uint8_t hitIndex) const {
|
const HitData& hitData) const {
|
||||||
float mod = 1;
|
float mod = 1;
|
||||||
auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex);
|
mod *= hitData.GetEffectiveness();
|
||||||
mod *= hit.GetEffectiveness();
|
|
||||||
// HOOK: Modify damage modifier.
|
// HOOK: Modify damage modifier.
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,14 +6,18 @@ namespace PkmnLib::Battling {
|
||||||
class DamageLibrary : public CreatureLib::Battling::DamageLibrary {
|
class DamageLibrary : public CreatureLib::Battling::DamageLibrary {
|
||||||
public:
|
public:
|
||||||
uint32_t GetDamage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
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 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,
|
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,
|
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;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue