CreatureLib/src/Library/CreatureData/SpeciesVariant.hpp

85 lines
3.9 KiB
C++

#ifndef CREATURELIB_SPECIESVARIANT_HPP
#define CREATURELIB_SPECIESVARIANT_HPP
#include "../StatisticSet.hpp"
#include "LearnableAttacks.hpp"
#include "TalentIndex.hpp"
namespace CreatureLib::Library {
/*!
\brief A single species can have more than one variant. This class holds the data for those variants.
*/
class SpeciesVariant {
protected:
ArbUt::StringView _name;
float _height;
float _weight;
uint32_t _baseExperience;
private:
ArbUt::List<uint8_t> _types;
Library::StatisticSet<uint16_t> _baseStatistics;
ArbUt::List<ArbUt::StringView> _talents;
ArbUt::List<ArbUt::StringView> _secretTalents;
std::unique_ptr<const LearnableAttacks> _attacks;
std::unordered_set<uint32_t> _flags;
public:
SpeciesVariant(const ArbUt::StringView& name, float height, float weight, uint32_t baseExperience,
const ArbUt::List<uint8_t>& types, Library::StatisticSet<uint16_t> baseStats,
const ArbUt::List<ArbUt::StringView>& talents,
const ArbUt::List<ArbUt::StringView>& secretTalents, const LearnableAttacks* attacks,
std::unordered_set<uint32_t> flags = {})
: _name(name), _height(height), _weight(weight), _baseExperience(baseExperience), _types((types)),
_baseStatistics(baseStats), _talents(talents), _secretTalents(secretTalents), _attacks(attacks),
_flags(flags){};
virtual ~SpeciesVariant() = default;
inline const ArbUt::StringView& GetName() const { return _name; }
inline float GetHeight() const { return _height; }
inline float GetWeight() const { return _weight; }
inline uint32_t GetBaseExperience() const { return _baseExperience; }
[[nodiscard]] inline size_t GetTypeCount() const { return _types.Count(); }
[[nodiscard]] inline uint8_t GetType(size_t index) const { return _types[index]; }
[[nodiscard]] inline const ArbUt::List<uint8_t>& GetTypes() const { return _types; }
[[nodiscard]] inline uint16_t GetStatistic(Library::Statistic stat) const {
return _baseStatistics.GetStat(stat);
}
[[nodiscard]] inline size_t GetTalentCount() const noexcept { return _talents.Count(); }
[[nodiscard]] inline size_t GetSecretTalentCount() const noexcept { return _secretTalents.Count(); }
[[nodiscard]] const ArbUt::StringView& GetTalent(const TalentIndex& index) const {
if (index.IsSecret() && _secretTalents.Count() > 0) {
auto i = index.GetIndex();
if (i > _secretTalents.Count())
i = _secretTalents.Count();
return _secretTalents.At(i);
}
auto i = index.GetIndex();
if (i > _talents.Count())
i = _talents.Count();
return _talents.At(i);
}
[[nodiscard]] const TalentIndex GetTalentIndex(const ArbUt::StringView& talent) const;
[[nodiscard]] inline ArbUt::BorrowedPtr<const CreatureLib::Library::LearnableAttacks>
GetLearnableAttacks() const {
return _attacks;
}
[[nodiscard]] inline TalentIndex GetRandomTalent(ArbUt::Random& rand) const noexcept {
return TalentIndex(false, rand.Get(_talents.Count()));
}
[[nodiscard]] inline const ArbUt::List<ArbUt::StringView>& GetTalents() const { return _talents; }
[[nodiscard]] inline const ArbUt::List<ArbUt::StringView>& GetSecretTalents() const { return _secretTalents; }
inline bool HasFlag(const ArbUt::StringView& key) const noexcept {
return this->_flags.find(key) != this->_flags.end();
}
inline bool HasFlag(uint32_t keyHash) const noexcept {
return this->_flags.find(keyHash) != this->_flags.end();
}
};
}
#endif // CREATURELIB_SPECIESVARIANT_HPP