#ifndef CREATURELIB_STATISTICSET_HPP #define CREATURELIB_STATISTICSET_HPP #include "Exceptions/CreatureException.hpp" #include "Statistic.hpp" namespace CreatureLib::Library { template concept StatisticSetType = std::is_integral::value; /// @brief A class to hold all the different stats a creature can have. /// @tparam T An integer type that defines the kind the different fields in the set can have. template class StatisticSet { protected: T _health; T _physicalAttack; T _physicalDefense; T _magicalAttack; T _magicalDefense; T _speed; public: /// @brief Initialises the set with its different values. /// @param health The amount of health given in the set. /// @param physicalAttack The amount of physical attack given in the set. /// @param physicalDefense The amount of physical defense given in the set. /// @param magicalAttack The amount of magical attack given in the set. /// @param magicalDefense The amount of magical attack given in the set. /// @param speed The amount of speed given in the set. StatisticSet(T health, T physicalAttack, T physicalDefense, T magicalAttack, T magicalDefense, T speed) noexcept : _health(health), _physicalAttack(physicalAttack), _physicalDefense(physicalDefense), _magicalAttack(magicalAttack), _magicalDefense(magicalDefense), _speed(speed) {} /// @brief Initialises the set with 0 as every value. StatisticSet() noexcept : _health(0), _physicalAttack(0), _physicalDefense(0), _magicalAttack(0), _magicalDefense(0), _speed(0) {} /// @brief Returns the health in the set. /// @return The health in the set. inline T GetHealth() const noexcept { return _health; } /// @brief Returns the Physical Attack in the set. /// @return The Physical Attack in the set. inline T GetPhysicalAttack() const noexcept { return _physicalAttack; } /// @brief Returns the Physical Defense in the set. /// @return The Physical Defense in the set. inline T GetPhysicalDefense() const noexcept { return _physicalDefense; } /// @brief Returns the Magical Attack in the set. /// @return The Magical Attack in the set. inline T GetMagicalAttack() const noexcept { return _magicalAttack; } /// @brief Returns the Magical Defense in the set. /// @return The Magical Defense in the set. inline T GetMagicalDefense() const noexcept { return _magicalDefense; } /// @brief Returns the Speed in the set. /// @return The Speed in the set. inline T GetSpeed() const noexcept { return _speed; } /// @brief Returns a stat given a Statistic enum. /// @param stat The desired stat. /// @return The value of the desired stat. [[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: NOT_REACHABLE; } } /// @brief Sets a specific stat to a value. /// @param stat The stat to set. /// @param value The value to set the stat at. 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: NOT_REACHABLE; } } /// @brief Increment a stat by a given amount. /// @param stat The stat to increment. /// @param amount The value to increment it by. 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: NOT_REACHABLE; } } /// @brief Decrement a stat by a given amount. /// @param stat The stat to decrement. /// @param amount The value to decrement it by. 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: NOT_REACHABLE; } } }; } #endif // CREATURELIB_STATISTICSET_HPP