Rework for LearnMove method on CreatePokemon.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
984088f7a9
commit
0cce1fdda2
|
@ -23,8 +23,8 @@ PkmnLib::Battling::CreatePokemon::WithIndividualValue(CreatureLib::Library::Stat
|
|||
return this;
|
||||
}
|
||||
|
||||
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithEffortValue(CreatureLib::Library::Statistic stat,
|
||||
uint8_t value) {
|
||||
PkmnLib::Battling::CreatePokemon*
|
||||
PkmnLib::Battling::CreatePokemon::WithEffortValue(CreatureLib::Library::Statistic stat, uint8_t value) {
|
||||
switch (stat) {
|
||||
case PkmnLib::Library::Statistic::HealthPoints: _evHp = value; break;
|
||||
case PkmnLib::Library::Statistic::PhysicalAttack: _evAttack = value; break;
|
||||
|
@ -72,10 +72,14 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
|||
}
|
||||
auto experience = _library->GetGrowthRateLibrary()->CalculateExperience(species->GetGrowthRate(), _level);
|
||||
|
||||
auto attacks = List<CreatureLib::Battling::LearnedAttack*>(_attacks.size());
|
||||
auto attacks = List<CreatureLib::Battling::LearnedAttack*>(_attacks.Count());
|
||||
for (size_t i = 0; i < attacks.Count(); i++) {
|
||||
auto kv = _attacks[i];
|
||||
attacks[i] = new LearnedMove(std::get<0>(kv), std::get<1>(kv));
|
||||
auto& kv = _attacks[i];
|
||||
auto move = kv.Move;
|
||||
if (move != nullptr)
|
||||
attacks[i] = new LearnedMove(move, kv.LearnMethod);
|
||||
else
|
||||
attacks[i] = nullptr;
|
||||
}
|
||||
auto ivs = CreatureLib::Library::StatisticSet(_ivHp, _ivAttack, _ivDefense, _ivSpAtt, _ivSpDef, _ivSpeed);
|
||||
auto evs = CreatureLib::Library::StatisticSet(_evHp, _evAttack, _evDefense, _evSpAtt, _evSpDef, _evSpeed);
|
||||
|
@ -97,7 +101,8 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
|||
pkmn->Initialize();
|
||||
return pkmn;
|
||||
}
|
||||
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithNature(const Arbutils::CaseInsensitiveConstString& nature) {
|
||||
PkmnLib::Battling::CreatePokemon*
|
||||
PkmnLib::Battling::CreatePokemon::WithNature(const Arbutils::CaseInsensitiveConstString& nature) {
|
||||
_nature = nature;
|
||||
return this;
|
||||
}
|
||||
|
@ -137,7 +142,8 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::IsShiny(bool
|
|||
_isShiny = value;
|
||||
return this;
|
||||
}
|
||||
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithHeldItem(const Arbutils::CaseInsensitiveConstString& item) {
|
||||
PkmnLib::Battling::CreatePokemon*
|
||||
PkmnLib::Battling::CreatePokemon::WithHeldItem(const Arbutils::CaseInsensitiveConstString& item) {
|
||||
_heldItem = item;
|
||||
return this;
|
||||
}
|
||||
|
@ -148,10 +154,12 @@ PkmnLib::Battling::CreatePokemon::LearnMove(const Arbutils::CaseInsensitiveConst
|
|||
if (!_library->GetMoveLibrary()->TryGet(moveName, move)) {
|
||||
throw CreatureException("Invalid Move given: " + moveName.std_str());
|
||||
}
|
||||
if (_attacks.size() >= _library->GetSettings()->GetMaximalMoves()) {
|
||||
if (_currentMove >= _library->GetSettings()->GetMaximalMoves() - 1) {
|
||||
throw CreatureException("This pokemon already has the maximal allowed moves.");
|
||||
}
|
||||
Assert(move != nullptr);
|
||||
_attacks.emplace_back(move, method);
|
||||
auto& c = _attacks[_currentMove++];
|
||||
c.Move = move;
|
||||
c.LearnMethod = method;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,14 @@ namespace PkmnLib::Battling {
|
|||
CreatureLib::Library::Gender _gender = static_cast<CreatureLib::Library::Gender>(-1);
|
||||
Arbutils::CaseInsensitiveConstString _heldItem = ""_cnc;
|
||||
uint32_t _identifier = 0;
|
||||
std::vector<std::tuple<const Library::MoveData*, CreatureLib::Battling::AttackLearnMethod>> _attacks = {};
|
||||
|
||||
struct ToLearnMethod {
|
||||
const Library::MoveData* Move;
|
||||
CreatureLib::Battling::AttackLearnMethod LearnMethod;
|
||||
ToLearnMethod() : Move(nullptr), LearnMethod(CreatureLib::Battling::AttackLearnMethod::Unknown){};
|
||||
};
|
||||
Arbutils::Collections::List<ToLearnMethod> _attacks;
|
||||
size_t _currentMove = 0;
|
||||
|
||||
uint8_t _ivHp = 0;
|
||||
uint8_t _ivAttack = 0;
|
||||
|
@ -38,13 +45,16 @@ namespace PkmnLib::Battling {
|
|||
|
||||
public:
|
||||
CreatePokemon(const BattleLibrary* library, const Arbutils::CaseInsensitiveConstString& species, uint8_t level)
|
||||
: _library(library), _species(species), _level(level) {}
|
||||
: _library(library), _species(species), _level(level) {
|
||||
_attacks.Resize(library->GetSettings()->GetMaximalMoves(), ToLearnMethod());
|
||||
}
|
||||
|
||||
CreatePokemon* WithForme(const Arbutils::CaseInsensitiveConstString& forme);
|
||||
CreatePokemon* WithGender(CreatureLib::Library::Gender gender);
|
||||
CreatePokemon* IsShiny(bool value);
|
||||
CreatePokemon* WithHeldItem(const Arbutils::CaseInsensitiveConstString& item);
|
||||
CreatePokemon* LearnMove(const Arbutils::CaseInsensitiveConstString& move, CreatureLib::Battling::AttackLearnMethod method);
|
||||
CreatePokemon* LearnMove(const Arbutils::CaseInsensitiveConstString& move,
|
||||
CreatureLib::Battling::AttackLearnMethod method);
|
||||
|
||||
CreatePokemon* WithRandomIndividualValues(Arbutils::Random rand = Arbutils::Random());
|
||||
CreatePokemon* WithIndividualValue(CreatureLib::Library::Statistic stat, uint8_t value);
|
||||
|
|
|
@ -11,14 +11,26 @@ TEST_CASE("Create and delete Pokemon"){
|
|||
|
||||
TEST_CASE("Get Nature from Pokemon") {
|
||||
auto lib = TestLibrary::GetLibrary();
|
||||
auto mon = PkmnLib::Battling::CreatePokemon(lib, "testSpecies"_cnc, 1)
|
||||
.WithNature("neutralNature"_cnc)
|
||||
->Build();
|
||||
auto mon = PkmnLib::Battling::CreatePokemon(lib, "testSpecies"_cnc, 1).WithNature("neutralNature"_cnc)->Build();
|
||||
auto nature = mon->GetNature();
|
||||
REQUIRE(nature->GetDecreaseModifier() == 1);
|
||||
REQUIRE(nature->GetIncreaseModifier() == 1);
|
||||
delete mon;
|
||||
}
|
||||
|
||||
TEST_CASE("Get Attack name from Pokemon") {
|
||||
auto lib = TestLibrary::GetLibrary();
|
||||
auto mon = PkmnLib::Battling::CreatePokemon(lib, "testSpecies"_cnc, 1)
|
||||
.LearnMove(Arbutils::CaseInsensitiveConstString("testMove"),
|
||||
CreatureLib::Battling::AttackLearnMethod::Level)
|
||||
->LearnMove(Arbutils::CaseInsensitiveConstString("testMove2"),
|
||||
CreatureLib::Battling::AttackLearnMethod::Level)
|
||||
->Build();
|
||||
auto move = mon->GetMoves()[0];
|
||||
REQUIRE(move->GetMoveData()->GetName() == "testMove"_cnc);
|
||||
auto move2 = mon->GetMoves()[1];
|
||||
REQUIRE(move2->GetMoveData()->GetName() == "testMove2"_cnc);
|
||||
delete mon;
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue