Added functionality to get full stats from creature

This commit is contained in:
Deukhoofd 2019-10-10 15:08:34 +02:00
parent cbfeae94fa
commit 212a7d1ad6
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
7 changed files with 37 additions and 7 deletions

View File

@ -34,3 +34,26 @@ std::string CreatureLib::Library::Creature::GetNickname() const {
return __Species->GetName(); return __Species->GetName();
return _nickname; 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;
}
int32_t CreatureLib::Library::Creature::CalculateFullStat(CreatureLib::Core::Statistic stat) const {
if (stat == Core::Statistic::Health)
return CalculateHealth(this);
return CalculateStat(this, stat);
}

View File

@ -30,8 +30,11 @@ namespace CreatureLib::Library{
Core::StatisticSet statPotential, uint32_t identifier, Gender gender, Core::StatisticSet statPotential, uint32_t identifier, Gender gender,
uint8_t coloring, const Item* heldItem); uint8_t coloring, const Item* heldItem);
virtual ~Creature(){}
std::string GetTalent() const; std::string GetTalent() const;
std::string GetNickname() const; std::string GetNickname() const;
virtual int32_t CalculateFullStat(Core::Statistic stat) const;
}; };
} }

View File

@ -3,10 +3,9 @@
CreatureLib::Library::DataLibrary::DataLibrary(CreatureLib::Library::SpeciesLibrary *species, CreatureLib::Library::DataLibrary::DataLibrary(CreatureLib::Library::SpeciesLibrary *species,
CreatureLib::Library::AttackLibrary *attacks, CreatureLib::Library::AttackLibrary *attacks,
CreatureLib::Library::ItemLibrary *items, CreatureLib::Library::ItemLibrary *items,
CreatureLib::Library::GrowthRateLibrary* growthRates) CreatureLib::Library::GrowthRateLibrary *growthRates)
:_species(species), _attacks(attacks), _items(items), _growthRates(growthRates) : _species(species), _attacks(attacks), _items(items),
_growthRates(growthRates){
{
} }

View File

@ -17,7 +17,12 @@ namespace CreatureLib::Library {
const ItemLibrary* _items; const ItemLibrary* _items;
const GrowthRateLibrary* _growthRates; const GrowthRateLibrary* _growthRates;
public: public:
DataLibrary(SpeciesLibrary* species, AttackLibrary* attacks, ItemLibrary* items, GrowthRateLibrary* growthRates); DataLibrary(CreatureLib::Library::SpeciesLibrary *species,
CreatureLib::Library::AttackLibrary *attacks,
CreatureLib::Library::ItemLibrary *items,
CreatureLib::Library::GrowthRateLibrary *growthRates
);
~DataLibrary(){ ~DataLibrary(){
delete _species; delete _species;
delete _attacks; delete _attacks;

View File

@ -1,6 +1,6 @@
#ifdef TESTS_BUILD #ifdef TESTS_BUILD
#include "../../src/Library/CreateCreature.hpp" #include "../../src/Library/CreateCreature.hpp"
#include "TestLibrary.cpp" #include "../TestLibrary/TestLibrary.cpp"
using namespace CreatureLib::Library; using namespace CreatureLib::Library;
TEST_CASE( "Create basic creature", "[Library]" ) { TEST_CASE( "Create basic creature", "[Library]" ) {

View File

@ -2,7 +2,7 @@
#define CATCH_CONFIG_MAIN #define CATCH_CONFIG_MAIN
#include "../../extern/catch.hpp" #include "../../extern/catch.hpp"
#include "TestLibrary.cpp" #include "../TestLibrary/TestLibrary.cpp"
TEST_CASE( "Can Create Species Library", "[Library]" ) { TEST_CASE( "Can Create Species Library", "[Library]" ) {
auto l = BuildSpeciesLibrary(); auto l = BuildSpeciesLibrary();