#include "CreateCreature.hpp" #include #include "../Library/BattleLibrary.hpp" using namespace CreatureLib::Battling; CreateCreature* CreateCreature::WithVariant(std::string variant) { this->_variant = std::move(variant); return this; } CreateCreature* CreateCreature::WithNickname(std::string nickname) { this->_nickname = std::move(nickname); return this; } CreateCreature* CreateCreature::WithGender(Library::Gender gender) { this->_gender = gender; return this; } CreateCreature* CreateCreature::WithAttack(const std::string& attackName, AttackLearnMethod learnMethod) { if (_attacks.size() >= _library->GetSettings().GetMaximalMoves()) throw CreatureException("You have already set the maximum amount of allowed moves."); auto attackData = _library->GetAttackLibrary()->GetAttack(attackName); _attacks.emplace_back(attackData, learnMethod); return this; } Creature* CreateCreature::Create() { auto rand = Core::Random(); auto species = this->_library->GetSpeciesLibrary()->GetSpecies(this->_species); auto variant = species->GetVariant(this->_variant); int8_t talent; if (this->_talent.empty()) { talent = variant->GetRandomTalent(&rand); } else { talent = variant->GetTalentIndex(this->_talent); } auto identifier = this->_identifier; if (identifier == 0) { identifier = rand.Get(); } auto gender = this->_gender; if (gender == static_cast(-1)) { gender = species->GetRandomGender(rand); } const Library::Item* heldItem = nullptr; if (!this->_heldItem.empty()) { heldItem = _library->GetItemLibrary()->GetItem(this->_heldItem); } // FIXME: implement experience auto experience = 0; auto attacks = std::vector(_attacks.size()); for (size_t i = 0; i < attacks.size(); i++) { auto kv = _attacks[i]; attacks[i] = new LearnedAttack(std::get<0>(kv), std::get<1>(kv)); } return new Creature(_library, species, variant, _level, experience, identifier, gender, _coloring, heldItem, _nickname, talent, attacks); }