Adds templated functions for getting stats
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
24871b6b65
commit
df1fd007f1
|
@ -40,7 +40,7 @@ void TurnOrdering::OrderChoices(std::vector<std::shared_ptr<BaseTurnChoice>>& ve
|
||||||
attackChoice->SetPriority(priority);
|
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);
|
HOOK(ChangeSpeed, item, item.get(), &speed);
|
||||||
item->__SetSpeed(speed);
|
item->__SetSpeed(speed);
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,9 +91,9 @@ namespace CreatureLib::Battling {
|
||||||
}
|
}
|
||||||
|
|
||||||
// We modify the health of the creature by the change in its max health.
|
// 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();
|
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) {
|
if (_currentHealth < static_cast<u32>(INT32_MAX) && static_cast<i32>(_currentHealth) < -diffHealth) {
|
||||||
_currentHealth = 0;
|
_currentHealth = 0;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -84,7 +84,7 @@ namespace CreatureLib::Battling {
|
||||||
|
|
||||||
virtual void Initialize() {
|
virtual void Initialize() {
|
||||||
RecalculateFlatStats();
|
RecalculateFlatStats();
|
||||||
_currentHealth = GetBoostedStat(Library::Statistic::Health);
|
_currentHealth = GetMaxHealth();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const ArbUt::BorrowedPtr<const BattleLibrary>& GetLibrary() const noexcept { return _library; }
|
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);
|
bool ChangeStatBoost(Library::Statistic stat, i8 diffAmount, bool selfInflicted = false);
|
||||||
[[nodiscard]] inline u32 GetFlatStat(Library::Statistic stat) const { return _flatStats.GetStat(stat); }
|
[[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); }
|
[[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 u32 GetBaseStat(Library::Statistic stat) const { return _variant->GetStatistic(stat); }
|
||||||
[[nodiscard]] inline i8 GetStatBoost(Library::Statistic stat) const { return _statBoost.GetStat(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 RecalculateFlatStats();
|
||||||
void RecalculateBoostedStats();
|
void RecalculateBoostedStats();
|
||||||
void RecalculateFlatStat(Library::Statistic);
|
void RecalculateFlatStat(Library::Statistic);
|
||||||
|
|
|
@ -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) {
|
inline void SetStat(Statistic stat, T value) {
|
||||||
if (value < Min)
|
if (value < Min)
|
||||||
value = Min;
|
value = Min;
|
||||||
|
|
|
@ -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.
|
/// @brief Sets a specific stat to a value.
|
||||||
/// @param stat The stat to set.
|
/// @param stat The stat to set.
|
||||||
/// @param value The value to set the stat at.
|
/// @param value The value to set the stat at.
|
||||||
|
|
Loading…
Reference in New Issue