Implements GetRandomAttack method on LearnableAttacks.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
c6ce5fe8a7
commit
ad9cbf0670
|
@ -1,8 +0,0 @@
|
|||
#include "CreatureMoves.hpp"
|
||||
#include <utility>
|
||||
|
||||
CreatureLib::Library::LevelMove::LevelMove(uint8_t level, std::string name) : _level(level), _name(std::move(name)) {}
|
||||
|
||||
uint8_t CreatureLib::Library::LevelMove::GetLevel() const { return this->_level; }
|
||||
|
||||
std::string CreatureLib::Library::LevelMove::GetName() const { return this->_name; }
|
|
@ -1,33 +0,0 @@
|
|||
#ifndef CREATURELIB_CREATUREMOVES_HPP
|
||||
#define CREATURELIB_CREATUREMOVES_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
class LevelMove {
|
||||
private:
|
||||
uint8_t _level;
|
||||
std::string _name;
|
||||
|
||||
public:
|
||||
LevelMove(uint8_t level, std::string name);
|
||||
[[nodiscard]] inline uint8_t GetLevel() const;
|
||||
[[nodiscard]] inline std::string GetName() const;
|
||||
};
|
||||
|
||||
class CreatureMoves {
|
||||
private:
|
||||
std::vector<LevelMove> _levelMoves;
|
||||
std::vector<std::string> _eggMoves;
|
||||
std::vector<std::string> _machineMoves;
|
||||
std::vector<std::string> _tutorMoves;
|
||||
std::vector<std::string> _variantDependentMoves;
|
||||
|
||||
public:
|
||||
// TODO: Public API funcs
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_CREATUREMOVES_HPP
|
|
@ -4,6 +4,7 @@
|
|||
#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"
|
||||
|
||||
|
@ -12,19 +13,29 @@ using namespace Arbutils::Collections;
|
|||
namespace CreatureLib::Library {
|
||||
class LearnableAttacks {
|
||||
Dictionary<uint8_t, List<const AttackData*>> _learnedByLevel;
|
||||
std::unordered_set<const AttackData*> _distinctAttacks;
|
||||
|
||||
public:
|
||||
LearnableAttacks(size_t levelAttackCapacity)
|
||||
explicit LearnableAttacks(size_t levelAttackCapacity)
|
||||
: _learnedByLevel(Dictionary<uint8_t, List<const AttackData*>>(levelAttackCapacity)) {
|
||||
for (auto kv : _learnedByLevel) {
|
||||
for (auto attack : kv.second)
|
||||
for (auto attack : kv.second) {
|
||||
AssertNotNull(attack)
|
||||
_distinctAttacks.insert(attack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~LearnableAttacks() = default;
|
||||
|
||||
void AddLevelMove(uint8_t level, const AttackData* attack);
|
||||
|
||||
const List<const AttackData*>& GetAttacksForLevel(uint8_t level) const;
|
||||
|
||||
virtual const AttackData* GetRandomAttack(Arbutils::Random rand = Arbutils::Random()) {
|
||||
auto val = rand.Get(_distinctAttacks.size());
|
||||
return *std::next(_distinctAttacks.begin(), val);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include <memory>
|
||||
#include <string>
|
||||
#include "../StatisticSet.hpp"
|
||||
#include "CreatureMoves.hpp"
|
||||
#include "LearnableAttacks.hpp"
|
||||
#include "TalentIndex.hpp"
|
||||
using ConstString = Arbutils::CaseInsensitiveConstString;
|
||||
|
|
Loading…
Reference in New Issue