Added lots of security using asserts.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#include "BattleLibrary.hpp"
|
||||
#include <cassert>
|
||||
|
||||
using namespace CreatureLib::Battling;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "BattleStatCalculator.hpp"
|
||||
#include <Arbutils/Assert.hpp>
|
||||
#include "../../Library/Exceptions/NotImplementedException.hpp"
|
||||
#include "../Models/Creature.hpp"
|
||||
|
||||
@@ -24,12 +25,14 @@ Battling::BattleStatCalculator::CalculateBoostedStats(Battling::Creature* creatu
|
||||
}
|
||||
|
||||
uint32_t CalculateHealthStat(Battling::Creature* creature) {
|
||||
AssertNotNull(creature)
|
||||
auto level = creature->GetLevel();
|
||||
auto a = (creature->GetBaseStat(Library::Statistic::Health)) * 2 * level;
|
||||
return floor(a / 100) + level + 10;
|
||||
}
|
||||
|
||||
uint32_t CalculateOtherStat(Battling::Creature* creature, Library::Statistic stat) {
|
||||
AssertNotNull(creature)
|
||||
auto level = creature->GetLevel();
|
||||
auto a = (creature->GetBaseStat(stat)) * 2 * level;
|
||||
return floor(a / 100) + 10;
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#include "DamageLibrary.hpp"
|
||||
#include <Arbutils/Assert.hpp>
|
||||
#include "../ScriptHandling/ScriptMacros.hpp"
|
||||
|
||||
using namespace CreatureLib::Battling;
|
||||
uint32_t DamageLibrary::GetDamage(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const {
|
||||
AssertNotNull(attack)
|
||||
AssertNotNull(target)
|
||||
auto levelMod = static_cast<float>(2 * attack->GetUser()->GetLevel());
|
||||
auto hit = attack->GetAttackDataForTarget(target)->GetHit(hitIndex);
|
||||
auto bp = hit->GetBasePower();
|
||||
@@ -15,13 +18,18 @@ uint32_t DamageLibrary::GetDamage(ExecutingAttack* attack, Creature* target, uin
|
||||
}
|
||||
|
||||
uint8_t DamageLibrary::GetBasePower(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const {
|
||||
AssertNotNull(attack)
|
||||
AssertNotNull(target)
|
||||
auto bp = attack->GetAttack()->GetAttack()->GetBasePower();
|
||||
HOOK(OverrideBasePower, attack, attack, target, hitIndex, &bp);
|
||||
return bp;
|
||||
}
|
||||
|
||||
float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const {
|
||||
AssertNotNull(attack)
|
||||
AssertNotNull(target)
|
||||
auto user = attack->GetUser();
|
||||
AssertNotNull(user)
|
||||
HOOK(ChangeDamageStatsUser, attack, attack, target, hitIndex, &user);
|
||||
auto hit = attack->GetAttackDataForTarget(target)->GetHit(hitIndex);
|
||||
Library::Statistic offensiveStat;
|
||||
@@ -57,8 +65,11 @@ float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target,
|
||||
}
|
||||
|
||||
float DamageLibrary::GetDamageModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const {
|
||||
AssertNotNull(attack)
|
||||
AssertNotNull(target)
|
||||
float mod = 1;
|
||||
auto hit = attack->GetAttackDataForTarget(target)->GetHit(hitIndex);
|
||||
AssertNotNull(hit)
|
||||
mod *= hit->GetEffectiveness();
|
||||
HOOK(ModifyDamageModifier, attack, attack, target, hitIndex, &mod);
|
||||
return mod;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
void CreatureLib::Battling::ExperienceLibrary::HandleExperienceGain(
|
||||
CreatureLib::Battling::Creature* faintedMon, const std::unordered_set<Creature*>& opponents) const {
|
||||
for (auto opponent : opponents) {
|
||||
if (opponent == nullptr)
|
||||
continue;
|
||||
auto levelDiff = faintedMon->GetLevel() - opponent->GetLevel() + 10;
|
||||
if (levelDiff <= 0)
|
||||
continue;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
#include "MiscLibrary.hpp"
|
||||
#include <Arbutils/Assert.hpp>
|
||||
#include "../Models/Battle.hpp"
|
||||
#include "../TurnChoices/AttackTurnChoice.hpp"
|
||||
|
||||
bool CreatureLib::Battling::MiscLibrary::IsCritical(CreatureLib::Battling::ExecutingAttack* attack,
|
||||
CreatureLib::Battling::Creature* target, uint8_t hit) const {
|
||||
AssertNotNull(target)
|
||||
auto rand = target->GetBattle()->GetRandom();
|
||||
return rand->Get(10) <= 0;
|
||||
}
|
||||
@@ -31,6 +33,7 @@ static CreatureLib::Battling::LearnedAttack* GetReplacementAttack() {
|
||||
bool CreatureLib::Battling::MiscLibrary::CanFlee(FleeTurnChoice* switchChoice) const { return true; }
|
||||
CreatureLib::Battling::BaseTurnChoice*
|
||||
CreatureLib::Battling::MiscLibrary::ReplacementAttack(Creature* user, CreatureIndex target) const {
|
||||
AssertNotNull(user)
|
||||
auto sideTarget = 0;
|
||||
if (user->GetBattleSide()->GetSideIndex() == 0)
|
||||
sideTarget = 1;
|
||||
|
||||
Reference in New Issue
Block a user