Adds templated functions for getting stats
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2022-05-28 12:09:11 +02:00
parent 24871b6b65
commit df1fd007f1
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
5 changed files with 45 additions and 4 deletions

View File

@ -40,7 +40,7 @@ void TurnOrdering::OrderChoices(std::vector<std::shared_ptr<BaseTurnChoice>>& ve
attackChoice->SetPriority(priority);
}
auto speed = item->GetUser()->GetBoostedStat(Library::Statistic::Speed);
auto speed = item->GetUser()->GetBoostedStat<Library::Statistic::Speed>();
HOOK(ChangeSpeed, item, item.get(), &speed);
item->__SetSpeed(speed);
}

View File

@ -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<u32>(INT32_MAX) && static_cast<i32>(_currentHealth) < -diffHealth) {
_currentHealth = 0;
} else {

View File

@ -84,7 +84,7 @@ namespace CreatureLib::Battling {
virtual void Initialize() {
RecalculateFlatStats();
_currentHealth = GetBoostedStat(Library::Statistic::Health);
_currentHealth = GetMaxHealth();
}
inline const ArbUt::BorrowedPtr<const BattleLibrary>& 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 <Library::Statistic stat> [[nodiscard]] inline u32 GetFlatStat() const {
return _flatStats.GetStat<stat>();
}
[[nodiscard]] inline u32 GetBoostedStat(Library::Statistic stat) const { return _boostedStats.GetStat(stat); }
template <Library::Statistic stat> [[nodiscard]] inline u32 GetBoostedStat() const {
return _boostedStats.GetStat<stat>();
}
[[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 <Library::Statistic stat> [[nodiscard]] inline u32 GetStatBoost() const {
return _statBoost.GetStat<stat>();
}
void RecalculateFlatStats();
void RecalculateBoostedStats();
void RecalculateFlatStat(Library::Statistic);

View File

@ -42,6 +42,22 @@ namespace CreatureLib::Library {
}
}
template <Statistic stat> [[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;

View File

@ -69,6 +69,22 @@ namespace CreatureLib::Library {
}
}
template <Statistic stat> [[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.