Support for learnable moves
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
cfb7663d78
commit
bb8978314f
|
@ -1,6 +1,5 @@
|
|||
#include "CreatureSpecies.hpp"
|
||||
|
||||
#include <utility>
|
||||
using namespace CreatureLib::Library;
|
||||
|
||||
CreatureSpecies::CreatureSpecies(uint16_t id, std::string name, const SpeciesVariant* defaultVariant,
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
#include "LearnableAttacks.hpp"
|
||||
|
||||
using namespace CreatureLib::Library;
|
||||
|
||||
void LearnableAttacks::AddLevelMove(uint8_t level, AttackData *attack) {
|
||||
_learnedByLevel[level].push_back(attack);
|
||||
}
|
||||
|
||||
const std::vector<const AttackData *> &LearnableAttacks::GetMovesForLevel(uint8_t level) const {
|
||||
return _learnedByLevel[level];
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef CREATURELIB_LEARNABLEATTACKS_HPP
|
||||
#define CREATURELIB_LEARNABLEATTACKS_HPP
|
||||
|
||||
#include <vector>
|
||||
#include "../Attacks/AttackData.hpp"
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
class LearnableAttacks {
|
||||
std::vector<std::vector<const AttackData*>> _learnedByLevel;
|
||||
public:
|
||||
LearnableAttacks(uint8_t maxLevel)
|
||||
:_learnedByLevel(std::vector<std::vector<const AttackData*>>(maxLevel)){}
|
||||
|
||||
void AddLevelMove(uint8_t level, AttackData* attack);
|
||||
|
||||
const std::vector<const AttackData*>& GetMovesForLevel(uint8_t level) const;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //CREATURELIB_LEARNABLEATTACKS_HPP
|
|
@ -42,11 +42,15 @@ int8_t CreatureLib::Library::SpeciesVariant::GetRandomTalent(CreatureLib::Core::
|
|||
return rand->Get(_talents.size());
|
||||
}
|
||||
|
||||
const CreatureLib::Library::LearnableAttacks *CreatureLib::Library::SpeciesVariant::GetLearnableAttacks() const {
|
||||
return _attacks;
|
||||
}
|
||||
|
||||
CreatureLib::Library::SpeciesVariant::SpeciesVariant(std::string name, float height, float weight,
|
||||
uint32_t baseExperience, std::vector<std::string> types,
|
||||
CreatureLib::Core::StatisticSet<uint16_t > baseStats,
|
||||
std::vector<std::string> talents,
|
||||
std::vector<std::string> secretTalents)
|
||||
std::vector<std::string> secretTalents, const LearnableAttacks* attacks)
|
||||
: __Name(name),
|
||||
__Height(height),
|
||||
__Weight(weight),
|
||||
|
@ -54,5 +58,10 @@ CreatureLib::Library::SpeciesVariant::SpeciesVariant(std::string name, float hei
|
|||
_types(types),
|
||||
_baseStatistics(baseStats),
|
||||
_talents(talents),
|
||||
_secretTalents(secretTalents)
|
||||
_secretTalents(secretTalents),
|
||||
_attacks(attacks)
|
||||
{}
|
||||
|
||||
CreatureLib::Library::SpeciesVariant::~SpeciesVariant() {
|
||||
delete _attacks;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "../../Core/StatisticSet.hpp"
|
||||
#include "../../GenericTemplates.cpp"
|
||||
#include "../../Core/Random.hpp"
|
||||
#include "LearnableAttacks.hpp"
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
/*!
|
||||
|
@ -22,17 +23,19 @@ namespace CreatureLib::Library {
|
|||
const Core::StatisticSet<uint16_t > _baseStatistics;
|
||||
std::vector<std::string> _talents;
|
||||
std::vector<std::string> _secretTalents;
|
||||
//CreatureMoves _moves;
|
||||
const LearnableAttacks* _attacks;
|
||||
public:
|
||||
SpeciesVariant(std::string name, float height, float weight, uint32_t baseExperience,
|
||||
std::vector<std::string> types, Core::StatisticSet<uint16_t > baseStats, std::vector<std::string> talents,
|
||||
std::vector<std::string> secretTalents);
|
||||
std::vector<std::string> secretTalents, const LearnableAttacks* attacks);
|
||||
|
||||
~SpeciesVariant();
|
||||
|
||||
[[nodiscard]] size_t GetTypeCount() const;
|
||||
[[nodiscard]] std::string GetType(size_t index) const;
|
||||
[[nodiscard]] uint32_t GetStatistic(Core::Statistic stat) const;
|
||||
[[nodiscard]] std::string GetTalent(int32_t index) const;
|
||||
//[[nodiscard]] const CreatureMoves* GetCreatureMoves() const;
|
||||
[[nodiscard]] const LearnableAttacks* GetLearnableAttacks() const;
|
||||
[[nodiscard]] int8_t GetTalentIndex(std::string talent) const;
|
||||
[[nodiscard]] int8_t GetRandomTalent(Core::Random* rand) const;
|
||||
};
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
#include "DataLibrary.hpp"
|
||||
|
||||
CreatureLib::Library::DataLibrary::DataLibrary(CreatureLib::Library::SpeciesLibrary *species,
|
||||
CreatureLib::Library::DataLibrary::DataLibrary(LibrarySettings settings,
|
||||
CreatureLib::Library::SpeciesLibrary *species,
|
||||
CreatureLib::Library::AttackLibrary *attacks,
|
||||
CreatureLib::Library::ItemLibrary *items,
|
||||
CreatureLib::Library::GrowthRateLibrary *growthRates)
|
||||
: _species(species), _attacks(attacks), _items(items),
|
||||
: _settings(settings), _species(species), _attacks(attacks), _items(items),
|
||||
_growthRates(growthRates){
|
||||
|
||||
}
|
||||
|
||||
const CreatureLib::Library::LibrarySettings &CreatureLib::Library::DataLibrary::GetSettings() const {
|
||||
return _settings;
|
||||
}
|
||||
|
||||
const CreatureLib::Library::SpeciesLibrary *CreatureLib::Library::DataLibrary::GetSpeciesLibrary() const {
|
||||
return _species;
|
||||
}
|
||||
|
@ -26,3 +31,4 @@ const CreatureLib::Library::GrowthRateLibrary *CreatureLib::Library::DataLibrary
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "AttackLibrary.hpp"
|
||||
#include "ItemLibrary.hpp"
|
||||
#include "GrowthRates/GrowthRateLibrary.hpp"
|
||||
#include "LibrarySettings.hpp"
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
/*!
|
||||
|
@ -12,12 +13,14 @@ namespace CreatureLib::Library {
|
|||
*/
|
||||
class DataLibrary {
|
||||
private:
|
||||
const LibrarySettings _settings;
|
||||
const SpeciesLibrary* _species;
|
||||
const AttackLibrary* _attacks;
|
||||
const ItemLibrary* _items;
|
||||
const GrowthRateLibrary* _growthRates;
|
||||
public:
|
||||
DataLibrary(CreatureLib::Library::SpeciesLibrary *species,
|
||||
DataLibrary(LibrarySettings settings,
|
||||
CreatureLib::Library::SpeciesLibrary *species,
|
||||
CreatureLib::Library::AttackLibrary *attacks,
|
||||
CreatureLib::Library::ItemLibrary *items,
|
||||
CreatureLib::Library::GrowthRateLibrary *growthRates
|
||||
|
@ -30,6 +33,7 @@ namespace CreatureLib::Library {
|
|||
delete _growthRates;
|
||||
}
|
||||
|
||||
[[nodiscard]] const LibrarySettings& GetSettings() const;
|
||||
[[nodiscard]] const SpeciesLibrary* GetSpeciesLibrary() const;
|
||||
[[nodiscard]] const AttackLibrary* GetAttackLibrary() const;
|
||||
[[nodiscard]] const ItemLibrary* GetItemLibrary() const;
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
#ifndef CREATURELIB_LIBRARYSETTINGS_HPP
|
||||
#define CREATURELIB_LIBRARYSETTINGS_HPP
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
class LibrarySettings{
|
||||
uint8_t _maximalLevel;
|
||||
uint8_t _maximalMoves;
|
||||
public:
|
||||
LibrarySettings(uint8_t maximalLevel, uint8_t maximalMoves)
|
||||
: _maximalLevel(maximalLevel), _maximalMoves(maximalMoves){}
|
||||
|
||||
inline uint8_t GetMaximalLevel() const{
|
||||
return _maximalLevel;
|
||||
}
|
||||
|
||||
inline uint8_t GetMaximalMoves() const{
|
||||
return _maximalMoves;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_LIBRARYSETTINGS_HPP
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef CREATURELIB_ATTACKLEARNMETHOD_HPP
|
||||
#define CREATURELIB_ATTACKLEARNMETHOD_HPP
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
enum class AttackLearnMethod {
|
||||
Unknown,
|
||||
Level
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_ATTACKLEARNMETHOD_HPP
|
|
@ -93,5 +93,5 @@ Creature *CreateCreature::Create() {
|
|||
_magAttackExperience, _magDefenseExperience, _speedExperience),
|
||||
Core::StatisticSet(_healthPotential, _physAttackPotential, _physDefensePotential,
|
||||
_magAttackPotential, _magDefensePotential, _speedPotential),
|
||||
identifier, gender, _coloring, heldItem);
|
||||
identifier, gender, _coloring, {}, heldItem);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include <assert.h>
|
||||
#include "Creature.hpp"
|
||||
|
||||
CreatureLib::Library::Creature::Creature(const CreatureLib::Library::DataLibrary *library,
|
||||
|
@ -7,6 +8,7 @@ CreatureLib::Library::Creature::Creature(const CreatureLib::Library::DataLibrary
|
|||
CreatureLib::Core::StatisticSet<uint8_t > statExperience,
|
||||
CreatureLib::Core::StatisticSet<uint8_t > statPotential,
|
||||
uint32_t identifier, CreatureLib::Library::Gender gender, uint8_t coloring,
|
||||
std::vector<LearnedAttack*> attacks,
|
||||
const CreatureLib::Library::Item *heldItem)
|
||||
:
|
||||
__Library(library),
|
||||
|
@ -20,9 +22,18 @@ CreatureLib::Library::Creature::Creature(const CreatureLib::Library::DataLibrary
|
|||
__Coloring(coloring),
|
||||
__HeldItem(heldItem),
|
||||
_nickname(nickname),
|
||||
_talentIndex(talentIndex)
|
||||
_talentIndex(talentIndex),
|
||||
_attacks(attacks)
|
||||
{
|
||||
if (_attacks.size() == 0){
|
||||
//TODO: give random moves
|
||||
}
|
||||
}
|
||||
|
||||
CreatureLib::Library::Creature::~Creature() {
|
||||
for (auto i: _attacks){
|
||||
delete i;
|
||||
}
|
||||
}
|
||||
|
||||
std::string CreatureLib::Library::Creature::GetTalent() const {
|
||||
|
@ -69,3 +80,4 @@ uint8_t CreatureLib::Library::Creature::GetStatPotential(CreatureLib::Core::Stat
|
|||
uint8_t CreatureLib::Library::Creature::GetStatExperience(CreatureLib::Core::Statistic stat) const {
|
||||
return this->__StatExperience.GetStat(stat);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "../Gender.hpp"
|
||||
#include "../../GenericTemplates.cpp"
|
||||
#include "../../Core/StatisticSet.hpp"
|
||||
#include "LearnedAttack.hpp"
|
||||
|
||||
namespace CreatureLib::Library{
|
||||
class Creature {
|
||||
|
@ -24,13 +25,14 @@ namespace CreatureLib::Library{
|
|||
private:
|
||||
std::string _nickname = "";
|
||||
int8_t _talentIndex;
|
||||
std::vector<LearnedAttack*> _attacks;
|
||||
public:
|
||||
Creature(const DataLibrary* library, const CreatureSpecies* species, const SpeciesVariant* variant,
|
||||
uint8_t level, std::string nickname, int8_t talentIndex, Core::StatisticSet<uint8_t > statExperience,
|
||||
Core::StatisticSet<uint8_t > statPotential, uint32_t identifier, Gender gender,
|
||||
uint8_t coloring, const Item* heldItem);
|
||||
uint8_t coloring, std::vector<LearnedAttack*> attacks, const Item* heldItem);
|
||||
|
||||
virtual ~Creature(){}
|
||||
virtual ~Creature();
|
||||
|
||||
std::string GetTalent() const;
|
||||
std::string GetNickname() const;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "LearnedAttack.hpp"
|
||||
|
||||
CreatureLib::Library::LearnedAttack::LearnedAttack(CreatureLib::Library::AttackData *attack, uint8_t maxUses)
|
||||
:_attack(attack), _maxUses(maxUses), _remainingUses(maxUses)
|
||||
CreatureLib::Library::LearnedAttack::LearnedAttack(CreatureLib::Library::AttackData *attack, uint8_t maxUses, AttackLearnMethod learnMethod)
|
||||
:_attack(attack), _maxUses(maxUses), _remainingUses(maxUses), _learnMethod(learnMethod)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -17,3 +17,28 @@ uint8_t CreatureLib::Library::LearnedAttack::GetMaxUses() const {
|
|||
uint8_t CreatureLib::Library::LearnedAttack::GetRemainingUses() const {
|
||||
return _remainingUses;
|
||||
}
|
||||
|
||||
CreatureLib::Library::AttackLearnMethod CreatureLib::Library::LearnedAttack::GetLearnMethod() const {
|
||||
return _learnMethod;
|
||||
}
|
||||
|
||||
|
||||
bool CreatureLib::Library::LearnedAttack::TryUse(uint8_t uses) {
|
||||
if (uses > _remainingUses) return false;
|
||||
_remainingUses -= uses;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CreatureLib::Library::LearnedAttack::DecreaseUses(uint8_t amount) {
|
||||
_remainingUses -= amount;
|
||||
}
|
||||
|
||||
void CreatureLib::Library::LearnedAttack::RestoreUses(uint8_t amount) {
|
||||
_remainingUses += amount;
|
||||
}
|
||||
|
||||
void CreatureLib::Library::LearnedAttack::RestoreUses() {
|
||||
_remainingUses = _maxUses;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,18 +2,26 @@
|
|||
#define CREATURELIB_LEARNEDATTACK_HPP
|
||||
|
||||
#include "../Attacks/AttackData.hpp"
|
||||
#include "AttackLearnMethod.hpp"
|
||||
|
||||
namespace CreatureLib::Library{
|
||||
class LearnedAttack {
|
||||
const AttackData* _attack;
|
||||
uint8_t _maxUses;
|
||||
uint8_t _remainingUses;
|
||||
AttackLearnMethod _learnMethod;
|
||||
public:
|
||||
LearnedAttack(AttackData* attack, uint8_t maxUses);
|
||||
LearnedAttack(AttackData* attack, uint8_t maxUses, AttackLearnMethod learnMethod);
|
||||
|
||||
const AttackData* GetAttack() const;
|
||||
uint8_t GetMaxUses() const;
|
||||
uint8_t GetRemainingUses() const;
|
||||
AttackLearnMethod GetLearnMethod() const;
|
||||
|
||||
bool TryUse(uint8_t uses);
|
||||
void DecreaseUses(uint8_t amount);
|
||||
void RestoreUses(uint8_t amount);
|
||||
void RestoreUses();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,8 @@ static SpeciesLibrary* BuildSpeciesLibrary(){
|
|||
l->LoadSpecies("testSpecies1", new CreatureSpecies(0, "testSpecies1",
|
||||
new SpeciesVariant("default", 1,1, 10, {"fire", "water"},
|
||||
StatisticSet<uint16_t >(10,10,10,10,10,10),
|
||||
{"testTalent"}, {"testSecretTalent"}),
|
||||
{"testTalent"}, {"testSecretTalent"},
|
||||
new LearnableAttacks(100)),
|
||||
0.5f, "testGrowthRate", 5, 100));
|
||||
return l;
|
||||
}
|
||||
|
@ -33,7 +34,8 @@ static GrowthRateLibrary* BuildGrowthRateLibrary(){
|
|||
|
||||
|
||||
static DataLibrary* BuildLibrary(){
|
||||
auto l = new DataLibrary(BuildSpeciesLibrary(), BuildAttackLibrary(), BuildItemLibrary(), BuildGrowthRateLibrary());
|
||||
auto l = new DataLibrary(LibrarySettings(100, 4), BuildSpeciesLibrary(), BuildAttackLibrary(),
|
||||
BuildItemLibrary(), BuildGrowthRateLibrary());
|
||||
return l;
|
||||
}
|
||||
|
||||
|
@ -44,9 +46,4 @@ static DataLibrary* GetLibrary(){
|
|||
}
|
||||
return __library;
|
||||
}
|
||||
|
||||
#ifndef LIBRARY_BUILD_TESTS
|
||||
#define LIBRARY_BUILD_TESTS
|
||||
|
||||
#endif
|
||||
#endif
|
Loading…
Reference in New Issue