Merge Core library into Library, as with its utility functionality merged into Arbutils, it's becoming less and less useful.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -8,7 +8,7 @@ size_t CreatureLib::Library::SpeciesVariant::GetTypeCount() const { return _type
|
||||
|
||||
uint8_t CreatureLib::Library::SpeciesVariant::GetType(size_t index) const { return _types[index]; }
|
||||
|
||||
uint32_t CreatureLib::Library::SpeciesVariant::GetStatistic(CreatureLib::Core::Statistic stat) const {
|
||||
uint32_t CreatureLib::Library::SpeciesVariant::GetStatistic(CreatureLib::Library::Statistic stat) const {
|
||||
return _baseStatistics.GetStat(stat);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ const CreatureLib::Library::LearnableAttacks* CreatureLib::Library::SpeciesVaria
|
||||
|
||||
CreatureLib::Library::SpeciesVariant::SpeciesVariant(ConstString name, float height, float weight,
|
||||
uint32_t baseExperience, std::vector<uint8_t> types,
|
||||
CreatureLib::Core::StatisticSet<uint16_t> baseStats,
|
||||
CreatureLib::Library::StatisticSet<uint16_t> baseStats,
|
||||
std::vector<ConstString> talents,
|
||||
std::vector<ConstString> secretTalents,
|
||||
const LearnableAttacks* attacks)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <Arbutils/Random.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "../../Core/StatisticSet.hpp"
|
||||
#include "../StatisticSet.hpp"
|
||||
#include "CreatureMoves.hpp"
|
||||
#include "LearnableAttacks.hpp"
|
||||
#include "TalentIndex.hpp"
|
||||
@@ -23,14 +23,14 @@ namespace CreatureLib::Library {
|
||||
|
||||
private:
|
||||
std::vector<uint8_t> _types;
|
||||
const Core::StatisticSet<uint16_t> _baseStatistics;
|
||||
const Library::StatisticSet<uint16_t> _baseStatistics;
|
||||
std::vector<ConstString> _talents;
|
||||
std::vector<ConstString> _secretTalents;
|
||||
const LearnableAttacks* _attacks;
|
||||
|
||||
public:
|
||||
SpeciesVariant(ConstString name, float height, float weight, uint32_t baseExperience,
|
||||
std::vector<uint8_t> types, Core::StatisticSet<uint16_t> baseStats,
|
||||
std::vector<uint8_t> types, Library::StatisticSet<uint16_t> baseStats,
|
||||
std::vector<ConstString> talents, std::vector<ConstString> secretTalents,
|
||||
const LearnableAttacks* attacks);
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace CreatureLib::Library {
|
||||
[[nodiscard]] size_t GetTypeCount() const;
|
||||
[[nodiscard]] uint8_t GetType(size_t index) const;
|
||||
[[nodiscard]] const std::vector<uint8_t>& GetTypes() const;
|
||||
[[nodiscard]] uint32_t GetStatistic(Core::Statistic stat) const;
|
||||
[[nodiscard]] uint32_t GetStatistic(Library::Statistic stat) const;
|
||||
[[nodiscard]] const size_t GetTalentCount() const { return _talents.size(); }
|
||||
[[nodiscard]] const size_t GetSecretTalentCount() const { return _secretTalents.size(); }
|
||||
[[nodiscard]] const ConstString& GetTalent(const TalentIndex& index) const {
|
||||
|
||||
13
src/Library/Exceptions/CreatureException.hpp
Normal file
13
src/Library/Exceptions/CreatureException.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef CREATURELIB_CREATUREEXCEPTION_HPP
|
||||
#define CREATURELIB_CREATUREEXCEPTION_HPP
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
class CreatureException : public std::runtime_error {
|
||||
public:
|
||||
explicit CreatureException(const std::string& error) : std::runtime_error(error) {}
|
||||
virtual ~CreatureException() = default;
|
||||
};
|
||||
|
||||
#endif // CREATURELIB_CREATUREEXCEPTION_HPP
|
||||
12
src/Library/Exceptions/NotImplementedException.hpp
Normal file
12
src/Library/Exceptions/NotImplementedException.hpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef CREATURELIB_NOTIMPLEMENTEDEXCEPTION_HPP
|
||||
#define CREATURELIB_NOTIMPLEMENTEDEXCEPTION_HPP
|
||||
|
||||
#include "CreatureException.hpp"
|
||||
|
||||
class NotImplementedException : CreatureException {
|
||||
public:
|
||||
NotImplementedException(std::string error) : CreatureException(error) {}
|
||||
NotImplementedException() : CreatureException("Not Implemented") {}
|
||||
};
|
||||
|
||||
#endif // CREATURELIB_NOTIMPLEMENTEDEXCEPTION_HPP
|
||||
11
src/Library/Exceptions/NotReachableException.hpp
Normal file
11
src/Library/Exceptions/NotReachableException.hpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef CREATURELIB_NOTREACHABLEEXCEPTION_HPP
|
||||
#define CREATURELIB_NOTREACHABLEEXCEPTION_HPP
|
||||
|
||||
#include "CreatureException.hpp"
|
||||
|
||||
class NotReachableException : CreatureException {
|
||||
public:
|
||||
NotReachableException() : CreatureException("Not Reachable"){};
|
||||
};
|
||||
|
||||
#endif // CREATURELIB_NOTREACHABLEEXCEPTION_HPP
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "GrowthRateLibrary.hpp"
|
||||
#include "../../Core/Exceptions/CreatureException.hpp"
|
||||
#include "../Exceptions/CreatureException.hpp"
|
||||
|
||||
uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const ConstString& growthRate,
|
||||
uint32_t experience) const {
|
||||
|
||||
11
src/Library/Statistic.hpp
Normal file
11
src/Library/Statistic.hpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef CREATURELIB_STATISTIC_HPP
|
||||
#define CREATURELIB_STATISTIC_HPP
|
||||
|
||||
#include <Arbutils/Enum.hpp>
|
||||
#include <cstdint>
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
ENUM(Statistic, uint8_t, Health, PhysicalAttack, PhysicalDefense, MagicalAttack, MagicalDefense, Speed)
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_STATISTIC_HPP
|
||||
81
src/Library/StatisticSet.hpp
Normal file
81
src/Library/StatisticSet.hpp
Normal file
@@ -0,0 +1,81 @@
|
||||
#ifndef CREATURELIB_STATISTICSET_HPP
|
||||
#define CREATURELIB_STATISTICSET_HPP
|
||||
#include <exception>
|
||||
#include <stdint.h>
|
||||
#include "Exceptions/NotReachableException.hpp"
|
||||
#include "Statistic.hpp"
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
template <class T> class StatisticSet {
|
||||
protected:
|
||||
T _health;
|
||||
T _physicalAttack;
|
||||
T _physicalDefense;
|
||||
T _magicalAttack;
|
||||
T _magicalDefense;
|
||||
T _speed;
|
||||
|
||||
public:
|
||||
StatisticSet(T health, T physicalAttack, T physicalDefense, T magicalAttack, T magicalDefense, T speed)
|
||||
: _health(health), _physicalAttack(physicalAttack), _physicalDefense(physicalDefense),
|
||||
_magicalAttack(magicalAttack), _magicalDefense(magicalDefense), _speed(speed) {}
|
||||
StatisticSet()
|
||||
: _health(0), _physicalAttack(0), _physicalDefense(0), _magicalAttack(0), _magicalDefense(0), _speed(0) {}
|
||||
|
||||
inline T GetHealth() const { return _health; }
|
||||
inline T GetPhysicalAttack() const { return _physicalAttack; }
|
||||
inline T GetPhysicalDefense() const { return _physicalDefense; }
|
||||
inline T GetMagicalAttack() const { return _magicalAttack; }
|
||||
inline T GetMagicalDefense() const { return _magicalDefense; }
|
||||
inline T GetSpeed() const { return _speed; }
|
||||
|
||||
[[nodiscard]] inline T GetStat(Statistic stat) const {
|
||||
switch (stat) {
|
||||
case CreatureLib::Library::Statistic::Health: return _health;
|
||||
case CreatureLib::Library::Statistic::PhysicalAttack: return _physicalAttack;
|
||||
case CreatureLib::Library::Statistic::PhysicalDefense: return _physicalDefense;
|
||||
case CreatureLib::Library::Statistic::MagicalAttack: return _magicalAttack;
|
||||
case CreatureLib::Library::Statistic::MagicalDefense: return _magicalDefense;
|
||||
case CreatureLib::Library::Statistic::Speed: return _speed;
|
||||
default: throw NotReachableException();
|
||||
}
|
||||
}
|
||||
|
||||
inline void SetStat(Statistic stat, T value) {
|
||||
switch (stat) {
|
||||
case CreatureLib::Library::Statistic::Health: _health = value; break;
|
||||
case CreatureLib::Library::Statistic::PhysicalAttack: _physicalAttack = value; break;
|
||||
case CreatureLib::Library::Statistic::PhysicalDefense: _physicalDefense = value; break;
|
||||
case CreatureLib::Library::Statistic::MagicalAttack: _magicalAttack = value; break;
|
||||
case CreatureLib::Library::Statistic::MagicalDefense: _magicalDefense = value; break;
|
||||
case CreatureLib::Library::Statistic::Speed: _speed = value; break;
|
||||
default: throw NotReachableException();
|
||||
}
|
||||
}
|
||||
|
||||
inline void IncreaseStatBy(Statistic stat, T amount) {
|
||||
switch (stat) {
|
||||
case CreatureLib::Library::Statistic::Health: _health += amount; break;
|
||||
case CreatureLib::Library::Statistic::PhysicalAttack: _physicalAttack += amount; break;
|
||||
case CreatureLib::Library::Statistic::PhysicalDefense: _physicalDefense += amount; break;
|
||||
case CreatureLib::Library::Statistic::MagicalAttack: _magicalAttack += amount; break;
|
||||
case CreatureLib::Library::Statistic::MagicalDefense: _magicalDefense += amount; break;
|
||||
case CreatureLib::Library::Statistic::Speed: _speed += amount; break;
|
||||
default: throw NotReachableException();
|
||||
}
|
||||
}
|
||||
inline void DecreaseStatBy(Statistic stat, T amount) {
|
||||
switch (stat) {
|
||||
case CreatureLib::Library::Statistic::Health: _health -= amount; break;
|
||||
case CreatureLib::Library::Statistic::PhysicalAttack: _physicalAttack -= amount; break;
|
||||
case CreatureLib::Library::Statistic::PhysicalDefense: _physicalDefense -= amount; break;
|
||||
case CreatureLib::Library::Statistic::MagicalAttack: _magicalAttack -= amount; break;
|
||||
case CreatureLib::Library::Statistic::MagicalDefense: _magicalDefense -= amount; break;
|
||||
case CreatureLib::Library::Statistic::Speed: _speed -= amount; break;
|
||||
default: throw NotReachableException();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_STATISTICSET_HPP
|
||||
Reference in New Issue
Block a user