Remove creature classes from Library lib, merged with Battling lib.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -6,12 +6,12 @@ CreatureSpecies::CreatureSpecies(uint16_t id, std::string name, const SpeciesVar
|
||||
float genderRatio, std::string growthRate, uint8_t captureRate, uint8_t baseHappiness)
|
||||
:
|
||||
__Id(id),
|
||||
__Name(std::move(name)),
|
||||
__GenderRate(genderRatio),
|
||||
__GrowthRate(std::move(growthRate)),
|
||||
__CaptureRate(captureRate),
|
||||
__BaseHappiness(baseHappiness),
|
||||
_variants({{"default", defaultVariant}})
|
||||
_variants({{"default", defaultVariant}}),
|
||||
_name(std::move(name))
|
||||
{}
|
||||
|
||||
const SpeciesVariant *CreatureSpecies::GetVariant(const std::string& key) const {
|
||||
@@ -25,3 +25,7 @@ Gender CreatureSpecies::GetRandomGender(CreatureLib::Core::Random &rand) const {
|
||||
return Gender ::Male;
|
||||
}
|
||||
|
||||
const std::string &CreatureSpecies::GetName() const {
|
||||
return _name;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,13 +12,13 @@ namespace CreatureLib::Library {
|
||||
*/
|
||||
class CreatureSpecies {
|
||||
GetProperty(uint16_t, Id);
|
||||
GetProperty(std::string, Name);
|
||||
GetProperty(float, GenderRate);
|
||||
GetProperty(std::string, GrowthRate);
|
||||
GetProperty(uint8_t, CaptureRate);
|
||||
GetProperty(uint8_t, BaseHappiness);
|
||||
private:
|
||||
std::unordered_map<std::string, const SpeciesVariant*> _variants;
|
||||
std::string _name;
|
||||
public:
|
||||
CreatureSpecies(uint16_t id, std::string name, const SpeciesVariant* defaultVariant,
|
||||
float genderRatio, std::string growthRate, uint8_t captureRate, uint8_t baseHappiness);
|
||||
@@ -31,6 +31,7 @@ namespace CreatureLib::Library {
|
||||
|
||||
[[nodiscard]] const SpeciesVariant* GetVariant(const std::string& key) const;
|
||||
[[nodiscard]] Gender GetRandomGender(Core::Random& rand) const;
|
||||
[[nodiscard]] const std::string& GetName() const;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ uint32_t CreatureLib::Library::SpeciesVariant::GetStatistic(CreatureLib::Core::S
|
||||
return _baseStatistics.GetStat(stat);
|
||||
}
|
||||
|
||||
std::string CreatureLib::Library::SpeciesVariant::GetTalent(int32_t index) const {
|
||||
const std::string& CreatureLib::Library::SpeciesVariant::GetTalent(int32_t index) const {
|
||||
if (index < 0){
|
||||
index = -index - 1;
|
||||
return _secretTalents[index];
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace CreatureLib::Library {
|
||||
[[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 std::string& GetTalent(int32_t index) const;
|
||||
[[nodiscard]] const LearnableAttacks* GetLearnableAttacks() const;
|
||||
[[nodiscard]] int8_t GetTalentIndex(std::string talent) const;
|
||||
[[nodiscard]] int8_t GetRandomTalent(Core::Random* rand) const;
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
#ifndef CREATURELIB_ATTACKLEARNMETHOD_HPP
|
||||
#define CREATURELIB_ATTACKLEARNMETHOD_HPP
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
enum class AttackLearnMethod {
|
||||
Unknown,
|
||||
Level
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_ATTACKLEARNMETHOD_HPP
|
||||
@@ -1,97 +0,0 @@
|
||||
#include "CreateCreature.hpp"
|
||||
#include <utility>
|
||||
|
||||
using namespace CreatureLib::Library;
|
||||
|
||||
CreateCreature* CreateCreature::WithVariant(std::string variant) {
|
||||
this->_variant = std::move(variant);
|
||||
return this;
|
||||
}
|
||||
|
||||
CreateCreature *CreateCreature::WithNickname(std::string nickname) {
|
||||
this->_nickname = std::move(nickname);
|
||||
return this;
|
||||
}
|
||||
|
||||
CreateCreature *CreateCreature::WithStatPotential(CreatureLib::Core::Statistic stat, uint32_t value) {
|
||||
switch (stat){
|
||||
case Core::Health:_healthPotential = value;
|
||||
case Core::PhysicalAttack: _physAttackPotential = value;
|
||||
case Core::PhysicalDefense: _physDefensePotential = value;
|
||||
case Core::MagicalAttack: _magAttackPotential = value;
|
||||
case Core::MagicalDefense:_magDefensePotential = value;
|
||||
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) {
|
||||
_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;
|
||||
case Core::PhysicalAttack: _physAttackExperience = value;
|
||||
case Core::PhysicalDefense: _physDefenseExperience = value;
|
||||
case Core::MagicalAttack: _magAttackExperience = value;
|
||||
case Core::MagicalDefense:_magDefenseExperience = value;
|
||||
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) {
|
||||
_healthExperience = health;
|
||||
_physAttackExperience = physAttack;
|
||||
_physDefenseExperience = physDefense;
|
||||
_magAttackExperience = magAttack;
|
||||
_magDefenseExperience = magDefense;
|
||||
_speedExperience = speed;
|
||||
return this;
|
||||
}
|
||||
|
||||
CreateCreature *CreateCreature::WithGender(Gender gender) {
|
||||
this->_gender = gender;
|
||||
return this;
|
||||
}
|
||||
|
||||
Creature *CreateCreature::Create() {
|
||||
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()){
|
||||
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<Gender >(-1)){
|
||||
gender = species->GetRandomGender(rand);
|
||||
}
|
||||
const Item* heldItem = nullptr;
|
||||
if (!this->_heldItem.empty()){
|
||||
heldItem = _library->GetItemLibrary()->GetItem(this->_heldItem);
|
||||
}
|
||||
return new Creature(this->_library, species, variant, this->_level, this->_nickname, talent,
|
||||
Core::StatisticSet(_healthExperience, _physAttackExperience, _physDefenseExperience,
|
||||
_magAttackExperience, _magDefenseExperience, _speedExperience),
|
||||
Core::StatisticSet(_healthPotential, _physAttackPotential, _physDefensePotential,
|
||||
_magAttackPotential, _magDefensePotential, _speedPotential),
|
||||
identifier, gender, _coloring, {}, heldItem);
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
#ifndef CREATURELIB_CREATECREATURE_HPP
|
||||
#define CREATURELIB_CREATECREATURE_HPP
|
||||
|
||||
|
||||
#include "../DataLibrary.hpp"
|
||||
#include "Creature.hpp"
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
class CreateCreature {
|
||||
const DataLibrary *_library;
|
||||
std::string _species;
|
||||
std::string _variant = "default";
|
||||
uint8_t _level;
|
||||
std::string _nickname = "";
|
||||
|
||||
uint8_t _healthPotential = 0;
|
||||
uint8_t _physAttackPotential = 0;
|
||||
uint8_t _physDefensePotential = 0;
|
||||
uint8_t _magAttackPotential = 0;
|
||||
uint8_t _magDefensePotential = 0;
|
||||
uint8_t _speedPotential = 0;
|
||||
|
||||
uint8_t _healthExperience = 0;
|
||||
uint8_t _physAttackExperience = 0;
|
||||
uint8_t _physDefenseExperience = 0;
|
||||
uint8_t _magAttackExperience = 0;
|
||||
uint8_t _magDefenseExperience = 0;
|
||||
uint8_t _speedExperience = 0;
|
||||
|
||||
std::string _talent = "";
|
||||
Gender _gender = static_cast<Gender>(-1);
|
||||
uint8_t _coloring = 0;
|
||||
std::string _heldItem = "";
|
||||
uint32_t _identifier = 0;
|
||||
|
||||
public:
|
||||
CreateCreature(const DataLibrary *library, std::string species, uint8_t level)
|
||||
: _library(library), _species(std::move(species)), _level(level)
|
||||
{
|
||||
}
|
||||
|
||||
CreateCreature* WithVariant(std::string variant);
|
||||
CreateCreature* WithNickname(std::string nickname);
|
||||
CreateCreature* WithStatPotential(Core::Statistic stat, uint32_t value);
|
||||
CreateCreature* WithStatPotentials(uint32_t health, uint32_t physAttack, uint32_t physDefense, uint32_t magAttack,
|
||||
uint32_t magDefense,uint32_t speed);
|
||||
CreateCreature* WithStatExperience(Core::Statistic stat, uint32_t value);
|
||||
CreateCreature* WithStatExperiences(uint32_t health, uint32_t physAttack, uint32_t physDefense, uint32_t magAttack,
|
||||
uint32_t magDefense,uint32_t speed);
|
||||
CreateCreature* WithGender(Gender gender);
|
||||
|
||||
|
||||
Creature* Create();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //CREATURELIB_CREATECREATURE_HPP
|
||||
@@ -1,83 +0,0 @@
|
||||
#include <assert.h>
|
||||
#include "Creature.hpp"
|
||||
|
||||
CreatureLib::Library::Creature::Creature(const CreatureLib::Library::DataLibrary *library,
|
||||
const CreatureLib::Library::CreatureSpecies *species,
|
||||
const CreatureLib::Library::SpeciesVariant *variant, uint8_t level,
|
||||
std::string nickname, int8_t talentIndex,
|
||||
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),
|
||||
__Species(species),
|
||||
__Variant(variant),
|
||||
__Level(level),
|
||||
__StatExperience(statExperience),
|
||||
__StatPotential(statPotential),
|
||||
__UniqueIdentifier(identifier),
|
||||
__Gender(gender),
|
||||
__Coloring(coloring),
|
||||
__HeldItem(heldItem),
|
||||
_nickname(nickname),
|
||||
_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 {
|
||||
return __Variant->GetTalent(_talentIndex);
|
||||
}
|
||||
|
||||
std::string CreatureLib::Library::Creature::GetNickname() const {
|
||||
if (_nickname.empty())
|
||||
return __Species->GetName();
|
||||
return _nickname;
|
||||
}
|
||||
|
||||
int32_t CalculateHealth(const CreatureLib::Library::Creature* creature){
|
||||
auto baseStat = creature->GetVariant()->GetStatistic(CreatureLib::Core::Statistic::Health);
|
||||
auto statPotential = creature->GetStatPotential().GetHealth();
|
||||
auto statExperience = creature->GetStatExperience().GetHealth();
|
||||
auto level = creature->GetLevel();
|
||||
return ((2 * baseStat + statPotential + (statExperience / 4) * level) / 100) + level + 10;
|
||||
}
|
||||
|
||||
int32_t CalculateStat(const CreatureLib::Library::Creature* creature, CreatureLib::Core::Statistic stat){
|
||||
auto baseStat = creature->GetVariant()->GetStatistic(stat);
|
||||
auto statPotential = creature->GetStatPotential().GetStat(stat);
|
||||
auto statExperience = creature->GetStatExperience().GetStat(stat);
|
||||
auto level = creature->GetLevel();
|
||||
return ((2 * baseStat + statPotential + (statExperience / 4) * level) / 100) + 5;
|
||||
}
|
||||
|
||||
|
||||
uint32_t CreatureLib::Library::Creature::CalculateFullStat(CreatureLib::Core::Statistic stat) const {
|
||||
if (stat == Core::Statistic::Health)
|
||||
return CalculateHealth(this);
|
||||
return CalculateStat(this, stat);
|
||||
}
|
||||
|
||||
uint16_t CreatureLib::Library::Creature::GetBaseStat(CreatureLib::Core::Statistic stat) const {
|
||||
return this->GetVariant()->GetStatistic(stat);
|
||||
}
|
||||
|
||||
uint8_t CreatureLib::Library::Creature::GetStatPotential(CreatureLib::Core::Statistic stat) const {
|
||||
return this->__StatPotential.GetStat(stat);
|
||||
}
|
||||
|
||||
uint8_t CreatureLib::Library::Creature::GetStatExperience(CreatureLib::Core::Statistic stat) const {
|
||||
return this->__StatExperience.GetStat(stat);
|
||||
}
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
#ifndef CREATURELIB_CREATURE_HPP
|
||||
#define CREATURELIB_CREATURE_HPP
|
||||
|
||||
#include "../DataLibrary.hpp"
|
||||
#include "../Gender.hpp"
|
||||
#include "../../GenericTemplates.cpp"
|
||||
#include "../../Core/StatisticSet.hpp"
|
||||
#include "LearnedAttack.hpp"
|
||||
|
||||
namespace CreatureLib::Library{
|
||||
class Creature {
|
||||
GetProperty(const DataLibrary*, Library);
|
||||
GetProperty(const CreatureSpecies*, Species);
|
||||
GetProperty(const SpeciesVariant*, Variant);
|
||||
GetProperty(uint8_t, Level);
|
||||
GetProperty(uint32_t, Experience);
|
||||
GetProperty(Core::StatisticSet<uint8_t >, StatExperience);
|
||||
GetProperty(Core::StatisticSet<uint8_t >, StatPotential);
|
||||
GetProperty(uint32_t, UniqueIdentifier);
|
||||
GetProperty(Gender, Gender);
|
||||
GetProperty(uint8_t, Coloring);
|
||||
GetProperty(const Item*, HeldItem);
|
||||
|
||||
GetProperty(uint32_t, CurrentHealth);
|
||||
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, std::vector<LearnedAttack*> attacks, const Item* heldItem);
|
||||
|
||||
virtual ~Creature();
|
||||
|
||||
std::string GetTalent() const;
|
||||
std::string GetNickname() const;
|
||||
virtual uint32_t CalculateFullStat(Core::Statistic stat) const;
|
||||
virtual uint16_t GetBaseStat(Core::Statistic stat) const;
|
||||
virtual uint8_t GetStatPotential(Core::Statistic stat) const;
|
||||
virtual uint8_t GetStatExperience(Core::Statistic stat) const;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //CREATURELIB_CREATURE_HPP
|
||||
@@ -1,44 +0,0 @@
|
||||
#include "LearnedAttack.hpp"
|
||||
|
||||
CreatureLib::Library::LearnedAttack::LearnedAttack(CreatureLib::Library::AttackData *attack, uint8_t maxUses, AttackLearnMethod learnMethod)
|
||||
:_attack(attack), _maxUses(maxUses), _remainingUses(maxUses), _learnMethod(learnMethod)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
const CreatureLib::Library::AttackData *CreatureLib::Library::LearnedAttack::GetAttack() const {
|
||||
return _attack;
|
||||
}
|
||||
|
||||
uint8_t CreatureLib::Library::LearnedAttack::GetMaxUses() const {
|
||||
return _maxUses;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
#ifndef CREATURELIB_LEARNEDATTACK_HPP
|
||||
#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, 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();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //CREATURELIB_LEARNEDATTACK_HPP
|
||||
Reference in New Issue
Block a user