CreatureLib/src/Battling/Models/Creature.hpp

172 lines
7.2 KiB
C++
Raw Normal View History

#ifndef CREATURELIB_BATTLECREATURE_HPP
#define CREATURELIB_BATTLECREATURE_HPP
#include <Arbutils/Collections/List.hpp>
#include <Arbutils/Memory/borrowed_ptr.hpp>
#include "../../Library/ClampedStatisticSet.hpp"
#include "../../Library/CreatureData/CreatureSpecies.hpp"
#include "../../Library/Items/Item.hpp"
2019-11-09 11:15:45 +00:00
#include "../ScriptHandling/ScriptAggregator.hpp"
#include "../ScriptHandling/ScriptSet.hpp"
2019-11-09 11:15:45 +00:00
#include "../ScriptHandling/ScriptSource.hpp"
#include "DamageSource.hpp"
#include "LearnedAttack.hpp"
using namespace Arbutils::Collections;
namespace CreatureLib::Battling {
// Forward declare battle class
class Battle;
class BattleSide;
class BattleLibrary;
class Creature : public ScriptSource {
protected:
const BattleLibrary* _library;
borrowed_ptr<const Library::CreatureSpecies> _species;
2020-05-26 12:35:18 +00:00
borrowed_ptr<const Library::SpeciesVariant> _variant;
borrowed_ptr<const Library::CreatureSpecies> _displaySpecies = nullptr;
2020-05-26 12:35:18 +00:00
borrowed_ptr<const Library::SpeciesVariant> _displayVariant = nullptr;
uint8_t _level;
uint32_t _experience;
uint32_t _uniqueIdentifier;
Library::Gender _gender;
uint8_t _coloring;
borrowed_ptr<const Library::Item> _heldItem;
uint32_t _currentHealth;
Library::ClampedStatisticSet<int8_t, -6, 6> _statBoost;
Library::StatisticSet<uint32_t> _flatStats;
Library::StatisticSet<uint32_t> _boostedStats;
Battle* _battle = nullptr;
BattleSide* _side = nullptr;
bool _onBattleField = false;
std::string _nickname = "";
CreatureLib::Library::TalentIndex _talentIndex;
2019-11-17 10:25:52 +00:00
Script* _activeTalent = nullptr;
bool _hasOverridenTalent;
ConstString _overridenTalentName = ""_cnc;
2019-12-14 11:40:50 +00:00
std::unordered_set<Creature*> _seenOpponents = {};
List<LearnedAttack*> _attacks;
bool _allowedExperienceGain;
Script* _status = nullptr;
ScriptSet _volatile = {};
2020-01-02 17:43:16 +00:00
private:
void OnFaint();
public:
Creature(const BattleLibrary* library, const borrowed_ptr<const Library::CreatureSpecies>& species,
2020-05-26 12:35:18 +00:00
const borrowed_ptr<const Library::SpeciesVariant>& variant, uint8_t level, uint32_t experience,
uint32_t uid, Library::Gender gender, uint8_t coloring,
const borrowed_ptr<const Library::Item> heldItem, std::string nickname,
const Library::TalentIndex& talent, const List<LearnedAttack*>& attacks,
bool allowedExperienceGain = true);
virtual ~Creature() {
for (auto attack : _attacks) {
delete attack;
}
delete _activeTalent;
delete _status;
};
2019-11-10 13:37:06 +00:00
virtual void Initialize() {
RecalculateFlatStats();
_currentHealth = GetBoostedStat(Library::Statistic::Health);
}
inline const borrowed_ptr<const Library::CreatureSpecies>& GetSpecies() const noexcept { return _species; }
2020-05-26 12:35:18 +00:00
inline const borrowed_ptr<const Library::SpeciesVariant>& GetVariant() const noexcept { return _variant; }
2020-03-22 12:42:26 +00:00
inline uint8_t GetLevel() const noexcept { return _level; }
inline uint32_t GetExperience() const noexcept { return _experience; }
inline Library::Gender GetGender() const noexcept { return _gender; }
inline uint8_t GetColoring() const noexcept { return _coloring; }
inline bool HasHeldItem(const ConstString& name) const noexcept {
return _heldItem != nullptr && _heldItem->GetName() == name;
}
2020-03-22 12:42:26 +00:00
inline bool HasHeldItem(uint32_t nameHash) const noexcept {
return _heldItem != nullptr && _heldItem->GetName() == nameHash;
}
inline const borrowed_ptr<const Library::Item>& GetHeldItem() const noexcept { return _heldItem; }
void SetHeldItem(const ConstString& itemName);
void SetHeldItem(uint32_t itemNameHash);
inline void SetHeldItem(const borrowed_ptr<const Library::Item>& item) noexcept { _heldItem = item; };
2020-03-22 12:42:26 +00:00
inline uint32_t GetCurrentHealth() const noexcept { return _currentHealth; }
void SetBattleData(Battle* battle, BattleSide* side);
Battle* GetBattle() const;
BattleSide* GetBattleSide() const;
2019-12-14 11:40:50 +00:00
void SetOnBattleField(bool value) { _onBattleField = value; }
bool IsOnBattleField() const { return _onBattleField; }
2020-03-22 12:42:26 +00:00
const std::string& GetNickname() const noexcept { return _nickname; }
const ConstString& GetActiveTalent() const;
2020-03-22 12:42:26 +00:00
[[nodiscard]] bool IsFainted() const noexcept;
[[nodiscard]] const List<uint8_t>& GetTypes() const noexcept;
2020-03-22 12:42:26 +00:00
[[nodiscard]] bool HasType(uint8_t type) const noexcept;
2019-11-02 12:57:43 +00:00
2020-03-22 12:42:26 +00:00
uint32_t GetMaxHealth() const noexcept { return _boostedStats.GetHealth(); }
void ChangeLevelBy(int8_t amount);
void Damage(uint32_t damage, DamageSource source);
void Heal(uint32_t amount, bool canRevive = false);
void OverrideActiveTalent(const ConstString& talent);
void AddExperience(uint32_t amount);
2019-12-14 11:40:50 +00:00
void MarkOpponentAsSeen(Creature* creature) { _seenOpponents.insert(creature); }
const std::unordered_set<Creature*>& GetSeenOpponents() const { return _seenOpponents; }
size_t ScriptCount() const override;
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override;
void ClearVolatileScripts();
void AddVolatileScript(const ConstString& name);
void AddVolatileScript(Script* script);
void RemoveVolatileScript(const ConstString& name);
void RemoveVolatileScript(Script* script);
bool HasVolatileScript(const ConstString& name) const;
const List<LearnedAttack*>& GetAttacks() noexcept { return _attacks; }
borrowed_ptr<const Library::CreatureSpecies> GetDisplaySpecies() const noexcept;
2020-05-26 12:35:18 +00:00
borrowed_ptr<const Library::SpeciesVariant> GetDisplayVariant() const noexcept;
void SetDisplaySpecies(const borrowed_ptr<const Library::CreatureSpecies>& species) noexcept {
2020-05-24 18:57:22 +00:00
_displaySpecies = species;
}
void SetDisplayVariant(const Library::SpeciesVariant* variant) noexcept { _displayVariant = variant; };
inline bool AllowedExperienceGain() const noexcept { return _allowedExperienceGain; }
inline void SetAllowedExperienceGain(bool allowed) noexcept { _allowedExperienceGain = allowed; }
// region Stat APIs
bool ChangeStatBoost(Library::Statistic stat, int8_t diffAmount);
[[nodiscard]] inline uint32_t GetFlatStat(Library::Statistic stat) const { return _flatStats.GetStat(stat); }
[[nodiscard]] inline uint32_t GetBoostedStat(Library::Statistic stat) const {
return _boostedStats.GetStat(stat);
}
[[nodiscard]] inline uint32_t GetBaseStat(Library::Statistic stat) const {
return _variant->GetStatistic(stat);
}
[[nodiscard]] inline int8_t GetStatBoost(Library::Statistic stat) const { return _statBoost.GetStat(stat); }
void RecalculateFlatStats();
void RecalculateBoostedStats();
void RecalculateFlatStat(Library::Statistic);
void RecalculateBoostedStat(Library::Statistic);
// endregion
};
}
#endif // CREATURELIB_CREATURE_HPP