53 lines
2.0 KiB
C++
53 lines
2.0 KiB
C++
#ifndef CREATURELIB_LEARNABLEATTACKS_HPP
|
|
#define CREATURELIB_LEARNABLEATTACKS_HPP
|
|
|
|
#include <Arbutils/Assert.hpp>
|
|
#include <Arbutils/Collections/Dictionary.hpp>
|
|
#include <Arbutils/Collections/List.hpp>
|
|
#include <Arbutils/Memory/BorrowedPtr.hpp>
|
|
#include <Arbutils/Random.hpp>
|
|
#include <unordered_map>
|
|
#include "../../Defines.hpp"
|
|
#include "../Attacks/AttackData.hpp"
|
|
|
|
namespace CreatureLib::Library {
|
|
class LearnableAttacks {
|
|
protected:
|
|
ArbUt::Dictionary<uint8_t, ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>> _learnedByLevel;
|
|
ArbUt::List<ArbUt::BorrowedPtr<const AttackData>> _distinctLevelAttacks;
|
|
|
|
public:
|
|
explicit LearnableAttacks(size_t levelAttackCapacity)
|
|
: _learnedByLevel(
|
|
ArbUt::Dictionary<uint8_t, ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>>(levelAttackCapacity)) {}
|
|
|
|
virtual ~LearnableAttacks() = default;
|
|
|
|
void AddLevelAttack(level_int_t level, ArbUt::BorrowedPtr<const AttackData> attack);
|
|
|
|
inline bool HasAttacksForLevel(uint8_t level) const noexcept { return _learnedByLevel.Has(level); }
|
|
inline const ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>& GetAttacksForLevel(uint8_t level) const {
|
|
if (!_learnedByLevel.Has(level)) {
|
|
THROW("No attacks found for level " << (uint32_t)level << ".");
|
|
}
|
|
return _learnedByLevel.Get(level);
|
|
}
|
|
|
|
inline const ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>& GetDistinctLevelAttacks() const noexcept {
|
|
return _distinctLevelAttacks;
|
|
}
|
|
|
|
virtual ArbUt::BorrowedPtr<const AttackData> GetRandomAttack(ArbUt::Random& rand) const {
|
|
if (_distinctLevelAttacks.Count() == 0) {
|
|
return nullptr;
|
|
}
|
|
auto val = rand.Get(_distinctLevelAttacks.Count());
|
|
auto it = _distinctLevelAttacks.begin();
|
|
std::advance(it, val);
|
|
return *it;
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif // CREATURELIB_LEARNABLEATTACKS_HPP
|