Updates CreatureLib, implements ConstStrings.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#include "CreatePokemon.hpp"
|
||||
|
||||
PkmnLib::Battling::CreatePokemon*
|
||||
PkmnLib::Battling::CreatePokemon::WithRandomIndividualValues(CreatureLib::Core::Random rand) {
|
||||
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithRandomIndividualValues(Arbutils::Random rand) {
|
||||
_ivHp = rand.Get(0, 32);
|
||||
_ivAttack = rand.Get(0, 32);
|
||||
_ivDefense = rand.Get(0, 32);
|
||||
@@ -38,15 +37,15 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithEffortVa
|
||||
}
|
||||
|
||||
PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
||||
auto rand = CreatureLib::Core::Random();
|
||||
auto rand = Arbutils::Random();
|
||||
const PkmnLib::Library::PokemonSpecies* species = nullptr;
|
||||
if (!this->_library->GetSpeciesLibrary()->TryGet(this->_species.c_str(), species)) {
|
||||
if (!this->_library->GetSpeciesLibrary()->TryGet(this->_species, species)) {
|
||||
std::stringstream err;
|
||||
err << "Invalid species '" << _species << "'.";
|
||||
throw CreatureException(err.str());
|
||||
}
|
||||
const PkmnLib::Library::PokemonForme* forme;
|
||||
if (!species->TryGetForme(this->_forme, forme)){
|
||||
if (!species->TryGetForme(this->_forme, forme)) {
|
||||
std::stringstream err;
|
||||
err << "Invalid forme '" << _forme << "' for species '" << _forme << "'.";
|
||||
throw CreatureException(err.str());
|
||||
@@ -66,9 +65,9 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
||||
gender = species->GetRandomGender(rand);
|
||||
}
|
||||
const Library::Item* heldItem = nullptr;
|
||||
if (!this->_heldItem.empty()) {
|
||||
if (!_library->GetItemLibrary()->TryGet(this->_heldItem.c_str(), heldItem)) {
|
||||
throw CreatureException("Unknown Item: " + this->_heldItem);
|
||||
if (!this->_heldItem.Empty()) {
|
||||
if (!_library->GetItemLibrary()->TryGet(this->_heldItem, heldItem)) {
|
||||
throw CreatureException("Unknown Item: " + this->_heldItem.std_str());
|
||||
}
|
||||
}
|
||||
auto experience = _library->GetGrowthRateLibrary()->CalculateExperience(species->GetGrowthRate(), _level);
|
||||
@@ -123,7 +122,8 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithEffortVa
|
||||
_evSpeed = speed;
|
||||
return this;
|
||||
}
|
||||
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithForme(const std::string& forme) {
|
||||
PkmnLib::Battling::CreatePokemon*
|
||||
PkmnLib::Battling::CreatePokemon::WithForme(const Arbutils::CaseInsensitiveConstString& forme) {
|
||||
_forme = forme;
|
||||
return this;
|
||||
}
|
||||
@@ -136,17 +136,18 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::IsShiny(bool
|
||||
_isShiny = value;
|
||||
return this;
|
||||
}
|
||||
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithHeldItem(const std::string& item) {
|
||||
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithHeldItem(const Arbutils::CaseInsensitiveConstString& item) {
|
||||
_heldItem = item;
|
||||
return this;
|
||||
}
|
||||
PkmnLib::Battling::CreatePokemon*
|
||||
PkmnLib::Battling::CreatePokemon::LearnMove(const std::string& moveName, CreatureLib::Battling::AttackLearnMethod method) {
|
||||
PkmnLib::Battling::CreatePokemon::LearnMove(const Arbutils::CaseInsensitiveConstString& moveName,
|
||||
CreatureLib::Battling::AttackLearnMethod method) {
|
||||
const PkmnLib::Library::MoveData* move;
|
||||
if (!_library->GetMoveLibrary()->TryGet(moveName.c_str(), move)){
|
||||
throw CreatureException("Invalid Move given: " + moveName);
|
||||
if (!_library->GetMoveLibrary()->TryGet(moveName, move)) {
|
||||
throw CreatureException("Invalid Move given: " + moveName.std_str());
|
||||
}
|
||||
if (_attacks.size() >= _library->GetSettings()->GetMaximalMoves()){
|
||||
if (_attacks.size() >= _library->GetSettings()->GetMaximalMoves()) {
|
||||
throw CreatureException("This pokemon already has the maximal allowed moves.");
|
||||
}
|
||||
_attacks.emplace_back(move, method);
|
||||
|
||||
@@ -7,15 +7,15 @@ namespace PkmnLib::Battling {
|
||||
class CreatePokemon {
|
||||
private:
|
||||
const BattleLibrary* _library;
|
||||
std::string _species;
|
||||
std::string _forme = "default";
|
||||
Arbutils::CaseInsensitiveConstString _species;
|
||||
Arbutils::CaseInsensitiveConstString _forme = "default"_cnc;
|
||||
uint8_t _level;
|
||||
std::string _nickname = "";
|
||||
|
||||
std::string _ability = "";
|
||||
uint8_t _nature = 255;
|
||||
CreatureLib::Library::Gender _gender = static_cast<CreatureLib::Library::Gender>(-1);
|
||||
std::string _heldItem = "";
|
||||
Arbutils::CaseInsensitiveConstString _heldItem = ""_cnc;
|
||||
uint32_t _identifier = 0;
|
||||
std::vector<std::tuple<const Library::MoveData*, CreatureLib::Battling::AttackLearnMethod>> _attacks = {};
|
||||
|
||||
@@ -37,16 +37,16 @@ namespace PkmnLib::Battling {
|
||||
bool _isShiny = false;
|
||||
|
||||
public:
|
||||
CreatePokemon(const BattleLibrary* library, std::string species, uint8_t level)
|
||||
: _library(library), _species(std::move(species)), _level(level) {}
|
||||
CreatePokemon(const BattleLibrary* library, const Arbutils::CaseInsensitiveConstString& species, uint8_t level)
|
||||
: _library(library), _species(species), _level(level) {}
|
||||
|
||||
CreatePokemon* WithForme(const std::string& forme);
|
||||
CreatePokemon* WithForme(const Arbutils::CaseInsensitiveConstString& forme);
|
||||
CreatePokemon* WithGender(CreatureLib::Library::Gender gender);
|
||||
CreatePokemon* IsShiny(bool value);
|
||||
CreatePokemon* WithHeldItem(const std::string& item);
|
||||
CreatePokemon* LearnMove(const std::string& move, CreatureLib::Battling::AttackLearnMethod method);
|
||||
CreatePokemon* WithHeldItem(const Arbutils::CaseInsensitiveConstString& item);
|
||||
CreatePokemon* LearnMove(const Arbutils::CaseInsensitiveConstString& move, CreatureLib::Battling::AttackLearnMethod method);
|
||||
|
||||
CreatePokemon* WithRandomIndividualValues(CreatureLib::Core::Random rand = CreatureLib::Core::Random());
|
||||
CreatePokemon* WithRandomIndividualValues(Arbutils::Random rand = Arbutils::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);
|
||||
|
||||
Reference in New Issue
Block a user