#include "CreateCreature.hpp" #include #include #include "../Library/BattleLibrary.hpp" using namespace CreatureLib::Battling; CreateCreature CreateCreature::WithVariant(const ArbUt::StringView& 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 ArbUt::StringView& attackName, AttackLearnMethod learnMethod) { if (_attacks.Count() >= _library->GetSettings()->GetMaximalMoves()) { THROW_CREATURE("You have already set the maximum amount of allowed moves."); } auto attackData = _library->GetAttackLibrary()->Get(attackName.GetHash()); _attacks.Append(std::tuple(attackData, learnMethod)); return *this; } Creature* CreateCreature::Create() { auto rand = ArbUt::Random(); auto species = this->_library->GetSpeciesLibrary()->Get(this->_species.GetHash()); 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); } ArbUt::BorrowedPtr heldItem; if (!this->_heldItem.Empty()) { if (!_library->GetItemLibrary()->TryGet(this->_heldItem.GetHash(), heldItem)) { THROW_CREATURE("Invalid held item '" << this->_heldItem.c_str() << "'."); } } auto experience = _library->GetGrowthRateLibrary()->CalculateExperience(species->GetGrowthRate(), _level); auto attacks = std::vector(_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; }