From 191b128125f135fd8d22e947a1c18686b2878d59 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 5 Jan 2020 15:18:30 +0100 Subject: [PATCH] Implements Pokemon stat calculation. --- conanfile.py | 2 +- src/Battling/Library/BattleLibrary.hpp | 3 +- src/Battling/Library/StatCalculator.cpp | 70 +++++++++++ src/Battling/Library/StatCalculator.hpp | 33 +++++ src/Battling/Pokemon/CreatePokemon.cpp | 26 +++- src/Battling/Pokemon/CreatePokemon.hpp | 8 +- src/Battling/Pokemon/Pokemon.cpp | 5 +- src/Battling/Pokemon/Pokemon.hpp | 9 +- src/Library/Natures/Nature.hpp | 8 ++ tests/LibraryTests/StatCalculationTests.cpp | 133 ++++++++++++++++++++ tests/TestLibrary/TestLibrary.cpp | 31 +++++ tests/TestLibrary/TestLibrary.hpp | 26 +--- 12 files changed, 323 insertions(+), 31 deletions(-) create mode 100644 src/Battling/Library/StatCalculator.cpp create mode 100644 src/Battling/Library/StatCalculator.hpp create mode 100644 tests/LibraryTests/StatCalculationTests.cpp diff --git a/conanfile.py b/conanfile.py index 92c0056..dccaadc 100644 --- a/conanfile.py +++ b/conanfile.py @@ -12,7 +12,7 @@ class PkmnLibConan(ConanFile): generators = "cmake" exports_sources = "*" compiler = "clang" - requires = "CreatureLib/dd8d4d738d3574933c8f071220028d0088fbb326@creaturelib/master" + requires = "CreatureLib/144d17d859e134c17cdb45c32f4a7e4f68eeb7a0@creaturelib/master" def build(self): cmake = CMake(self) diff --git a/src/Battling/Library/BattleLibrary.hpp b/src/Battling/Library/BattleLibrary.hpp index 32b7daf..393bac1 100644 --- a/src/Battling/Library/BattleLibrary.hpp +++ b/src/Battling/Library/BattleLibrary.hpp @@ -3,11 +3,12 @@ #include #include "../../Library/PokemonLibrary.hpp" +#include "StatCalculator.hpp" namespace PkmnLib::Battling { class BattleLibrary : public CreatureLib::Battling::BattleLibrary { public: - BattleLibrary(Library::PokemonLibrary* staticLib, CreatureLib::Battling::BattleStatCalculator* statCalculator, + BattleLibrary(Library::PokemonLibrary* staticLib, StatCalculator* statCalculator, CreatureLib::Battling::DamageLibrary* damageLibrary, CreatureLib::Battling::ExperienceLibrary* experienceLibrary, CreatureLib::Battling::ScriptResolver* scriptResolver, diff --git a/src/Battling/Library/StatCalculator.cpp b/src/Battling/Library/StatCalculator.cpp new file mode 100644 index 0000000..d68bfd8 --- /dev/null +++ b/src/Battling/Library/StatCalculator.cpp @@ -0,0 +1,70 @@ +#include "StatCalculator.hpp" +#include "../Pokemon/Pokemon.hpp" + +uint32_t PkmnLib::Battling::StatCalculator::CalculateHealthStat(const Pokemon* pkmn) const { + uint32_t base = pkmn->GetBaseStat(Library::Statistic::HealthPoints); + uint32_t iv = pkmn->GetIndividualValue(Library::Statistic::HealthPoints); + uint32_t ev = pkmn->GetEffortValue(Library::Statistic::HealthPoints); + uint8_t level = pkmn->GetLevel(); + return static_cast(((2 * base + iv + static_cast(ev / 4)) * level) / 100) + level + 10; +} +uint32_t PkmnLib::Battling::StatCalculator::CalculateOtherStat(const Pokemon* pkmn, + CreatureLib::Core::Statistic stat) const { + uint32_t base = pkmn->GetBaseStat(stat); + uint32_t iv = pkmn->GetIndividualValue(stat); + uint32_t ev = pkmn->GetEffortValue(stat); + uint8_t level = pkmn->GetLevel(); + uint32_t unmodified = + static_cast(((2 * base + iv + static_cast(ev / 4)) * level) / 100) + 5; + return static_cast(unmodified * pkmn->GetNature().GetStatModifier(stat)); +} +float PkmnLib::Battling::StatCalculator::GetStatBoostModifier(const CreatureLib::Battling::Creature* pkmn, + CreatureLib::Core::Statistic stat) const { + int8_t boost = pkmn->GetStatBoost(stat); + switch (boost) { + case -6: return 2.0 / 8; + case -5: return 2.0 / 7; + case -4: return 2.0 / 6; + case -3: return 2.0 / 5; + case -2: return 2.0 / 4; + case -1: return 2.0 / 3; + case 0: return 1; + case 1: return 3.0 / 2; + case 2: return 4.0 / 2; + case 3: return 5.0 / 2; + case 4: return 6.0 / 2; + case 5: return 7.0 / 2; + case 6: return 8.0 / 2; + default: throw CreatureException("Stat boost was out of expected range of -6 till 6."); + } +} +CreatureLib::Core::StatisticSet +PkmnLib::Battling::StatCalculator::CalculateFlatStats(CreatureLib::Battling::Creature* creature) const { + auto pkmn = dynamic_cast(creature); + return CreatureLib::Core::StatisticSet( + CalculateHealthStat(pkmn), CalculateOtherStat(pkmn, Library::Statistic::PhysicalAttack), + CalculateOtherStat(pkmn, Library::Statistic::PhysicalDefense), + CalculateOtherStat(pkmn, Library::Statistic::SpecialAttack), + CalculateOtherStat(pkmn, Library::Statistic::SpecialDefense), + CalculateOtherStat(pkmn, Library::Statistic::Speed)); +} +CreatureLib::Core::StatisticSet +PkmnLib::Battling::StatCalculator::CalculateBoostedStats(CreatureLib::Battling::Creature* creature) const { + return CreatureLib::Core::StatisticSet( + CalculateBoostedStat(creature, Library::Statistic::HealthPoints), + CalculateBoostedStat(creature, Library::Statistic::PhysicalAttack), + CalculateBoostedStat(creature, Library::Statistic::PhysicalDefense), + CalculateBoostedStat(creature, Library::Statistic::SpecialAttack), + CalculateBoostedStat(creature, Library::Statistic::SpecialDefense), + CalculateBoostedStat(creature, Library::Statistic::Speed)); +} +uint32_t PkmnLib::Battling::StatCalculator::CalculateFlatStat(CreatureLib::Battling::Creature* creature, + CreatureLib::Core::Statistic stat) const { + if (stat == Library::Statistic::HealthPoints) + return CalculateHealthStat(dynamic_cast(creature)); + return CalculateOtherStat(dynamic_cast(creature), stat); +} +uint32_t PkmnLib::Battling::StatCalculator::CalculateBoostedStat(CreatureLib::Battling::Creature* creature, + CreatureLib::Core::Statistic stat) const { + return creature->GetFlatStat(stat) * GetStatBoostModifier(creature, stat); +} diff --git a/src/Battling/Library/StatCalculator.hpp b/src/Battling/Library/StatCalculator.hpp new file mode 100644 index 0000000..70709df --- /dev/null +++ b/src/Battling/Library/StatCalculator.hpp @@ -0,0 +1,33 @@ +#ifndef PKMNLIB_STATCALCULATOR_HPP +#define PKMNLIB_STATCALCULATOR_HPP + +#include +#include "../../Library/Statistic.hpp" + +namespace PkmnLib::Battling { + class Pokemon; + + class StatCalculator : public CreatureLib::Battling::BattleStatCalculator { + protected: + virtual uint32_t CalculateHealthStat(const Pokemon* pkmn) const; + virtual uint32_t CalculateOtherStat(const Pokemon* pkmn, CreatureLib::Core::Statistic stat) const; + virtual float GetStatBoostModifier(const CreatureLib::Battling::Creature* pkmn, + CreatureLib::Core::Statistic stat) const; + + public: + ~StatCalculator() override = default; + CreatureLib::Core::StatisticSet + CalculateFlatStats(CreatureLib::Battling::Creature* creature) const override; + + CreatureLib::Core::StatisticSet + CalculateBoostedStats(CreatureLib::Battling::Creature* creature) const override; + + uint32_t CalculateFlatStat(CreatureLib::Battling::Creature* creature, + CreatureLib::Core::Statistic stat) const override; + + uint32_t CalculateBoostedStat(CreatureLib::Battling::Creature* creature, + CreatureLib::Core::Statistic stat) const override; + }; +} + +#endif // PKMNLIB_STATCALCULATOR_HPP diff --git a/src/Battling/Pokemon/CreatePokemon.cpp b/src/Battling/Pokemon/CreatePokemon.cpp index 15a963c..0afdf3a 100644 --- a/src/Battling/Pokemon/CreatePokemon.cpp +++ b/src/Battling/Pokemon/CreatePokemon.cpp @@ -70,10 +70,34 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() { _nature = _library->GetNatureLibrary()->GetRandomNature(rand); } - return new Pokemon(_library, species, forme, _level, experience, identifier, gender, _coloring, heldItem, _nickname, + auto pkmn = new Pokemon(_library, species, forme, _level, experience, identifier, gender, _coloring, heldItem, _nickname, ability, attacks, ivs, evs,_nature); + pkmn->Initialize(); + return pkmn; } PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithNature(const std::string& nature) { _nature = _library->GetNatureLibrary()->GetNatureIdByName(nature); return this; } +PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithIndividualValues(uint8_t hp, uint8_t att, + uint8_t def, uint8_t spAtt, + uint8_t spDef, uint8_t speed) { + _ivHp = hp; + _ivAttack = att; + _ivDefense = def; + _ivSpAtt = spAtt; + _ivSpDef = spDef; + _ivSpeed = speed; + return this; +} +PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithEffortValues(uint8_t hp, uint8_t att, + uint8_t def, uint8_t spAtt, + uint8_t spDef, uint8_t speed) { + _evHp = hp; + _evAttack = att; + _evDefense = def; + _evSpAtt = spAtt; + _evSpDef = spDef; + _evSpeed = speed; + return this; +} diff --git a/src/Battling/Pokemon/CreatePokemon.hpp b/src/Battling/Pokemon/CreatePokemon.hpp index 9161508..7a8d203 100644 --- a/src/Battling/Pokemon/CreatePokemon.hpp +++ b/src/Battling/Pokemon/CreatePokemon.hpp @@ -1,9 +1,8 @@ #ifndef PKMNLIB_CREATEPOKEMON_HPP #define PKMNLIB_CREATEPOKEMON_HPP -#include "Pokemon.hpp" - #include +#include "Pokemon.hpp" namespace PkmnLib::Battling { class CreatePokemon { private: @@ -41,7 +40,12 @@ namespace PkmnLib::Battling { CreatePokemon* WithRandomIndividualValues(CreatureLib::Core::Random rand = CreatureLib::Core::Random()); CreatePokemon* WithIndividualValue(CreatureLib::Core::Statistic stat, uint8_t value); + CreatePokemon* WithIndividualValues(uint8_t hp, uint8_t att, uint8_t def, uint8_t spAtt, uint8_t spDef, + uint8_t speed); CreatePokemon* WithEffortValue(CreatureLib::Core::Statistic stat, uint8_t value); + CreatePokemon* WithEffortValues(uint8_t hp, uint8_t att, uint8_t def, uint8_t spAtt, uint8_t spDef, + uint8_t speed); + CreatePokemon* WithNature(const std::string& nature); Pokemon* Build(); diff --git a/src/Battling/Pokemon/Pokemon.cpp b/src/Battling/Pokemon/Pokemon.cpp index 64e983a..d773555 100644 --- a/src/Battling/Pokemon/Pokemon.cpp +++ b/src/Battling/Pokemon/Pokemon.cpp @@ -1,7 +1,8 @@ #include "Pokemon.hpp" -const PkmnLib::Library::Nature& PkmnLib::Battling::Pokemon::GetNature() { +const PkmnLib::Library::Nature& PkmnLib::Battling::Pokemon::GetNature() const{ if (_natureCache == nullptr){ - _natureCache = this->GetLibrary()->GetNatureLibrary()->GetNaturePtr(_nature); + auto p = const_cast(this); + p->_natureCache = this->GetLibrary()->GetNatureLibrary()->GetNaturePtr(_nature); } return *_natureCache; } diff --git a/src/Battling/Pokemon/Pokemon.hpp b/src/Battling/Pokemon/Pokemon.hpp index e32d573..b894617 100644 --- a/src/Battling/Pokemon/Pokemon.hpp +++ b/src/Battling/Pokemon/Pokemon.hpp @@ -3,6 +3,7 @@ #include #include +#include "../../Library/Statistic.hpp" #include "../Library/BattleLibrary.hpp" #include "LearnedMove.hpp" @@ -15,7 +16,7 @@ namespace PkmnLib::Battling { uint8_t _nature; const Library::Nature* _natureCache = nullptr; - const BattleLibrary* GetLibrary() { return reinterpret_cast(_library); } + const BattleLibrary* GetLibrary() const { return reinterpret_cast(_library); } public: Pokemon(const BattleLibrary* library, const Library::PokemonSpecies* species, @@ -28,7 +29,11 @@ namespace PkmnLib::Battling { heldItem, nickname, talent, std::move(moves)), _individualValues(individualValues), _effortValues(effortValues), _nature(nature) {} - const Library::Nature& GetNature(); + const Library::Nature& GetNature() const; + const uint8_t GetIndividualValue(CreatureLib::Core::Statistic stat) const { + return _individualValues.GetStat(stat); + } + const uint8_t GetEffortValue(CreatureLib::Core::Statistic stat) const { return _effortValues.GetStat(stat); } }; } diff --git a/src/Library/Natures/Nature.hpp b/src/Library/Natures/Nature.hpp index dce6e6e..97ab180 100644 --- a/src/Library/Natures/Nature.hpp +++ b/src/Library/Natures/Nature.hpp @@ -25,6 +25,14 @@ namespace PkmnLib::Library { [[nodiscard]] CreatureLib::Core::Statistic GetIncreasedStat() const { return _increaseStat; } [[nodiscard]] CreatureLib::Core::Statistic GetDecreasedStat() const { return _decreaseStat; } + + [[nodiscard]] float GetStatModifier(CreatureLib::Core::Statistic stat) const { + if (stat == _increaseStat) + return _increaseModifier; + else if (stat == _decreaseStat) + return _decreaseModifier; + return 1; + } }; } diff --git a/tests/LibraryTests/StatCalculationTests.cpp b/tests/LibraryTests/StatCalculationTests.cpp new file mode 100644 index 0000000..1a8a83b --- /dev/null +++ b/tests/LibraryTests/StatCalculationTests.cpp @@ -0,0 +1,133 @@ +#ifdef TESTS_BUILD +#include "../../extern/catch.hpp" +#include "../../src/Battling/Pokemon/CreatePokemon.hpp" +#include "../TestLibrary/TestLibrary.hpp" + +using namespace PkmnLib::Battling; + +TEST_CASE("Low level, no IVs, no EVs, neutral nature, no stat boosts stat test") { + auto pkmn = CreatePokemon(TestLibrary::GetLibrary(), "statTestSpecies1", 10).WithNature("neutralNature")->Build(); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::HealthPoints) == 40); + CHECK(pkmn->GetCurrentHealth() == 40); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::PhysicalAttack) == 25); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::PhysicalDefense) == 25); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::SpecialAttack) == 25); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::SpecialDefense) == 25); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::Speed) == 25); + delete pkmn; +} + +TEST_CASE("High level, no IVs, no EVs, neutral nature, no stat boosts stat test") { + auto pkmn = CreatePokemon(TestLibrary::GetLibrary(), "statTestSpecies1", 100).WithNature("neutralNature")->Build(); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::HealthPoints) == 310); + CHECK(pkmn->GetCurrentHealth() == 310); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::PhysicalAttack) == 205); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::PhysicalDefense) == 205); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::SpecialAttack) == 205); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::SpecialDefense) == 205); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::Speed) == 205); + delete pkmn; +} + +TEST_CASE("Low level, max IVs, no EVs, neutral nature, no stat boosts stat test") { + auto pkmn = CreatePokemon(TestLibrary::GetLibrary(), "statTestSpecies1", 10) + .WithNature("neutralNature") + ->WithIndividualValues(31, 31, 31, 31, 31, 31) + ->Build(); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::HealthPoints) == 43); + CHECK(pkmn->GetCurrentHealth() == 43); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::PhysicalAttack) == 28); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::PhysicalDefense) == 28); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::SpecialAttack) == 28); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::SpecialDefense) == 28); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::Speed) == 28); + delete pkmn; +} + +TEST_CASE("High level, max IVs, no EVs, neutral nature, no stat boosts stat test") { + auto pkmn = CreatePokemon(TestLibrary::GetLibrary(), "statTestSpecies1", 100) + .WithNature("neutralNature") + ->WithIndividualValues(31, 31, 31, 31, 31, 31) + ->Build(); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::HealthPoints) == 341); + CHECK(pkmn->GetCurrentHealth() == 341); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::PhysicalAttack) == 236); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::PhysicalDefense) == 236); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::SpecialAttack) == 236); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::SpecialDefense) == 236); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::Speed) == 236); + delete pkmn; +} + +TEST_CASE("High level, max IVs, max EVs, neutral nature, no stat boosts stat test") { + auto pkmn = CreatePokemon(TestLibrary::GetLibrary(), "statTestSpecies1", 100) + .WithNature("neutralNature") + ->WithIndividualValues(31, 31, 31, 31, 31, 31) + ->WithEffortValues(255, 255, 255, 255, 255, 255) + ->Build(); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::HealthPoints) == 404); + CHECK(pkmn->GetCurrentHealth() == 404); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::PhysicalAttack) == 299); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::PhysicalDefense) == 299); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::SpecialAttack) == 299); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::SpecialDefense) == 299); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::Speed) == 299); + delete pkmn; +} + +TEST_CASE("High level, max IVs, max EVs, nature buffs attack, nerfs speed, no stat boosts stat test") { + auto pkmn = CreatePokemon(TestLibrary::GetLibrary(), "statTestSpecies1", 100) + .WithNature("buffsAttackNerfsSpeed") + ->WithIndividualValues(31, 31, 31, 31, 31, 31) + ->WithEffortValues(255, 255, 255, 255, 255, 255) + ->Build(); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::HealthPoints) == 404); + CHECK(pkmn->GetCurrentHealth() == 404); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::PhysicalAttack) == 328); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::PhysicalDefense) == 299); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::SpecialAttack) == 299); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::SpecialDefense) == 299); + CHECK(pkmn->GetFlatStat(PkmnLib::Library::Statistic::Speed) == 269); + delete pkmn; +} + +TEST_CASE("High level, max IVs, max EVs, nature buffs attack, nerfs speed, Attack boosted +6 stat test") { + auto pkmn = CreatePokemon(TestLibrary::GetLibrary(), "statTestSpecies1", 100) + .WithNature("buffsAttackNerfsSpeed") + ->WithIndividualValues(31, 31, 31, 31, 31, 31) + ->WithEffortValues(255, 255, 255, 255, 255, 255) + ->Build(); + + pkmn->ChangeStatBoost(PkmnLib::Library::Statistic::PhysicalAttack, 6); + + CHECK(pkmn->GetBoostedStat(PkmnLib::Library::Statistic::HealthPoints) == 404); + CHECK(pkmn->GetCurrentHealth() == 404); + CHECK(pkmn->GetBoostedStat(PkmnLib::Library::Statistic::PhysicalAttack) == 1312); + CHECK(pkmn->GetBoostedStat(PkmnLib::Library::Statistic::PhysicalDefense) == 299); + CHECK(pkmn->GetBoostedStat(PkmnLib::Library::Statistic::SpecialAttack) == 299); + CHECK(pkmn->GetBoostedStat(PkmnLib::Library::Statistic::SpecialDefense) == 299); + CHECK(pkmn->GetBoostedStat(PkmnLib::Library::Statistic::Speed) == 269); + delete pkmn; +} + +TEST_CASE("High level, max IVs, max EVs, nature buffs attack, nerfs speed, Attack boosted -6 stat test") { + auto pkmn = CreatePokemon(TestLibrary::GetLibrary(), "statTestSpecies1", 100) + .WithNature("buffsAttackNerfsSpeed") + ->WithIndividualValues(31, 31, 31, 31, 31, 31) + ->WithEffortValues(255, 255, 255, 255, 255, 255) + ->Build(); + + pkmn->ChangeStatBoost(PkmnLib::Library::Statistic::PhysicalAttack, -6); + + CHECK(pkmn->GetBoostedStat(PkmnLib::Library::Statistic::HealthPoints) == 404); + CHECK(pkmn->GetCurrentHealth() == 404); + CHECK(pkmn->GetBoostedStat(PkmnLib::Library::Statistic::PhysicalAttack) == 82); + CHECK(pkmn->GetBoostedStat(PkmnLib::Library::Statistic::PhysicalDefense) == 299); + CHECK(pkmn->GetBoostedStat(PkmnLib::Library::Statistic::SpecialAttack) == 299); + CHECK(pkmn->GetBoostedStat(PkmnLib::Library::Statistic::SpecialDefense) == 299); + CHECK(pkmn->GetBoostedStat(PkmnLib::Library::Statistic::Speed) == 269); + delete pkmn; +} + + +#endif \ No newline at end of file diff --git a/tests/TestLibrary/TestLibrary.cpp b/tests/TestLibrary/TestLibrary.cpp index 76f2d31..add83eb 100644 --- a/tests/TestLibrary/TestLibrary.cpp +++ b/tests/TestLibrary/TestLibrary.cpp @@ -1,2 +1,33 @@ #include "TestLibrary.hpp" PkmnLib::Battling::BattleLibrary* TestLibrary::_library = nullptr; +PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() { + auto lib = new PkmnLib::Library::SpeciesLibrary(); + lib->LoadSpecies("testSpecies", new PkmnLib::Library::PokemonSpecies( + 1, "testSpecies", + new PkmnLib::Library::PokemonForme( + "default", 1.0f, 1.0f, 100, {0}, + CreatureLib::Core::StatisticSet(100, 100, 100, 100, 100, 100), + {"testAbility"}, {"testHiddenAbility"}, + new CreatureLib::Library::LearnableAttacks(100)), + 0.5f, "testGrowthRate", 100, 100)); + lib->LoadSpecies( + "testSpecies2", + new PkmnLib::Library::PokemonSpecies( + 2, "testSpecies2", + new PkmnLib::Library::PokemonForme( + "default", 1.0f, 1.0f, 100, {0}, + CreatureLib::Core::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"}, + {"testHiddenAbility"}, new CreatureLib::Library::LearnableAttacks(100)), + 0.5f, "testGrowthRate", 100, 100)); + lib->LoadSpecies( + "statTestSpecies1", + new PkmnLib::Library::PokemonSpecies( + 3, "statTestSpecies1", + new PkmnLib::Library::PokemonForme( + "default", 1.0f, 1.0f, 100, {0}, + CreatureLib::Core::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"}, + {"testHiddenAbility"}, new CreatureLib::Library::LearnableAttacks(100)), + 0.5f, "testGrowthRate", 100, 100)); + + return lib; +} diff --git a/tests/TestLibrary/TestLibrary.hpp b/tests/TestLibrary/TestLibrary.hpp index 2c95b0d..27aae12 100644 --- a/tests/TestLibrary/TestLibrary.hpp +++ b/tests/TestLibrary/TestLibrary.hpp @@ -19,7 +19,7 @@ public: } static PkmnLib::Battling::BattleLibrary* BuildLibrary() { - auto statCalc = new CreatureLib::Battling::BattleStatCalculator(); + auto statCalc = new PkmnLib::Battling::StatCalculator(); return new PkmnLib::Battling::BattleLibrary( BuildStaticLibrary(), statCalc, new CreatureLib::Battling::DamageLibrary(), new CreatureLib::Battling::ExperienceLibrary(), new CreatureLib::Battling::ScriptResolver(), @@ -32,27 +32,7 @@ public: BuildGrowthRateLibrary(), BuildTypeLibrary(), BuildNatureLibrary()); } - static PkmnLib::Library::SpeciesLibrary* BuildSpeciesLibrary() { - auto lib = new PkmnLib::Library::SpeciesLibrary(); - lib->LoadSpecies("testSpecies", new PkmnLib::Library::PokemonSpecies( - 1, "testSpecies", - new PkmnLib::Library::PokemonForme( - "default", 1.0f, 1.0f, 100, {0}, - CreatureLib::Core::StatisticSet(100, 100, 100, 100, 100, 100), - {"testAbility"}, {"testHiddenAbility"}, - new CreatureLib::Library::LearnableAttacks(100)), - 0.5f, "testGrowthRate", 100, 100)); - lib->LoadSpecies( - "testSpecies2", - new PkmnLib::Library::PokemonSpecies( - 2, "testSpecies2", - new PkmnLib::Library::PokemonForme( - "default", 1.0f, 1.0f, 100, {0}, - CreatureLib::Core::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"}, - {"testHiddenAbility"}, new CreatureLib::Library::LearnableAttacks(100)), - 0.5f, "testGrowthRate", 100, 100)); - return lib; - } + static PkmnLib::Library::SpeciesLibrary* BuildSpeciesLibrary(); static PkmnLib::Library::MoveLibrary* BuildMoveLibrary() { auto lib = new PkmnLib::Library::MoveLibrary(); @@ -79,6 +59,8 @@ public: auto lib = new PkmnLib::Library::NatureLibrary(); lib->LoadNature("neutralNature", PkmnLib::Library::Nature(PkmnLib::Library::Statistic::PhysicalAttack, PkmnLib::Library::Statistic::PhysicalDefense, 1, 1)); + lib->LoadNature("buffsAttackNerfsSpeed", PkmnLib::Library::Nature(PkmnLib::Library::Statistic::PhysicalAttack, + PkmnLib::Library::Statistic::Speed, 1.1, 0.9)); return lib; } };