82 lines
4.2 KiB
C++
82 lines
4.2 KiB
C++
|
#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
|