Handle natures as pointers instead of values.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
086438f547
commit
6b704224d0
|
@ -16,7 +16,7 @@ uint32_t PkmnLib::Battling::StatCalculator::CalculateOtherStat(const Pokemon* pk
|
||||||
uint8_t level = pkmn->GetLevel();
|
uint8_t level = pkmn->GetLevel();
|
||||||
uint32_t unmodified =
|
uint32_t unmodified =
|
||||||
static_cast<uint32_t>(((2 * base + iv + static_cast<uint32_t>(ev / 4)) * level) / 100) + 5;
|
static_cast<uint32_t>(((2 * base + iv + static_cast<uint32_t>(ev / 4)) * level) / 100) + 5;
|
||||||
return static_cast<uint32_t>(unmodified * pkmn->GetNature().GetStatModifier(stat));
|
return static_cast<uint32_t>(unmodified * pkmn->GetNature()->GetStatModifier(stat));
|
||||||
}
|
}
|
||||||
float PkmnLib::Battling::StatCalculator::GetStatBoostModifier(const CreatureLib::Battling::Creature* pkmn,
|
float PkmnLib::Battling::StatCalculator::GetStatBoostModifier(const CreatureLib::Battling::Creature* pkmn,
|
||||||
CreatureLib::Library::Statistic stat) const {
|
CreatureLib::Library::Statistic stat) const {
|
||||||
|
|
|
@ -83,6 +83,7 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
||||||
if (_nature.Empty()) {
|
if (_nature.Empty()) {
|
||||||
_nature = _library->GetNatureLibrary()->GetRandomNatureName(rand);
|
_nature = _library->GetNatureLibrary()->GetRandomNatureName(rand);
|
||||||
}
|
}
|
||||||
|
auto nature = _library->GetNatureLibrary()->GetNatureByName(_nature);
|
||||||
|
|
||||||
auto shiny = false;
|
auto shiny = false;
|
||||||
if (_shininessSet) {
|
if (_shininessSet) {
|
||||||
|
@ -92,7 +93,7 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pkmn = new Pokemon(_library, species, forme, _level, experience, identifier, gender, shiny, heldItem,
|
auto pkmn = new Pokemon(_library, species, forme, _level, experience, identifier, gender, shiny, heldItem,
|
||||||
_nickname, ability, attacks, ivs, evs, _nature);
|
_nickname, ability, attacks, ivs, evs, nature);
|
||||||
pkmn->Initialize();
|
pkmn->Initialize();
|
||||||
return pkmn;
|
return pkmn;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include "Pokemon.hpp"
|
#include "Pokemon.hpp"
|
||||||
const PkmnLib::Library::Nature& PkmnLib::Battling::Pokemon::GetNature() const{
|
const PkmnLib::Library::Nature* PkmnLib::Battling::Pokemon::GetNature() const{
|
||||||
return this->GetLibrary()->GetNatureLibrary()->GetNatureByName(_nature);
|
return _nature;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace PkmnLib::Battling {
|
||||||
CreatureLib::Library::StatisticSet<uint8_t> _individualValues;
|
CreatureLib::Library::StatisticSet<uint8_t> _individualValues;
|
||||||
CreatureLib::Library::StatisticSet<uint8_t> _effortValues;
|
CreatureLib::Library::StatisticSet<uint8_t> _effortValues;
|
||||||
|
|
||||||
Arbutils::CaseInsensitiveConstString _nature;
|
const PkmnLib::Library::Nature* _nature;
|
||||||
|
|
||||||
const BattleLibrary* GetLibrary() const { return reinterpret_cast<const BattleLibrary*>(_library); }
|
const BattleLibrary* GetLibrary() const { return reinterpret_cast<const BattleLibrary*>(_library); }
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ namespace PkmnLib::Battling {
|
||||||
const std::string& nickname, const CreatureLib::Library::TalentIndex& talent,
|
const std::string& nickname, const CreatureLib::Library::TalentIndex& talent,
|
||||||
List<CreatureLib::Battling::LearnedAttack*> moves,
|
List<CreatureLib::Battling::LearnedAttack*> moves,
|
||||||
CreatureLib::Library::StatisticSet<uint8_t> individualValues,
|
CreatureLib::Library::StatisticSet<uint8_t> individualValues,
|
||||||
CreatureLib::Library::StatisticSet<uint8_t> effortValues, const Arbutils::CaseInsensitiveConstString& nature)
|
CreatureLib::Library::StatisticSet<uint8_t> effortValues, const PkmnLib::Library::Nature* nature)
|
||||||
: CreatureLib::Battling::Creature(library, species, forme, level, experience, uid, gender, coloring,
|
: CreatureLib::Battling::Creature(library, species, forme, level, experience, uid, gender, coloring,
|
||||||
heldItem, nickname, talent, std::move(moves)),
|
heldItem, nickname, talent, std::move(moves)),
|
||||||
_individualValues(individualValues), _effortValues(effortValues), _nature(nature) {}
|
_individualValues(individualValues), _effortValues(effortValues), _nature(nature) {}
|
||||||
|
@ -33,13 +33,13 @@ namespace PkmnLib::Battling {
|
||||||
return dynamic_cast<const Library::PokemonForme*>(GetVariant());
|
return dynamic_cast<const Library::PokemonForme*>(GetVariant());
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool IsShiny() const { return _coloring == 1; }
|
bool IsShiny() const { return _coloring == 1; }
|
||||||
|
|
||||||
const std::vector<LearnedMove*>& GetMoves() const {
|
const std::vector<LearnedMove*>& GetMoves() const {
|
||||||
return reinterpret_cast<const std::vector<LearnedMove*>&>(_attacks);
|
return reinterpret_cast<const std::vector<LearnedMove*>&>(_attacks);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Library::Nature& GetNature() const;
|
const Library::Nature* GetNature() const;
|
||||||
uint8_t GetIndividualValue(CreatureLib::Library::Statistic stat) const {
|
uint8_t GetIndividualValue(CreatureLib::Library::Statistic stat) const {
|
||||||
return _individualValues.GetStat(stat);
|
return _individualValues.GetStat(stat);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,17 +12,17 @@
|
||||||
namespace PkmnLib::Library {
|
namespace PkmnLib::Library {
|
||||||
class NatureLibrary {
|
class NatureLibrary {
|
||||||
private:
|
private:
|
||||||
Arbutils::Collections::Dictionary<Arbutils::CaseInsensitiveConstString, Nature> _items;
|
Arbutils::Collections::Dictionary<Arbutils::CaseInsensitiveConstString, const Nature*> _items;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit NatureLibrary(uint8_t size = 32)
|
explicit NatureLibrary(uint8_t size = 32)
|
||||||
: _items(Arbutils::Collections::Dictionary<Arbutils::CaseInsensitiveConstString, Nature>(size)) {}
|
: _items(Arbutils::Collections::Dictionary<Arbutils::CaseInsensitiveConstString, const Nature*>(size)) {}
|
||||||
|
|
||||||
inline void LoadNature(const Arbutils::CaseInsensitiveConstString& name, const Nature& nature) {
|
inline void LoadNature(const Arbutils::CaseInsensitiveConstString& name, const Nature* nature) {
|
||||||
_items.Insert(name, nature);
|
_items.Insert(name, nature);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const Nature& GetNatureByName(const Arbutils::CaseInsensitiveConstString& name) const {
|
inline const Nature* GetNatureByName(const Arbutils::CaseInsensitiveConstString& name) const {
|
||||||
return _items[name];
|
return _items[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,15 @@ namespace PkmnLib::Library {
|
||||||
auto& map = _items.GetStdMap();
|
auto& map = _items.GetStdMap();
|
||||||
return std::next(std::begin(map), i)->first;
|
return std::next(std::begin(map), i)->first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Arbutils::CaseInsensitiveConstString GetNatureName(const Nature* nature){
|
||||||
|
for (const auto& v: _items){
|
||||||
|
if (v.second == nature){
|
||||||
|
return v.first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw CreatureException("Nature not found.");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,19 +12,19 @@ TEST_CASE("Able to create and delete nature library", "library") {
|
||||||
|
|
||||||
TEST_CASE("Able to insert into nature library", "library") {
|
TEST_CASE("Able to insert into nature library", "library") {
|
||||||
auto lib = new NatureLibrary();
|
auto lib = new NatureLibrary();
|
||||||
lib->LoadNature("testNature"_cnc, Nature(Statistic::PhysicalAttack, Statistic::Speed));
|
lib->LoadNature("testNature"_cnc, new Nature(Statistic::PhysicalAttack, Statistic::Speed));
|
||||||
delete lib;
|
delete lib;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Able to retrieve nature by name", "library") {
|
TEST_CASE("Able to retrieve nature by name", "library") {
|
||||||
auto lib = new NatureLibrary();
|
auto lib = new NatureLibrary();
|
||||||
lib->LoadNature("testNature"_cnc, Nature(Statistic::PhysicalAttack, Statistic::Speed));
|
lib->LoadNature("testNature"_cnc, new Nature(Statistic::PhysicalAttack, Statistic::Speed));
|
||||||
|
|
||||||
auto nature = lib->GetNatureByName("testNature"_cnc);
|
auto nature = lib->GetNatureByName("testNature"_cnc);
|
||||||
REQUIRE(nature.GetIncreasedStat() == Statistic::PhysicalAttack);
|
REQUIRE(nature->GetIncreasedStat() == Statistic::PhysicalAttack);
|
||||||
REQUIRE(nature.GetDecreasedStat() == Statistic::Speed);
|
REQUIRE(nature->GetDecreasedStat() == Statistic::Speed);
|
||||||
REQUIRE(nature.GetIncreaseModifier() == 1.1f);
|
REQUIRE(nature->GetIncreaseModifier() == 1.1f);
|
||||||
REQUIRE(nature.GetDecreaseModifier() == 0.9f);
|
REQUIRE(nature->GetDecreaseModifier() == 0.9f);
|
||||||
|
|
||||||
delete lib;
|
delete lib;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,8 @@ TEST_CASE("Get Nature from Pokemon"){
|
||||||
.WithNature("neutralNature"_cnc)
|
.WithNature("neutralNature"_cnc)
|
||||||
->Build();
|
->Build();
|
||||||
auto nature = mon->GetNature();
|
auto nature = mon->GetNature();
|
||||||
REQUIRE(nature.GetDecreaseModifier() == 1);
|
REQUIRE(nature->GetDecreaseModifier() == 1);
|
||||||
REQUIRE(nature.GetIncreaseModifier() == 1);
|
REQUIRE(nature->GetIncreaseModifier() == 1);
|
||||||
delete mon;
|
delete mon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,10 +65,10 @@ public:
|
||||||
static PkmnLib::Library::NatureLibrary* BuildNatureLibrary() {
|
static PkmnLib::Library::NatureLibrary* BuildNatureLibrary() {
|
||||||
auto lib = new PkmnLib::Library::NatureLibrary();
|
auto lib = new PkmnLib::Library::NatureLibrary();
|
||||||
lib->LoadNature("neutralNature"_cnc,
|
lib->LoadNature("neutralNature"_cnc,
|
||||||
PkmnLib::Library::Nature(PkmnLib::Library::Statistic::PhysicalAttack,
|
new PkmnLib::Library::Nature(PkmnLib::Library::Statistic::PhysicalAttack,
|
||||||
PkmnLib::Library::Statistic::PhysicalDefense, 1, 1));
|
PkmnLib::Library::Statistic::PhysicalDefense, 1, 1));
|
||||||
lib->LoadNature("buffsAttackNerfsSpeed"_cnc,
|
lib->LoadNature("buffsAttackNerfsSpeed"_cnc,
|
||||||
PkmnLib::Library::Nature(PkmnLib::Library::Statistic::PhysicalAttack,
|
new PkmnLib::Library::Nature(PkmnLib::Library::Statistic::PhysicalAttack,
|
||||||
PkmnLib::Library::Statistic::Speed, 1.1, 0.9));
|
PkmnLib::Library::Statistic::Speed, 1.1, 0.9));
|
||||||
return lib;
|
return lib;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue