diff --git a/src/Library/CreatureData/LearnableAttacks.cpp b/src/Library/CreatureData/LearnableAttacks.cpp index effce02..819fe3e 100644 --- a/src/Library/CreatureData/LearnableAttacks.cpp +++ b/src/Library/CreatureData/LearnableAttacks.cpp @@ -3,13 +3,13 @@ namespace CreatureLib::Library { struct LearnableAttacks::impl { private: - ArbUt::Dictionary>> _learnedByLevel; + ArbUt::Dictionary>> _learnedByLevel; ArbUt::List> _distinctLevelAttacks; public: - explicit impl(size_t levelAttackCapacity) - : _learnedByLevel( - ArbUt::Dictionary>>(levelAttackCapacity)) {} + explicit impl(level_int_t levelAttackCapacity) + : _learnedByLevel(ArbUt::Dictionary>>( + levelAttackCapacity)) {} ~impl() = default; @@ -24,8 +24,8 @@ namespace CreatureLib::Library { } } - inline bool HasAttacksForLevel(uint8_t level) const noexcept { return _learnedByLevel.Has(level); } - inline const ArbUt::List>& GetAttacksForLevel(uint8_t level) const { + inline bool HasAttacksForLevel(level_int_t level) const noexcept { return _learnedByLevel.Has(level); } + inline const ArbUt::List>& GetAttacksForLevel(level_int_t level) const { if (!_learnedByLevel.Has(level)) { THROW("No attacks found for level " << (uint32_t)level << "."); } @@ -47,14 +47,17 @@ namespace CreatureLib::Library { } }; - LearnableAttacks::LearnableAttacks(size_t levelAttackCapacity) : _impl(new impl(levelAttackCapacity)) {} + LearnableAttacks::LearnableAttacks(level_int_t levelAttackCapacity) : _impl(new impl(levelAttackCapacity)) {} LearnableAttacks::~LearnableAttacks() = default; void LearnableAttacks::AddLevelAttack(level_int_t level, ArbUt::BorrowedPtr attack) { _impl->AddLevelAttack(level, attack); } - bool LearnableAttacks::HasAttacksForLevel(uint8_t level) const noexcept { return _impl->HasAttacksForLevel(level); } - const ArbUt::List>& LearnableAttacks::GetAttacksForLevel(uint8_t level) const { + bool LearnableAttacks::HasAttacksForLevel(level_int_t level) const noexcept { + return _impl->HasAttacksForLevel(level); + } + const ArbUt::List>& + LearnableAttacks::GetAttacksForLevel(level_int_t level) const { return _impl->GetAttacksForLevel(level); } const ArbUt::List>& diff --git a/src/Library/CreatureData/LearnableAttacks.hpp b/src/Library/CreatureData/LearnableAttacks.hpp index 7c9a418..82adfed 100644 --- a/src/Library/CreatureData/LearnableAttacks.hpp +++ b/src/Library/CreatureData/LearnableAttacks.hpp @@ -5,19 +5,37 @@ #include "../Attacks/AttackData.hpp" namespace CreatureLib::Library { + /// @brief Data class for holding the different attacks a creature can learn. class LearnableAttacks { private: struct impl; std::unique_ptr _impl; public: - explicit LearnableAttacks(size_t levelAttackCapacity); + /// @brief Initialise the class using the maximum level a creature can reach. + /// @param levelAttackCapacity The maximum level a creature can reach + explicit LearnableAttacks(level_int_t levelAttackCapacity); virtual ~LearnableAttacks(); + /// @brief Add an attack that can be learned at a certain level. + /// @param level The level the attack can be learned at. + /// @param attack A pointer to the attack data that can be learned/ void AddLevelAttack(level_int_t level, ArbUt::BorrowedPtr attack); - bool HasAttacksForLevel(uint8_t level) const noexcept; - const ArbUt::List>& GetAttacksForLevel(uint8_t level) const; + /// @brief Returns whether or not a specific level has learnable attacks. + /// @param level The level to check for. + /// @return Whether or not a specific level has learnable attacks. + bool HasAttacksForLevel(level_int_t level) const noexcept; + /// @brief Returns a list of the attacks that can be learned at a specific level. + /// @param level The level to get the attacks from. + /// @return A list of the attacks that can be learned at a specific level. + /// @warning Note that this will throw if the level has no learnable attacks. Use HasAttacksForLevel first. + const ArbUt::List>& GetAttacksForLevel(level_int_t level) const; + /// @brief Returns a list of distinct attacks that can be learned through levelling up. + /// @return A list of distinct attacks that can be learned through levelling up. const ArbUt::List>& GetDistinctLevelAttacks() const noexcept; + /// @brief Returns a random attack that can be learned. + /// @param rand A random number generator. + /// @return A random attack that can be learned. virtual ArbUt::BorrowedPtr GetRandomAttack(ArbUt::Random& rand) const; }; }