#include "CreateCreature.hpp" #include #include "../Library/BattleLibrary.hpp" using namespace CreatureLib::Battling; CreateCreature* CreateCreature::WithVariant(const Arbutils::CaseInsensitiveConstString& variant) { this->_variant = 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 Arbutils::CaseInsensitiveConstString& attackName, AttackLearnMethod learnMethod) { if (_attacks.Count() >= _library->GetSettings()->GetMaximalMoves()) throw CreatureException("You have already set the maximum amount of allowed moves."); auto attackData = _library->GetAttackLibrary()->Get(attackName); _attacks.Append(std::tuple(attackData, learnMethod)); return this; } Creature* CreateCreature::Create() { auto rand = Arbutils::Random(); auto species = this->_library->GetSpeciesLibrary()->Get(this->_species); auto variant = species->GetVariant(this->_variant); Library::TalentIndex 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()) { if (!_library->GetItemLibrary()->TryGet(this->_heldItem, heldItem)) { throw CreatureException("Invalid held item."); } } auto experience = _library->GetGrowthRateLibrary()->CalculateExperience(species->GetGrowthRate(), _level); auto attacks = List(_attacks.Count()); for (size_t i = 0; i < attacks.Count(); i++) { auto kv = _attacks[i]; attacks[i] = new LearnedAttack(std::get<0>(kv), std::get<1>(kv)); } auto c = new Creature(_library, species, variant, _level, experience, identifier, gender, _coloring, heldItem, _nickname, talent, attacks); c->Initialize(); return c; }