2019-11-28 11:55:22 +00:00
|
|
|
|
2019-10-06 11:50:52 +00:00
|
|
|
#include "CreateCreature.hpp"
|
|
|
|
|
2019-10-24 11:37:55 +00:00
|
|
|
using namespace CreatureLib::Battling;
|
2019-10-06 11:50:52 +00:00
|
|
|
|
2020-06-26 15:08:23 +00:00
|
|
|
CreateCreature CreateCreature::WithVariant(const ArbUt::StringView& variant) {
|
2020-02-27 17:23:23 +00:00
|
|
|
this->_variant = variant;
|
2020-04-25 08:41:15 +00:00
|
|
|
return *this;
|
2019-10-06 11:50:52 +00:00
|
|
|
}
|
|
|
|
|
2020-04-25 08:41:15 +00:00
|
|
|
CreateCreature CreateCreature::WithNickname(std::string nickname) {
|
2019-10-06 11:50:52 +00:00
|
|
|
this->_nickname = std::move(nickname);
|
2020-04-25 08:41:15 +00:00
|
|
|
return *this;
|
2019-10-06 11:50:52 +00:00
|
|
|
}
|
|
|
|
|
2020-04-25 08:41:15 +00:00
|
|
|
CreateCreature CreateCreature::WithGender(Library::Gender gender) {
|
2019-10-06 11:50:52 +00:00
|
|
|
this->_gender = gender;
|
2020-04-25 08:41:15 +00:00
|
|
|
return *this;
|
2019-10-06 11:50:52 +00:00
|
|
|
}
|
|
|
|
|
2020-06-26 15:08:23 +00:00
|
|
|
CreateCreature CreateCreature::WithAttack(const ArbUt::StringView& attackName, AttackLearnMethod learnMethod) {
|
2020-08-12 15:51:06 +00:00
|
|
|
if (_attacks.Count() >= _library->GetSettings()->GetMaximalAttacks()) {
|
2020-08-17 10:18:01 +00:00
|
|
|
THROW("You have already set the maximum amount of allowed moves.");
|
2020-07-28 17:37:03 +00:00
|
|
|
}
|
2019-10-25 18:08:25 +00:00
|
|
|
|
2020-05-26 12:13:30 +00:00
|
|
|
auto attackData = _library->GetAttackLibrary()->Get(attackName.GetHash());
|
2020-03-22 18:21:40 +00:00
|
|
|
_attacks.Append(std::tuple(attackData, learnMethod));
|
2020-04-25 08:41:15 +00:00
|
|
|
return *this;
|
2019-10-25 18:08:25 +00:00
|
|
|
}
|
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
Creature* CreateCreature::Create() {
|
2020-05-26 16:31:06 +00:00
|
|
|
auto rand = ArbUt::Random();
|
2020-05-26 12:13:30 +00:00
|
|
|
auto species = this->_library->GetSpeciesLibrary()->Get(this->_species.GetHash());
|
2019-10-06 11:50:52 +00:00
|
|
|
auto variant = species->GetVariant(this->_variant);
|
2020-03-05 10:25:41 +00:00
|
|
|
Library::TalentIndex talent;
|
2020-08-08 10:28:20 +00:00
|
|
|
if (this->_talent.IsEmpty()) {
|
2020-07-12 13:26:00 +00:00
|
|
|
talent = variant->GetRandomTalent(rand);
|
2019-11-28 11:55:22 +00:00
|
|
|
} else {
|
2019-10-06 11:50:52 +00:00
|
|
|
talent = variant->GetTalentIndex(this->_talent);
|
|
|
|
}
|
|
|
|
auto identifier = this->_identifier;
|
2019-11-28 11:55:22 +00:00
|
|
|
if (identifier == 0) {
|
2022-03-25 18:21:02 +00:00
|
|
|
identifier = rand.GetUnsigned();
|
2019-10-06 11:50:52 +00:00
|
|
|
}
|
|
|
|
auto gender = this->_gender;
|
2019-11-28 11:55:22 +00:00
|
|
|
if (gender == static_cast<Library::Gender>(-1)) {
|
2019-10-06 11:50:52 +00:00
|
|
|
gender = species->GetRandomGender(rand);
|
|
|
|
}
|
2020-12-12 12:40:30 +00:00
|
|
|
ArbUt::OptionalBorrowedPtr<const Library::Item> heldItem;
|
2020-08-08 10:28:20 +00:00
|
|
|
if (!this->_heldItem.IsEmpty()) {
|
2020-12-12 11:42:28 +00:00
|
|
|
auto val = _library->GetItemLibrary()->TryGet(this->_heldItem.GetHash());
|
|
|
|
if (!val.has_value()) {
|
2021-11-21 11:39:07 +00:00
|
|
|
THROW("Invalid held item '", this->_heldItem.c_str(), "'.");
|
2020-02-15 17:51:21 +00:00
|
|
|
}
|
2020-12-12 11:42:28 +00:00
|
|
|
heldItem = val.value();
|
2019-10-06 11:50:52 +00:00
|
|
|
}
|
2020-03-05 10:25:41 +00:00
|
|
|
auto experience = _library->GetGrowthRateLibrary()->CalculateExperience(species->GetGrowthRate(), _level);
|
2019-10-24 11:37:55 +00:00
|
|
|
|
2020-05-31 15:26:39 +00:00
|
|
|
auto attacks = std::vector<LearnedAttack*>(_attacks.Count());
|
2020-04-25 08:41:15 +00:00
|
|
|
for (size_t i = 0; i < _attacks.Count(); i++) {
|
2019-12-05 11:56:41 +00:00
|
|
|
auto kv = _attacks[i];
|
2020-05-31 15:26:39 +00:00
|
|
|
attacks[i] = new LearnedAttack(std::get<0>(kv), std::get<1>(kv));
|
2019-10-25 18:08:25 +00:00
|
|
|
}
|
2020-01-05 12:43:47 +00:00
|
|
|
auto c = new Creature(_library, species, variant, _level, experience, identifier, gender, _coloring, heldItem,
|
|
|
|
_nickname, talent, attacks);
|
|
|
|
c->Initialize();
|
|
|
|
return c;
|
2019-10-06 11:50:52 +00:00
|
|
|
}
|