Support learning moves with CreateCreature class
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-10-25 20:08:25 +02:00
parent 9588236183
commit 7d6de3557c
6 changed files with 38 additions and 3 deletions

View File

@@ -65,7 +65,18 @@ CreateCreature *CreateCreature::WithGender(Library::Gender gender) {
return this;
}
CreateCreature *CreateCreature::WithAttack(const std::string& attackName, AttackLearnMethod learnMethod) {
if (_attacks.size() >= _library->GetSettings().GetMaximalMoves())
//TODO: Better exception
throw "";
auto attackData = _library->GetAttackLibrary()->GetAttack(attackName);
_attacks.emplace_back(attackData, learnMethod);
return this;
}
Creature *CreateCreature::Create() {
_hasCreated = true;
auto rand = Core::Random();
auto species = this->_library->GetSpeciesLibrary()->GetSpecies(this->_species);
auto variant = species->GetVariant(this->_variant);
@@ -96,6 +107,12 @@ Creature *CreateCreature::Create() {
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, {});
heldItem, _nickname, talent, attacks);
}

View File

@@ -32,6 +32,9 @@ namespace CreatureLib::Battling {
uint8_t _coloring = 0;
std::string _heldItem = "";
uint32_t _identifier = 0;
std::vector<std::tuple<const Library::AttackData*, AttackLearnMethod>> _attacks = {};
bool _hasCreated;
public:
CreateCreature(const BattleLibrary *library, std::string species, uint8_t level)
@@ -48,6 +51,7 @@ namespace CreatureLib::Battling {
CreateCreature* WithStatExperiences(uint32_t health, uint32_t physAttack, uint32_t physDefense, uint32_t magAttack,
uint32_t magDefense,uint32_t speed);
CreateCreature* WithGender(Library::Gender gender);
CreateCreature* WithAttack(const std::string& attackName, AttackLearnMethod learnMethod);
Creature* Create();

View File

@@ -6,6 +6,11 @@ CreatureLib::Battling::LearnedAttack::LearnedAttack(CreatureLib::Library::Attack
}
CreatureLib::Battling::LearnedAttack::LearnedAttack(const CreatureLib::Library::AttackData *attack, AttackLearnMethod learnMethod)
: _attack(attack), _maxUses(attack->GetBaseUsages()), _remainingUses(_maxUses), _learnMethod(learnMethod)
{}
const CreatureLib::Library::AttackData *CreatureLib::Battling::LearnedAttack::GetAttack() const {
return _attack;
}
@@ -41,4 +46,3 @@ void CreatureLib::Battling::LearnedAttack::RestoreUses() {
_remainingUses = _maxUses;
}

View File

@@ -12,6 +12,7 @@ namespace CreatureLib::Battling{
AttackLearnMethod _learnMethod;
public:
LearnedAttack(Library::AttackData* attack, uint8_t maxUses, AttackLearnMethod learnMethod);
LearnedAttack(const Library::AttackData* attack, AttackLearnMethod learnMethod);
const Library::AttackData* GetAttack() const;
uint8_t GetMaxUses() const;