Pass back CreatePokemon by reference.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-08-04 17:19:14 +02:00
parent 6ffcd4dcbc
commit 8290bf546a
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 168 additions and 172 deletions

View File

@ -1,6 +1,6 @@
#include "CreatePokemon.hpp"
PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon::WithRandomIndividualValues(ArbUt::Random rand) {
namespace PkmnLib::Battling {
CreatePokemon& CreatePokemon::WithRandomIndividualValues(ArbUt::Random rand) {
_ivHp = rand.Get(0, 32);
_ivAttack = rand.Get(0, 32);
_ivDefense = rand.Get(0, 32);
@ -10,8 +10,7 @@ PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon::WithRandomInd
return *this;
}
PkmnLib::Battling::CreatePokemon
PkmnLib::Battling::CreatePokemon::WithIndividualValue(CreatureLib::Library::Statistic stat, uint8_t value) {
CreatePokemon& CreatePokemon::WithIndividualValue(CreatureLib::Library::Statistic stat, uint8_t value) {
switch (stat) {
case PkmnLib::Library::Statistic::HealthPoints: _ivHp = value; break;
case PkmnLib::Library::Statistic::PhysicalAttack: _ivAttack = value; break;
@ -23,8 +22,7 @@ PkmnLib::Battling::CreatePokemon::WithIndividualValue(CreatureLib::Library::Stat
return *this;
}
PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon::WithEffortValue(CreatureLib::Library::Statistic stat,
uint8_t value) {
CreatePokemon& 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;
@ -36,7 +34,7 @@ PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon::WithEffortVal
return *this;
}
PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
Pokemon* CreatePokemon::Build() {
auto rand = ArbUt::Random();
ArbUt::BorrowedPtr<const Library::PokemonSpecies> species = nullptr;
if (!this->_library->GetSpeciesLibrary()->TryGet(this->_species, species)) {
@ -103,12 +101,11 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
pkmn->Initialize();
return pkmn;
}
PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon::WithNature(const ArbUt::StringView& nature) {
CreatePokemon& CreatePokemon::WithNature(const ArbUt::StringView& nature) {
_nature = nature;
return *this;
}
PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon::WithIndividualValues(uint8_t hp, uint8_t att,
uint8_t def, uint8_t spAtt,
CreatePokemon& CreatePokemon::WithIndividualValues(uint8_t hp, uint8_t att, uint8_t def, uint8_t spAtt,
uint8_t spDef, uint8_t speed) {
_ivHp = hp;
_ivAttack = att;
@ -118,9 +115,8 @@ PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon::WithIndividua
_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) {
CreatePokemon& 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;
@ -129,25 +125,24 @@ PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon::WithEffortVal
_evSpeed = speed;
return *this;
}
PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon::WithForme(const ArbUt::StringView& forme) {
CreatePokemon& CreatePokemon::WithForme(const ArbUt::StringView& forme) {
_forme = forme;
return *this;
}
PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon::WithGender(CreatureLib::Library::Gender gender) {
CreatePokemon& CreatePokemon::WithGender(CreatureLib::Library::Gender gender) {
_gender = gender;
return *this;
}
PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon::IsShiny(bool value) {
CreatePokemon& CreatePokemon::IsShiny(bool value) {
_shininessSet = true;
_isShiny = value;
return *this;
}
PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon::WithHeldItem(const ArbUt::StringView& item) {
CreatePokemon& CreatePokemon::WithHeldItem(const ArbUt::StringView& item) {
_heldItem = item;
return *this;
}
PkmnLib::Battling::CreatePokemon
PkmnLib::Battling::CreatePokemon::LearnMove(const ArbUt::StringView& moveName,
CreatePokemon& CreatePokemon::LearnMove(const ArbUt::StringView& moveName,
CreatureLib::Battling::AttackLearnMethod method) {
ArbUt::BorrowedPtr<const PkmnLib::Library::MoveData> move = nullptr;
if (!_library->GetMoveLibrary()->TryGet(moveName, move)) {
@ -160,7 +155,8 @@ PkmnLib::Battling::CreatePokemon::LearnMove(const ArbUt::StringView& moveName,
_attacks.Append(ToLearnMethod(move, method));
return *this;
}
PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon::IsAllowedExperienceGain(bool value) {
CreatePokemon& CreatePokemon::IsAllowedExperienceGain(bool value) {
_allowedExperienceGain = value;
return *this;
}
}

View File

@ -52,22 +52,22 @@ namespace PkmnLib::Battling {
: _library(library), _species(species), _level(level), _attacks(library->GetSettings()->GetMaximalMoves()) {
}
CreatePokemon WithForme(const ArbUt::StringView& forme);
CreatePokemon WithGender(CreatureLib::Library::Gender gender);
CreatePokemon IsShiny(bool value);
CreatePokemon WithHeldItem(const ArbUt::StringView& item);
CreatePokemon LearnMove(const ArbUt::StringView& move, CreatureLib::Battling::AttackLearnMethod method);
CreatePokemon& WithForme(const ArbUt::StringView& forme);
CreatePokemon& WithGender(CreatureLib::Library::Gender gender);
CreatePokemon& IsShiny(bool value);
CreatePokemon& WithHeldItem(const ArbUt::StringView& item);
CreatePokemon& LearnMove(const ArbUt::StringView& move, CreatureLib::Battling::AttackLearnMethod method);
CreatePokemon WithRandomIndividualValues(ArbUt::Random rand = ArbUt::Random());
CreatePokemon WithIndividualValue(CreatureLib::Library::Statistic stat, uint8_t value);
CreatePokemon WithIndividualValues(uint8_t hp, uint8_t att, uint8_t def, uint8_t spAtt, uint8_t spDef,
CreatePokemon& WithRandomIndividualValues(ArbUt::Random rand = ArbUt::Random());
CreatePokemon& WithIndividualValue(CreatureLib::Library::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::Library::Statistic stat, uint8_t value);
CreatePokemon WithEffortValues(uint8_t hp, uint8_t att, uint8_t def, uint8_t spAtt, uint8_t spDef,
CreatePokemon& WithEffortValue(CreatureLib::Library::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 ArbUt::StringView& nature);
CreatePokemon IsAllowedExperienceGain(bool value);
CreatePokemon& WithNature(const ArbUt::StringView& nature);
CreatePokemon& IsAllowedExperienceGain(bool value);
Pokemon* Build();
};