diff --git a/src/Battling/Flow/TurnOrdering.cpp b/src/Battling/Flow/TurnOrdering.cpp index 9a30993..1ab015b 100644 --- a/src/Battling/Flow/TurnOrdering.cpp +++ b/src/Battling/Flow/TurnOrdering.cpp @@ -40,7 +40,7 @@ void TurnOrdering::OrderChoices(std::vector>& ve attackChoice->SetPriority(priority); } - auto speed = item->GetUser()->GetBoostedStat(Library::Statistic::Speed); + auto speed = item->GetUser()->GetBoostedStat(); HOOK(ChangeSpeed, item, item.get(), &speed); item->__SetSpeed(speed); } diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index c6eab66..59f1e14 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -91,9 +91,9 @@ namespace CreatureLib::Battling { } // We modify the health of the creature by the change in its max health. - auto prevHealth = GetBoostedStat(CreatureLib::Library::Statistic::Health); + auto prevHealth = GetMaxHealth(); RecalculateFlatStats(); - i32 diffHealth = GetBoostedStat(CreatureLib::Library::Statistic::Health) - prevHealth; + i32 diffHealth = GetMaxHealth() - prevHealth; if (_currentHealth < static_cast(INT32_MAX) && static_cast(_currentHealth) < -diffHealth) { _currentHealth = 0; } else { diff --git a/src/Battling/Models/Creature.hpp b/src/Battling/Models/Creature.hpp index 4c0963f..03403b7 100644 --- a/src/Battling/Models/Creature.hpp +++ b/src/Battling/Models/Creature.hpp @@ -84,7 +84,7 @@ namespace CreatureLib::Battling { virtual void Initialize() { RecalculateFlatStats(); - _currentHealth = GetBoostedStat(Library::Statistic::Health); + _currentHealth = GetMaxHealth(); } inline const ArbUt::BorrowedPtr& GetLibrary() const noexcept { return _library; } @@ -232,9 +232,18 @@ namespace CreatureLib::Battling { bool ChangeStatBoost(Library::Statistic stat, i8 diffAmount, bool selfInflicted = false); [[nodiscard]] inline u32 GetFlatStat(Library::Statistic stat) const { return _flatStats.GetStat(stat); } + template [[nodiscard]] inline u32 GetFlatStat() const { + return _flatStats.GetStat(); + } [[nodiscard]] inline u32 GetBoostedStat(Library::Statistic stat) const { return _boostedStats.GetStat(stat); } + template [[nodiscard]] inline u32 GetBoostedStat() const { + return _boostedStats.GetStat(); + } [[nodiscard]] inline u32 GetBaseStat(Library::Statistic stat) const { return _variant->GetStatistic(stat); } [[nodiscard]] inline i8 GetStatBoost(Library::Statistic stat) const { return _statBoost.GetStat(stat); } + template [[nodiscard]] inline u32 GetStatBoost() const { + return _statBoost.GetStat(); + } void RecalculateFlatStats(); void RecalculateBoostedStats(); void RecalculateFlatStat(Library::Statistic); diff --git a/src/Library/ClampedStatisticSet.hpp b/src/Library/ClampedStatisticSet.hpp index d058f88..8466601 100644 --- a/src/Library/ClampedStatisticSet.hpp +++ b/src/Library/ClampedStatisticSet.hpp @@ -42,6 +42,22 @@ namespace CreatureLib::Library { } } + template [[nodiscard]] inline T GetStat() const { + if constexpr (stat == CreatureLib::Library::Statistic::Health) { + return _health; + } else if constexpr (stat == CreatureLib::Library::Statistic::PhysicalAttack) { + return _physicalAttack; + } else if constexpr (stat == CreatureLib::Library::Statistic::PhysicalDefense) { + return _physicalDefense; + } else if constexpr (stat == CreatureLib::Library::Statistic::MagicalAttack) { + return _magicalAttack; + } else if constexpr (stat == CreatureLib::Library::Statistic::MagicalDefense) { + return _magicalDefense; + } else if constexpr (stat == CreatureLib::Library::Statistic::Speed) { + return _speed; + } + } + inline void SetStat(Statistic stat, T value) { if (value < Min) value = Min; diff --git a/src/Library/StatisticSet.hpp b/src/Library/StatisticSet.hpp index 1c42aa2..0703477 100644 --- a/src/Library/StatisticSet.hpp +++ b/src/Library/StatisticSet.hpp @@ -69,6 +69,22 @@ namespace CreatureLib::Library { } } + template [[nodiscard]] inline T GetStat() const { + if constexpr (stat == CreatureLib::Library::Statistic::Health) { + return _health; + } else if constexpr (stat == CreatureLib::Library::Statistic::PhysicalAttack) { + return _physicalAttack; + } else if constexpr (stat == CreatureLib::Library::Statistic::PhysicalDefense) { + return _physicalDefense; + } else if constexpr (stat == CreatureLib::Library::Statistic::MagicalAttack) { + return _magicalAttack; + } else if constexpr (stat == CreatureLib::Library::Statistic::MagicalDefense) { + return _magicalDefense; + } else if constexpr (stat == CreatureLib::Library::Statistic::Speed) { + return _speed; + } + } + /// @brief Sets a specific stat to a value. /// @param stat The stat to set. /// @param value The value to set the stat at.