47 lines
1.5 KiB
C++
47 lines
1.5 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/Random.hpp>
|
|
#include <unordered_map>
|
|
#include "../Attacks/AttackData.hpp"
|
|
|
|
namespace CreatureLib::Library {
|
|
class LearnableAttacks {
|
|
protected:
|
|
ArbUt::Dictionary<uint8_t, ArbUt::List<const AttackData*>> _learnedByLevel;
|
|
std::unordered_set<const AttackData*> _distinctAttacks;
|
|
|
|
public:
|
|
explicit LearnableAttacks(size_t levelAttackCapacity)
|
|
: _learnedByLevel(ArbUt::Dictionary<uint8_t, ArbUt::List<const AttackData*>>(levelAttackCapacity)) {
|
|
for (auto kv : _learnedByLevel) {
|
|
for (auto attack : kv.second) {
|
|
AssertNotNull(attack)
|
|
_distinctAttacks.insert(attack);
|
|
}
|
|
}
|
|
}
|
|
|
|
virtual ~LearnableAttacks() = default;
|
|
|
|
void AddLevelAttack(uint8_t level, const AttackData* attack);
|
|
|
|
const ArbUt::List<const AttackData*>& GetAttacksForLevel(uint8_t level) const;
|
|
|
|
virtual const AttackData* GetRandomAttack(ArbUt::Random& rand) const {
|
|
if (_distinctAttacks.empty()) {
|
|
return nullptr;
|
|
}
|
|
auto val = rand.Get(_distinctAttacks.size());
|
|
auto it = _distinctAttacks.begin();
|
|
std::advance(it, val);
|
|
return *it;
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif // CREATURELIB_LEARNABLEATTACKS_HPP
|