diff --git a/conanfile.py b/conanfile.py index 4062b21..92c0056 100644 --- a/conanfile.py +++ b/conanfile.py @@ -12,7 +12,7 @@ class PkmnLibConan(ConanFile): generators = "cmake" exports_sources = "*" compiler = "clang" - requires = "CreatureLib/b98b470f0dd9e0cc1d7452d5fae4fcdfec2f7cba@creaturelib/master" + requires = "CreatureLib/dd8d4d738d3574933c8f071220028d0088fbb326@creaturelib/master" def build(self): cmake = CMake(self) diff --git a/src/Battling/Library/BattleLibrary.hpp b/src/Battling/Library/BattleLibrary.hpp index acc1f6f..32b7daf 100644 --- a/src/Battling/Library/BattleLibrary.hpp +++ b/src/Battling/Library/BattleLibrary.hpp @@ -15,14 +15,23 @@ namespace PkmnLib::Battling { : CreatureLib::Battling::BattleLibrary(staticLib, statCalculator, damageLibrary, experienceLibrary, scriptResolver, miscLibrary) {} + const Library::PokemonLibrary* GetStaticLib() const{ + return reinterpret_cast(CreatureLib::Battling::BattleLibrary::_staticLib); + } + const Library::SpeciesLibrary* GetSpeciesLibrary() const { - return reinterpret_cast(CreatureLib::Battling::BattleLibrary::GetSpeciesLibrary()); + return reinterpret_cast( + CreatureLib::Battling::BattleLibrary::GetSpeciesLibrary()); } const Library::ItemLibrary* GetItemLibrary() const { - return reinterpret_cast(CreatureLib::Battling::BattleLibrary::GetItemLibrary()); + return reinterpret_cast( + CreatureLib::Battling::BattleLibrary::GetItemLibrary()); } + const Library::NatureLibrary* GetNatureLibrary() const { + return GetStaticLib()->GetNatureLibrary(); + } }; } diff --git a/src/Battling/Pokemon/CreatePokemon.cpp b/src/Battling/Pokemon/CreatePokemon.cpp index 00ebf15..15a963c 100644 --- a/src/Battling/Pokemon/CreatePokemon.cpp +++ b/src/Battling/Pokemon/CreatePokemon.cpp @@ -1,6 +1,6 @@ #include "CreatePokemon.hpp" #include "../../Library/Statistic.hpp" -PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::RandomizeIndividualValues(CreatureLib::Core::Random rand) { +PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithRandomIndividualValues(CreatureLib::Core::Random rand) { _ivHp = rand.Get(0, 32); _ivAttack = rand.Get(0, 32); _ivDefense = rand.Get(0, 32); @@ -10,7 +10,7 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::RandomizeInd return this; } -PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::SetIndividualValue(CreatureLib::Core::Statistic stat, uint8_t value) { +PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithIndividualValue(CreatureLib::Core::Statistic stat, uint8_t value) { switch (stat) { case PkmnLib::Library::Statistic::HealthPoints: _ivHp = value; break; case PkmnLib::Library::Statistic::PhysicalAttack: _ivAttack = value; break; @@ -22,7 +22,7 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::SetIndividua return this; } -PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::SetEffortValue(CreatureLib::Core::Statistic stat, uint8_t value) { +PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithEffortValue(CreatureLib::Core::Statistic stat, uint8_t value) { switch (stat) { case PkmnLib::Library::Statistic::HealthPoints: _evHp = value; break; case PkmnLib::Library::Statistic::PhysicalAttack: _evAttack = value; break; @@ -66,6 +66,14 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() { auto ivs = CreatureLib::Core::StatisticSet(_ivHp, _ivAttack, _ivDefense, _ivSpAtt, _ivSpDef, _ivSpeed); auto evs = CreatureLib::Core::StatisticSet(_evHp, _evAttack, _evDefense, _evSpAtt, _evSpDef, _evSpeed); + if (_nature == 255){ + _nature = _library->GetNatureLibrary()->GetRandomNature(rand); + } + return new Pokemon(_library, species, forme, _level, experience, identifier, gender, _coloring, heldItem, _nickname, - ability, attacks, ivs, evs); + ability, attacks, ivs, evs,_nature); +} +PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithNature(const std::string& nature) { + _nature = _library->GetNatureLibrary()->GetNatureIdByName(nature); + return this; } diff --git a/src/Battling/Pokemon/CreatePokemon.hpp b/src/Battling/Pokemon/CreatePokemon.hpp index 3a60702..9161508 100644 --- a/src/Battling/Pokemon/CreatePokemon.hpp +++ b/src/Battling/Pokemon/CreatePokemon.hpp @@ -14,6 +14,7 @@ namespace PkmnLib::Battling { std::string _nickname = ""; std::string _ability = ""; + uint8_t _nature = 255; CreatureLib::Library::Gender _gender = static_cast(-1); uint8_t _coloring = 0; std::string _heldItem = ""; @@ -38,9 +39,10 @@ namespace PkmnLib::Battling { CreatePokemon(const BattleLibrary* library, std::string species, uint8_t level) : _library(library), _species(std::move(species)), _level(level) {} - CreatePokemon* RandomizeIndividualValues(CreatureLib::Core::Random rand = CreatureLib::Core::Random()); - CreatePokemon* SetIndividualValue(CreatureLib::Core::Statistic stat, uint8_t value); - CreatePokemon* SetEffortValue(CreatureLib::Core::Statistic stat, uint8_t value); + CreatePokemon* WithRandomIndividualValues(CreatureLib::Core::Random rand = CreatureLib::Core::Random()); + CreatePokemon* WithIndividualValue(CreatureLib::Core::Statistic stat, uint8_t value); + CreatePokemon* WithEffortValue(CreatureLib::Core::Statistic stat, uint8_t value); + CreatePokemon* WithNature(const std::string& nature); Pokemon* Build(); }; diff --git a/src/Battling/Pokemon/Pokemon.cpp b/src/Battling/Pokemon/Pokemon.cpp index 71f641f..64e983a 100644 --- a/src/Battling/Pokemon/Pokemon.cpp +++ b/src/Battling/Pokemon/Pokemon.cpp @@ -1 +1,7 @@ #include "Pokemon.hpp" +const PkmnLib::Library::Nature& PkmnLib::Battling::Pokemon::GetNature() { + if (_natureCache == nullptr){ + _natureCache = this->GetLibrary()->GetNatureLibrary()->GetNaturePtr(_nature); + } + return *_natureCache; +} diff --git a/src/Battling/Pokemon/Pokemon.hpp b/src/Battling/Pokemon/Pokemon.hpp index 4fd413c..e32d573 100644 --- a/src/Battling/Pokemon/Pokemon.hpp +++ b/src/Battling/Pokemon/Pokemon.hpp @@ -12,16 +12,23 @@ namespace PkmnLib::Battling { CreatureLib::Core::StatisticSet _individualValues; CreatureLib::Core::StatisticSet _effortValues; + uint8_t _nature; + const Library::Nature* _natureCache = nullptr; + + const BattleLibrary* GetLibrary() { return reinterpret_cast(_library); } + public: Pokemon(const BattleLibrary* library, const Library::PokemonSpecies* species, const Library::PokemonForme* forme, uint8_t level, uint32_t experience, uint32_t uid, CreatureLib::Library::Gender gender, uint8_t coloring, const Library::Item* heldItem, const std::string& nickname, int8_t talent, std::vector moves, CreatureLib::Core::StatisticSet individualValues, - CreatureLib::Core::StatisticSet effortValues) + CreatureLib::Core::StatisticSet effortValues, uint8_t nature) : CreatureLib::Battling::Creature(library, species, forme, level, experience, uid, gender, coloring, heldItem, nickname, talent, std::move(moves)), - _individualValues(individualValues), _effortValues(effortValues) {} + _individualValues(individualValues), _effortValues(effortValues), _nature(nature) {} + + const Library::Nature& GetNature(); }; } diff --git a/src/Library/Natures/NatureLibrary.hpp b/src/Library/Natures/NatureLibrary.hpp index cd70cbe..714c0be 100644 --- a/src/Library/Natures/NatureLibrary.hpp +++ b/src/Library/Natures/NatureLibrary.hpp @@ -2,6 +2,7 @@ #define PKMNLIB_NATURELIBRARY_HPP #include +#include #include #include #include "Nature.hpp" @@ -39,6 +40,7 @@ namespace PkmnLib::Library { } const Nature& GetNature(uint8_t id) const { return _natures[id]; } + const Nature* GetNaturePtr(uint8_t id) const { return &_natures[id]; } uint8_t GetNatureIdByName(const std::string& name) const { auto find = _keyLookup.find(name); @@ -47,6 +49,10 @@ namespace PkmnLib::Library { } return _keyLookup.at(name); } + + uint8_t GetRandomNature(CreatureLib::Core::Random rand = CreatureLib::Core::Random()) const{ + return rand.Get(_current); + } }; } diff --git a/tests/PokemonTests/BasicPokemonTests.cpp b/tests/PokemonTests/BasicPokemonTests.cpp index c9f5e96..99d82e0 100644 --- a/tests/PokemonTests/BasicPokemonTests.cpp +++ b/tests/PokemonTests/BasicPokemonTests.cpp @@ -9,4 +9,16 @@ TEST_CASE("Create and delete Pokemon"){ delete mon; } +TEST_CASE("Get Nature from Pokemon"){ + auto lib = TestLibrary::GetLibrary(); + auto mon = PkmnLib::Battling::CreatePokemon(lib, "testSpecies", 1) + .WithNature("neutralNature") + ->Build(); + auto nature = mon->GetNature(); + REQUIRE(nature.GetDecreaseModifier() == 1); + REQUIRE(nature.GetIncreaseModifier() == 1); + delete mon; +} + + #endif \ No newline at end of file diff --git a/tests/TestLibrary/TestLibrary.hpp b/tests/TestLibrary/TestLibrary.hpp index b28deab..2c95b0d 100644 --- a/tests/TestLibrary/TestLibrary.hpp +++ b/tests/TestLibrary/TestLibrary.hpp @@ -5,6 +5,7 @@ #include "../../src/Battling/Library/BattleLibrary.hpp" #include "../../src/Library/Moves/MoveLibrary.hpp" #include "../../src/Library/PokemonLibrary.hpp" +#include "../../src/Library/Statistic.hpp" class TestLibrary { private: static PkmnLib::Battling::BattleLibrary* _library; @@ -76,6 +77,8 @@ public: static PkmnLib::Library::NatureLibrary* BuildNatureLibrary() { auto lib = new PkmnLib::Library::NatureLibrary(); + lib->LoadNature("neutralNature", PkmnLib::Library::Nature(PkmnLib::Library::Statistic::PhysicalAttack, + PkmnLib::Library::Statistic::PhysicalDefense, 1, 1)); return lib; } };