CreatureLib/src/Battling/Models/CreateCreature.cpp

117 lines
4.4 KiB
C++
Raw Normal View History

2019-10-06 11:50:52 +00:00
#include "CreateCreature.hpp"
#include <utility>
#include "../Library/BattleLibrary.hpp"
2019-10-06 11:50:52 +00:00
using namespace CreatureLib::Battling;
2019-10-06 11:50:52 +00:00
CreateCreature* CreateCreature::WithVariant(std::string variant) {
this->_variant = std::move(variant);
return this;
}
CreateCreature* CreateCreature::WithNickname(std::string nickname) {
2019-10-06 11:50:52 +00:00
this->_nickname = std::move(nickname);
return this;
}
CreateCreature* CreateCreature::WithStatPotential(CreatureLib::Core::Statistic stat, uint32_t value) {
switch (stat) {
case Core::Health: _healthPotential = value;
2019-10-06 11:50:52 +00:00
case Core::PhysicalAttack: _physAttackPotential = value;
case Core::PhysicalDefense: _physDefensePotential = value;
case Core::MagicalAttack: _magAttackPotential = value;
case Core::MagicalDefense: _magDefensePotential = value;
2019-10-06 11:50:52 +00:00
case Core::Speed: _speedPotential = value;
}
return this;
}
CreateCreature* CreateCreature::WithStatPotentials(uint32_t health, uint32_t physAttack, uint32_t physDefense,
uint32_t magAttack, uint32_t magDefense, uint32_t speed) {
2019-10-06 11:50:52 +00:00
_healthPotential = health;
_physAttackPotential = physAttack;
_physDefensePotential = physDefense;
_magAttackPotential = magAttack;
_magDefensePotential = magDefense;
_speedPotential = speed;
return this;
}
CreateCreature* CreateCreature::WithStatExperience(Core::Statistic stat, uint32_t value) {
switch (stat) {
case Core::Health: _healthExperience = value;
2019-10-06 11:50:52 +00:00
case Core::PhysicalAttack: _physAttackExperience = value;
case Core::PhysicalDefense: _physDefenseExperience = value;
case Core::MagicalAttack: _magAttackExperience = value;
case Core::MagicalDefense: _magDefenseExperience = value;
2019-10-06 11:50:52 +00:00
case Core::Speed: _speedExperience = value;
}
return this;
}
CreateCreature* CreateCreature::WithStatExperiences(uint32_t health, uint32_t physAttack, uint32_t physDefense,
uint32_t magAttack, uint32_t magDefense, uint32_t speed) {
2019-10-06 11:50:52 +00:00
_healthExperience = health;
_physAttackExperience = physAttack;
_physDefenseExperience = physDefense;
_magAttackExperience = magAttack;
_magDefenseExperience = magDefense;
_speedExperience = speed;
return this;
}
CreateCreature* CreateCreature::WithGender(Library::Gender gender) {
2019-10-06 11:50:52 +00:00
this->_gender = gender;
return this;
}
CreateCreature* CreateCreature::WithAttack(const std::string& attackName, AttackLearnMethod learnMethod) {
if (_attacks.size() >= _library->GetSettings().GetMaximalMoves())
2019-10-31 12:26:56 +00:00
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() {
_hasCreated = true;
2019-10-06 11:50:52 +00:00
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()) {
2019-10-06 11:50:52 +00:00
talent = variant->GetRandomTalent(&rand);
} else {
2019-10-06 11:50:52 +00:00
talent = variant->GetTalentIndex(this->_talent);
}
auto identifier = this->_identifier;
if (identifier == 0) {
2019-10-06 11:50:52 +00:00
identifier = rand.Get();
}
auto gender = this->_gender;
if (gender == static_cast<Library::Gender>(-1)) {
2019-10-06 11:50:52 +00:00
gender = species->GetRandomGender(rand);
}
const Library::Item* heldItem = nullptr;
if (!this->_heldItem.empty()) {
2019-10-06 11:50:52 +00:00
heldItem = _library->GetItemLibrary()->GetItem(this->_heldItem);
}
// FIXME: implement experience
auto experience = 0;
auto statExperience = Core::StatisticSet(_healthExperience, _physAttackExperience, _physDefenseExperience,
_magAttackExperience, _magDefenseExperience, _speedExperience);
auto statPotential = Core::StatisticSet(_healthPotential, _physAttackPotential, _physDefensePotential,
_magAttackPotential, _magDefensePotential, _speedPotential);
auto attacks = std::vector<LearnedAttack*>(_attacks.size());
for (auto kv : _attacks) {
attacks.push_back(new LearnedAttack(std::get<0>(kv), std::get<1>(kv)));
}
return new Creature(species, variant, _level, experience, statExperience, statPotential, identifier, gender,
_coloring, heldItem, _nickname, talent, attacks);
2019-10-06 11:50:52 +00:00
}