Added Creature C Interface, misc fixes and changes for Creature.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -34,7 +34,7 @@ Creature* CreateCreature::Create() {
|
||||
auto rand = Arbutils::Random();
|
||||
auto species = this->_library->GetSpeciesLibrary()->Get(this->_species);
|
||||
auto variant = species->GetVariant(this->_variant);
|
||||
TalentIndex talent;
|
||||
Library::TalentIndex talent;
|
||||
if (this->_talent.Empty()) {
|
||||
talent = variant->GetRandomTalent(&rand);
|
||||
} else {
|
||||
@@ -54,8 +54,7 @@ Creature* CreateCreature::Create() {
|
||||
throw CreatureException("Invalid held item.");
|
||||
}
|
||||
}
|
||||
// FIXME: implement experience
|
||||
auto experience = 0;
|
||||
auto experience = _library->GetGrowthRateLibrary()->CalculateExperience(species->GetGrowthRate(), _level);
|
||||
|
||||
auto attacks = std::vector<LearnedAttack*>(_attacks.size());
|
||||
for (size_t i = 0; i < attacks.size(); i++) {
|
||||
|
||||
@@ -9,7 +9,8 @@ using namespace CreatureLib;
|
||||
Battling::Creature::Creature(const BattleLibrary* library, const Library::CreatureSpecies* species,
|
||||
const Library::SpeciesVariant* variant, uint8_t level, uint32_t experience, uint32_t uid,
|
||||
Library::Gender gender, uint8_t coloring, const Library::Item* heldItem,
|
||||
std::string nickname, const TalentIndex& talent, std::vector<LearnedAttack*> attacks)
|
||||
std::string nickname, const Library::TalentIndex& talent,
|
||||
std::vector<LearnedAttack*> attacks)
|
||||
: _library(library), _species(species), _variant(variant), _level(level), _experience(experience),
|
||||
_uniqueIdentifier(uid), _gender(gender), _coloring(coloring), _heldItem(heldItem), _nickname(std::move(nickname)),
|
||||
_talentIndex(talent), _hasOverridenTalent(false), _attacks(std::move(attacks)) {
|
||||
@@ -20,8 +21,9 @@ Battling::Creature::Creature(const BattleLibrary* library, const Library::Creatu
|
||||
}
|
||||
}
|
||||
|
||||
void Battling::Creature::ChangeLevel(int8_t amount) {
|
||||
void Battling::Creature::ChangeLevelBy(int8_t amount) {
|
||||
this->_level += amount;
|
||||
_experience = _library->GetGrowthRateLibrary()->CalculateExperience(_species->GetGrowthRate(), _level);
|
||||
RecalculateFlatStats();
|
||||
}
|
||||
|
||||
@@ -176,13 +178,21 @@ const Library::SpeciesVariant* Battling::Creature::GetDisplayVariant() const {
|
||||
variant = _variant;
|
||||
return variant;
|
||||
}
|
||||
void Battling::Creature::SetHeldItem(const Arbutils::CaseInsensitiveConstString& itemName) {
|
||||
void Battling::Creature::SetHeldItem(const ConstString& itemName) {
|
||||
const Library::Item* item;
|
||||
if (!_library->GetItemLibrary()->TryGet(itemName, item)) {
|
||||
throw CreatureException("Item not found.");
|
||||
}
|
||||
_heldItem = item;
|
||||
}
|
||||
void Battling::Creature::SetHeldItem(uint32_t itemNameHash) {
|
||||
const Library::Item* item;
|
||||
if (!_library->GetItemLibrary()->TryGet(itemNameHash, item)) {
|
||||
throw CreatureException("Item not found.");
|
||||
}
|
||||
_heldItem = item;
|
||||
}
|
||||
|
||||
void Battling::Creature::AddVolatileScript(const ConstString& name) {
|
||||
auto script = _volatile.Get(name);
|
||||
if (script != nullptr) {
|
||||
@@ -196,4 +206,4 @@ void Battling::Creature::AddVolatileScript(const ConstString& name) {
|
||||
void Battling::Creature::AddVolatileScript(Script* script) { _volatile.Add(script); }
|
||||
void Battling::Creature::RemoveVolatileScript(const ConstString& name) { _volatile.Remove(name); }
|
||||
void Battling::Creature::RemoveVolatileScript(Battling::Script* script) { _volatile.Remove(script->GetName()); }
|
||||
void Battling::Creature::HasVolatileScript(const ConstString& name) const { _volatile.Has(name); }
|
||||
bool Battling::Creature::HasVolatileScript(const ConstString& name) const { return _volatile.Has(name); }
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace CreatureLib::Battling {
|
||||
bool _onBattleField = false;
|
||||
|
||||
std::string _nickname = "";
|
||||
TalentIndex _talentIndex;
|
||||
CreatureLib::Library::TalentIndex _talentIndex;
|
||||
Script* _activeTalent = nullptr;
|
||||
|
||||
bool _hasOverridenTalent;
|
||||
@@ -61,7 +61,7 @@ namespace CreatureLib::Battling {
|
||||
Creature(const BattleLibrary* library, const Library::CreatureSpecies* species,
|
||||
const Library::SpeciesVariant* variant, uint8_t level, uint32_t experience, uint32_t uid,
|
||||
Library::Gender gender, uint8_t coloring, const Library::Item* heldItem, std::string nickname,
|
||||
const TalentIndex& talent, std::vector<LearnedAttack*> attacks);
|
||||
const Library::TalentIndex& talent, std::vector<LearnedAttack*> attacks);
|
||||
|
||||
virtual ~Creature() {
|
||||
for (auto attack : _attacks) {
|
||||
@@ -82,11 +82,15 @@ namespace CreatureLib::Battling {
|
||||
inline uint32_t GetExperience() const { return _experience; }
|
||||
inline Library::Gender GetGender() const { return _gender; }
|
||||
inline uint8_t GetColoring() const { return _coloring; }
|
||||
inline const bool HasHeldItem(const std::string& name) const {
|
||||
inline bool HasHeldItem(const ConstString& name) const {
|
||||
return _heldItem != nullptr && _heldItem->GetName() == name;
|
||||
}
|
||||
inline bool HasHeldItem(uint32_t nameHash) const {
|
||||
return _heldItem != nullptr && _heldItem->GetName() == nameHash;
|
||||
}
|
||||
inline const Library::Item* GetHeldItem() const { return _heldItem; }
|
||||
void SetHeldItem(const Arbutils::CaseInsensitiveConstString& itemName);
|
||||
void SetHeldItem(const ConstString& itemName);
|
||||
void SetHeldItem(uint32_t itemNameHash);
|
||||
inline void SetHeldItem(const Library::Item* item) { _heldItem = item; };
|
||||
|
||||
inline uint32_t GetCurrentHealth() const { return _currentHealth; }
|
||||
@@ -105,7 +109,7 @@ namespace CreatureLib::Battling {
|
||||
[[nodiscard]] bool HasType(uint8_t type) const;
|
||||
|
||||
uint32_t GetMaxHealth() const { return _boostedStats.GetHealth(); }
|
||||
void ChangeLevel(int8_t amount);
|
||||
void ChangeLevelBy(int8_t amount);
|
||||
void Damage(uint32_t damage, DamageSource source);
|
||||
void Heal(uint32_t amount);
|
||||
void OverrideActiveTalent(const ConstString& talent);
|
||||
@@ -120,15 +124,15 @@ namespace CreatureLib::Battling {
|
||||
void AddVolatileScript(Script* script);
|
||||
void RemoveVolatileScript(const ConstString& name);
|
||||
void RemoveVolatileScript(Script* script);
|
||||
void HasVolatileScript(const ConstString& name) const;
|
||||
bool HasVolatileScript(const ConstString& name) const;
|
||||
|
||||
std::vector<LearnedAttack*>& GetAttacks() { return _attacks; }
|
||||
|
||||
const Library::CreatureSpecies* GetDisplaySpecies() const;
|
||||
const Library::SpeciesVariant* GetDisplayVariant() const;
|
||||
|
||||
const void SetDisplaySpecies(Library::CreatureSpecies* species) { _displaySpecies = species; }
|
||||
const void SetDisplayVariant(Library::SpeciesVariant* variant) { _displayVariant = variant; };
|
||||
const void SetDisplaySpecies(const Library::CreatureSpecies* species) { _displaySpecies = species; }
|
||||
const void SetDisplayVariant(const Library::SpeciesVariant* variant) { _displayVariant = variant; };
|
||||
|
||||
// region Stat APIs
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@ uint32_t CreatureLib::Library::SpeciesVariant::GetStatistic(CreatureLib::Core::S
|
||||
return _baseStatistics.GetStat(stat);
|
||||
}
|
||||
|
||||
const TalentIndex CreatureLib::Library::SpeciesVariant::GetTalentIndex(const ConstString& talent) const {
|
||||
const CreatureLib::Library::TalentIndex
|
||||
CreatureLib::Library::SpeciesVariant::GetTalentIndex(const ConstString& talent) const {
|
||||
for (size_t i = 0; i < _talents.size(); i++) {
|
||||
if (_talents.at(i) == talent) {
|
||||
return TalentIndex(false, i);
|
||||
@@ -26,7 +27,7 @@ const TalentIndex CreatureLib::Library::SpeciesVariant::GetTalentIndex(const Con
|
||||
throw CreatureException("The given talent is not a valid talent for this creature.");
|
||||
}
|
||||
|
||||
TalentIndex CreatureLib::Library::SpeciesVariant::GetRandomTalent(Arbutils::Random* rand) const {
|
||||
CreatureLib::Library::TalentIndex CreatureLib::Library::SpeciesVariant::GetRandomTalent(Arbutils::Random* rand) const {
|
||||
return TalentIndex(false, rand->Get(_talents.size()));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,15 +2,17 @@
|
||||
#define CREATURELIB_TALENTINDEX_HPP
|
||||
|
||||
#include <cstdint>
|
||||
class TalentIndex {
|
||||
bool _secret;
|
||||
uint8_t _index;
|
||||
namespace CreatureLib::Library {
|
||||
class TalentIndex {
|
||||
bool _secret;
|
||||
uint8_t _index;
|
||||
|
||||
public:
|
||||
TalentIndex() : _secret(false), _index(0){};
|
||||
TalentIndex(bool secret, uint8_t index) : _secret(secret), _index(index) {}
|
||||
constexpr inline bool IsSecret() const { return _secret; }
|
||||
constexpr inline bool GetIndex() const { return _index; }
|
||||
};
|
||||
public:
|
||||
TalentIndex() : _secret(false), _index(0){};
|
||||
TalentIndex(bool secret, uint8_t index) : _secret(secret), _index(index) {}
|
||||
constexpr inline bool IsSecret() const { return _secret; }
|
||||
constexpr inline bool GetIndex() const { return _index; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_TALENTINDEX_HPP
|
||||
|
||||
Reference in New Issue
Block a user