157 lines
6.6 KiB
C++
157 lines
6.6 KiB
C++
#include "CreatePokemon.hpp"
|
|
|
|
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);
|
|
_ivSpAtt = rand.Get(0, 32);
|
|
_ivSpDef = rand.Get(0, 32);
|
|
_ivSpeed = rand.Get(0, 32);
|
|
return this;
|
|
}
|
|
|
|
PkmnLib::Battling::CreatePokemon*
|
|
PkmnLib::Battling::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;
|
|
case PkmnLib::Library::Statistic::PhysicalDefense: _ivDefense = value; break;
|
|
case PkmnLib::Library::Statistic::SpecialAttack: _ivSpAtt = value; break;
|
|
case PkmnLib::Library::Statistic::SpecialDefense: _ivSpDef = value; break;
|
|
case PkmnLib::Library::Statistic::Speed: _ivSpeed = value; break;
|
|
}
|
|
return this;
|
|
}
|
|
|
|
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;
|
|
case PkmnLib::Library::Statistic::PhysicalDefense: _evDefense = value; break;
|
|
case PkmnLib::Library::Statistic::SpecialAttack: _evSpAtt = value; break;
|
|
case PkmnLib::Library::Statistic::SpecialDefense: _evSpDef = value; break;
|
|
case PkmnLib::Library::Statistic::Speed: _evSpeed = value; break;
|
|
}
|
|
return this;
|
|
}
|
|
|
|
PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
|
auto rand = Arbutils::Random();
|
|
const PkmnLib::Library::PokemonSpecies* species = nullptr;
|
|
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)) {
|
|
std::stringstream err;
|
|
err << "Invalid forme '" << _forme << "' for species '" << _forme << "'.";
|
|
throw CreatureException(err.str());
|
|
}
|
|
CreatureLib::Library::TalentIndex ability;
|
|
if (this->_ability.Empty()) {
|
|
ability = forme->GetRandomTalent(&rand);
|
|
} else {
|
|
ability = forme->GetTalentIndex(this->_ability);
|
|
}
|
|
auto identifier = this->_identifier;
|
|
if (identifier == 0) {
|
|
identifier = rand.Get();
|
|
}
|
|
auto gender = this->_gender;
|
|
if (gender == static_cast<CreatureLib::Library::Gender>(-1)) {
|
|
gender = species->GetRandomGender(rand);
|
|
}
|
|
const Library::Item* heldItem = nullptr;
|
|
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);
|
|
|
|
auto attacks = List<CreatureLib::Battling::LearnedAttack*>(_attacks.size());
|
|
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 ivs = CreatureLib::Library::StatisticSet(_ivHp, _ivAttack, _ivDefense, _ivSpAtt, _ivSpDef, _ivSpeed);
|
|
auto evs = CreatureLib::Library::StatisticSet(_evHp, _evAttack, _evDefense, _evSpAtt, _evSpDef, _evSpeed);
|
|
|
|
if (_nature.Empty()) {
|
|
_nature = _library->GetNatureLibrary()->GetRandomNatureName(rand);
|
|
}
|
|
auto nature = _library->GetNatureLibrary()->GetNatureByName(_nature);
|
|
|
|
auto shiny = false;
|
|
if (_shininessSet) {
|
|
shiny = _isShiny;
|
|
} else {
|
|
shiny = rand.Get(_library->GetSettings()->GetShinyRate()) == 0;
|
|
}
|
|
|
|
auto pkmn = new Pokemon(_library, species, forme, _level, experience, identifier, gender, shiny, heldItem,
|
|
_nickname, ability, attacks, ivs, evs, nature);
|
|
pkmn->Initialize();
|
|
return pkmn;
|
|
}
|
|
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithNature(const Arbutils::CaseInsensitiveConstString& nature) {
|
|
_nature = nature;
|
|
return this;
|
|
}
|
|
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithIndividualValues(uint8_t hp, uint8_t att,
|
|
uint8_t def, uint8_t spAtt,
|
|
uint8_t spDef, uint8_t speed) {
|
|
_ivHp = hp;
|
|
_ivAttack = att;
|
|
_ivDefense = def;
|
|
_ivSpAtt = spAtt;
|
|
_ivSpDef = spDef;
|
|
_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) {
|
|
_evHp = hp;
|
|
_evAttack = att;
|
|
_evDefense = def;
|
|
_evSpAtt = spAtt;
|
|
_evSpDef = spDef;
|
|
_evSpeed = speed;
|
|
return this;
|
|
}
|
|
PkmnLib::Battling::CreatePokemon*
|
|
PkmnLib::Battling::CreatePokemon::WithForme(const Arbutils::CaseInsensitiveConstString& forme) {
|
|
_forme = forme;
|
|
return this;
|
|
}
|
|
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithGender(CreatureLib::Library::Gender gender) {
|
|
_gender = gender;
|
|
return this;
|
|
}
|
|
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::IsShiny(bool value) {
|
|
_shininessSet = true;
|
|
_isShiny = value;
|
|
return this;
|
|
}
|
|
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithHeldItem(const Arbutils::CaseInsensitiveConstString& item) {
|
|
_heldItem = item;
|
|
return this;
|
|
}
|
|
PkmnLib::Battling::CreatePokemon*
|
|
PkmnLib::Battling::CreatePokemon::LearnMove(const Arbutils::CaseInsensitiveConstString& moveName,
|
|
CreatureLib::Battling::AttackLearnMethod method) {
|
|
const PkmnLib::Library::MoveData* move;
|
|
if (!_library->GetMoveLibrary()->TryGet(moveName, move)) {
|
|
throw CreatureException("Invalid Move given: " + moveName.std_str());
|
|
}
|
|
if (_attacks.size() >= _library->GetSettings()->GetMaximalMoves()) {
|
|
throw CreatureException("This pokemon already has the maximal allowed moves.");
|
|
}
|
|
_attacks.emplace_back(move, method);
|
|
return this;
|
|
}
|