Register many battle classes in AngelScript.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
68
src/Battling/Library/DamageLibrary.cpp
Normal file
68
src/Battling/Library/DamageLibrary.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#include "DamageLibrary.hpp"
|
||||
#include "../Pokemon/Pokemon.hpp"
|
||||
int PkmnLib::Battling::DamageLibrary::GetDamage(CreatureLib::Battling::ExecutingAttack* attack,
|
||||
CreatureLib::Battling::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 PkmnLib::Battling::DamageLibrary::GetBasePower(CreatureLib::Battling::ExecutingAttack* attack,
|
||||
CreatureLib::Battling::Creature* target, uint8_t hitIndex) 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 {
|
||||
auto user = attack->GetUser();
|
||||
// HOOK: allow overriding for which users stat we use.
|
||||
auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex);
|
||||
CreatureLib::Core::Statistic offensiveStat;
|
||||
CreatureLib::Core::Statistic defensiveStat;
|
||||
auto learnedMove = dynamic_cast<LearnedMove*>(attack->GetAttack());
|
||||
auto moveData = learnedMove->GetMoveData();
|
||||
if (moveData->GetCategory() == Library::MoveCategory::Physical) {
|
||||
offensiveStat = Library::Statistic::PhysicalAttack;
|
||||
defensiveStat = Library::Statistic::PhysicalDefense;
|
||||
} else {
|
||||
offensiveStat = Library::Statistic::SpecialAttack;
|
||||
defensiveStat = Library::Statistic::SpecialDefense;
|
||||
}
|
||||
|
||||
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 PkmnLib::Battling::DamageLibrary::GetDamageModifier(CreatureLib::Battling::ExecutingAttack* attack,
|
||||
CreatureLib::Battling::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