Pass HitData as reference to damage calculation library, to prevent multiple lookup.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
864a9d933d
commit
8eb22ad68d
|
@ -7,19 +7,23 @@ export const DamageLibrary* CreatureLib_DamageLibrary_Construct() { return new D
|
||||||
export void CreatureLib_DamageLibrary_Destruct(const DamageLibrary* p) { delete p; }
|
export void CreatureLib_DamageLibrary_Destruct(const DamageLibrary* p) { delete p; }
|
||||||
|
|
||||||
export uint8_t CreatureLib_DamageLibrary_GetDamage(uint32_t& out, const DamageLibrary* p, ExecutingAttack* attack,
|
export uint8_t CreatureLib_DamageLibrary_GetDamage(uint32_t& out, const DamageLibrary* p, ExecutingAttack* attack,
|
||||||
Creature* target, uint8_t hitIndex) {
|
Creature* target, uint8_t hitIndex,
|
||||||
Try(out = p->GetDamage(attack, target, hitIndex);)
|
ExecutingAttack::HitData* hitData) {
|
||||||
|
Try(out = p->GetDamage(attack, target, hitIndex, *hitData);)
|
||||||
}
|
}
|
||||||
|
|
||||||
export uint8_t CreatureLib_DamageLibrary_GetBasePower(uint8_t& out, const DamageLibrary* p, ExecutingAttack* attack,
|
export uint8_t CreatureLib_DamageLibrary_GetBasePower(uint8_t& out, const DamageLibrary* p, ExecutingAttack* attack,
|
||||||
Creature* target, uint8_t hitIndex) {
|
Creature* target, uint8_t hitIndex,
|
||||||
Try(out = p->GetBasePower(attack, target, hitIndex);)
|
ExecutingAttack::HitData* hitData) {
|
||||||
|
Try(out = p->GetBasePower(attack, target, hitIndex, *hitData);)
|
||||||
}
|
}
|
||||||
export float CreatureLib_DamageLibrary_GetStatModifier(float& out, const DamageLibrary* p, ExecutingAttack* attack,
|
export float CreatureLib_DamageLibrary_GetStatModifier(float& out, const DamageLibrary* p, ExecutingAttack* attack,
|
||||||
Creature* target, uint8_t hitIndex) {
|
Creature* target, uint8_t hitIndex,
|
||||||
Try(out = p->GetStatModifier(attack, target, hitIndex);)
|
ExecutingAttack::HitData* hitData) {
|
||||||
|
Try(out = p->GetStatModifier(attack, target, hitIndex, *hitData);)
|
||||||
}
|
}
|
||||||
export float CreatureLib_DamageLibrary_GetDamageModifier(float& out, const DamageLibrary* p, ExecutingAttack* attack,
|
export float CreatureLib_DamageLibrary_GetDamageModifier(float& out, const DamageLibrary* p, ExecutingAttack* attack,
|
||||||
Creature* target, uint8_t hitIndex) {
|
Creature* target, uint8_t hitIndex,
|
||||||
Try(out = p->GetDamageModifier(attack, target, hitIndex);)
|
ExecutingAttack::HitData* hitData) {
|
||||||
|
Try(out = p->GetDamageModifier(attack, target, hitIndex, *hitData);)
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,8 +147,8 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
|
||||||
HOOK(ChangeEffectiveness, attack, attack, target, hitIndex, &effectiveness)
|
HOOK(ChangeEffectiveness, attack, attack, target, hitIndex, &effectiveness)
|
||||||
hit.SetEffectiveness(effectiveness);
|
hit.SetEffectiveness(effectiveness);
|
||||||
hit.SetCritical(library->GetMiscLibrary()->IsCritical(attack, target, hitIndex));
|
hit.SetCritical(library->GetMiscLibrary()->IsCritical(attack, target, hitIndex));
|
||||||
hit.SetBasePower(dmgLibrary->GetBasePower(attack, target, hitIndex));
|
hit.SetBasePower(dmgLibrary->GetBasePower(attack, target, hitIndex, hit));
|
||||||
hit.SetDamage(dmgLibrary->GetDamage(attack, target, hitIndex));
|
hit.SetDamage(dmgLibrary->GetDamage(attack, target, hitIndex, hit));
|
||||||
|
|
||||||
if (attackData->GetCategory() == Library::AttackCategory::Status) {
|
if (attackData->GetCategory() == Library::AttackCategory::Status) {
|
||||||
if (attackData->HasSecondaryEffect()) {
|
if (attackData->HasSecondaryEffect()) {
|
||||||
|
|
|
@ -3,21 +3,22 @@
|
||||||
#include "../ScriptHandling/ScriptMacros.hpp"
|
#include "../ScriptHandling/ScriptMacros.hpp"
|
||||||
|
|
||||||
using namespace CreatureLib::Battling;
|
using namespace CreatureLib::Battling;
|
||||||
uint32_t DamageLibrary::GetDamage(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const {
|
uint32_t DamageLibrary::GetDamage(ExecutingAttack* attack, Creature* target, uint8_t hitIndex,
|
||||||
|
const ExecutingAttack::HitData& hitData) const {
|
||||||
AssertNotNull(attack)
|
AssertNotNull(attack)
|
||||||
AssertNotNull(target)
|
AssertNotNull(target)
|
||||||
auto levelMod = static_cast<float>(2 * attack->GetUser()->GetLevel()) / 5 + 2;
|
auto levelMod = static_cast<float>(2 * attack->GetUser()->GetLevel()) / 5 + 2;
|
||||||
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(ModifyStatModifier, attack, attack, target, hitIndex, &statMod);
|
HOOK(ModifyStatModifier, attack, attack, target, hitIndex, &statMod);
|
||||||
uint32_t damage = static_cast<uint32_t>((((levelMod * static_cast<float>(bp) * statMod) / 50) + 2) *
|
uint32_t damage = static_cast<uint32_t>((((levelMod * static_cast<float>(bp) * statMod) / 50) + 2) *
|
||||||
GetDamageModifier(attack, target, hitIndex));
|
GetDamageModifier(attack, target, hitIndex, hitData));
|
||||||
HOOK(OverrideDamage, attack, attack, target, hitIndex, &damage);
|
HOOK(OverrideDamage, attack, attack, target, hitIndex, &damage);
|
||||||
return damage;
|
return damage;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t DamageLibrary::GetBasePower(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const {
|
uint8_t DamageLibrary::GetBasePower(ExecutingAttack* attack, Creature* target, uint8_t hitIndex,
|
||||||
|
const ExecutingAttack::HitData& hitData) const {
|
||||||
AssertNotNull(attack)
|
AssertNotNull(attack)
|
||||||
AssertNotNull(target)
|
AssertNotNull(target)
|
||||||
auto bp = attack->GetAttack()->GetAttack()->GetBasePower();
|
auto bp = attack->GetAttack()->GetAttack()->GetBasePower();
|
||||||
|
@ -25,13 +26,13 @@ uint8_t DamageLibrary::GetBasePower(ExecutingAttack* attack, Creature* target, u
|
||||||
return bp;
|
return bp;
|
||||||
}
|
}
|
||||||
|
|
||||||
float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const {
|
float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex,
|
||||||
|
const ExecutingAttack::HitData& hitData) const {
|
||||||
AssertNotNull(attack)
|
AssertNotNull(attack)
|
||||||
AssertNotNull(target)
|
AssertNotNull(target)
|
||||||
auto user = attack->GetUser();
|
auto user = attack->GetUser();
|
||||||
AssertNotNull(user)
|
AssertNotNull(user)
|
||||||
HOOK(ChangeDamageStatsUser, attack, attack, target, hitIndex, &user);
|
HOOK(ChangeDamageStatsUser, attack, attack, target, hitIndex, &user);
|
||||||
auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex);
|
|
||||||
Library::Statistic offensiveStat;
|
Library::Statistic offensiveStat;
|
||||||
Library::Statistic defensiveStat;
|
Library::Statistic defensiveStat;
|
||||||
if (attack->GetAttack()->GetAttack()->GetCategory() == Library::AttackCategory::Physical) {
|
if (attack->GetAttack()->GetAttack()->GetCategory() == Library::AttackCategory::Physical) {
|
||||||
|
@ -42,9 +43,9 @@ float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target,
|
||||||
defensiveStat = Library::Statistic::MagicalDefense;
|
defensiveStat = Library::Statistic::MagicalDefense;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto bypassDefensive = hit.IsCritical() && target->GetStatBoost(defensiveStat) > 0;
|
auto bypassDefensive = hitData.IsCritical() && target->GetStatBoost(defensiveStat) > 0;
|
||||||
HOOK(BypassDefensiveStat, attack, attack, target, hitIndex, &bypassDefensive);
|
HOOK(BypassDefensiveStat, attack, attack, target, hitIndex, &bypassDefensive);
|
||||||
auto bypassOffensive = hit.IsCritical() && user->GetStatBoost(offensiveStat) < 0;
|
auto bypassOffensive = hitData.IsCritical() && user->GetStatBoost(offensiveStat) < 0;
|
||||||
HOOK(BypassOffensiveStat, attack, attack, target, hitIndex, &bypassOffensive);
|
HOOK(BypassOffensiveStat, attack, attack, target, hitIndex, &bypassOffensive);
|
||||||
|
|
||||||
float offensiveValue;
|
float offensiveValue;
|
||||||
|
@ -64,12 +65,12 @@ float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target,
|
||||||
return offensiveValue / defensiveValue;
|
return offensiveValue / defensiveValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
float DamageLibrary::GetDamageModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const {
|
float DamageLibrary::GetDamageModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex,
|
||||||
|
const ExecutingAttack::HitData& hitData) const {
|
||||||
AssertNotNull(attack)
|
AssertNotNull(attack)
|
||||||
AssertNotNull(target)
|
AssertNotNull(target)
|
||||||
float mod = 1;
|
float mod = 1;
|
||||||
auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex);
|
mod *= hitData.GetEffectiveness();
|
||||||
mod *= hit.GetEffectiveness();
|
|
||||||
HOOK(ModifyDamageModifier, attack, attack, target, hitIndex, &mod);
|
HOOK(ModifyDamageModifier, attack, attack, target, hitIndex, &mod);
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,15 @@ namespace CreatureLib::Battling {
|
||||||
class DamageLibrary {
|
class DamageLibrary {
|
||||||
public:
|
public:
|
||||||
virtual ~DamageLibrary() = default;
|
virtual ~DamageLibrary() = default;
|
||||||
virtual uint32_t GetDamage(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const;
|
virtual uint32_t GetDamage(ExecutingAttack* attack, Creature* target, uint8_t hitIndex,
|
||||||
|
const ExecutingAttack::HitData& hitData) const;
|
||||||
|
|
||||||
virtual uint8_t GetBasePower(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const;
|
virtual uint8_t GetBasePower(ExecutingAttack* attack, Creature* target, uint8_t hitIndex,
|
||||||
virtual float GetStatModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const;
|
const ExecutingAttack::HitData& hitData) const;
|
||||||
virtual float GetDamageModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const;
|
virtual float GetStatModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex,
|
||||||
|
const ExecutingAttack::HitData& hitData) const;
|
||||||
|
virtual float GetDamageModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex,
|
||||||
|
const ExecutingAttack::HitData& hitData) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue