#ifndef CREATURELIB_BATTLECREATURE_HPP #define CREATURELIB_BATTLECREATURE_HPP #include "../../Defines.hpp" #include "../../Library/ClampedStatisticSet.hpp" #include "../../Library/CreatureData/CreatureSpecies.hpp" #include "../../Library/Items/Item.hpp" #include "../ScriptHandling/ScriptAggregator.hpp" #include "../ScriptHandling/ScriptSet.hpp" #include "../ScriptHandling/ScriptSource.hpp" #include "DamageSource.hpp" #include "LearnedAttack.hpp" namespace CreatureLib::Battling { // Forward declare battle class class Battle; class BattleSide; class BattleLibrary; class Creature : public ScriptSource { protected: ArbUt::BorrowedPtr _library; ArbUt::BorrowedPtr _species; ArbUt::BorrowedPtr _variant; ArbUt::OptionalBorrowedPtr _displaySpecies = nullptr; ArbUt::OptionalBorrowedPtr _displayVariant = nullptr; level_int_t _level; uint32_t _experience; uint32_t _uniqueIdentifier; Library::Gender _gender; uint8_t _coloring; ArbUt::OptionalBorrowedPtr _heldItem; uint32_t _currentHealth = -1; Library::ClampedStatisticSet _statBoost; Library::StatisticSet _flatStats; Library::StatisticSet _boostedStats; ArbUt::OptionalBorrowedPtr _battle = nullptr; ArbUt::OptionalBorrowedPtr _side = nullptr; bool _onBattleField = false; std::string _nickname; CreatureLib::Library::TalentIndex _talentIndex; std::unique_ptr _activeTalent = nullptr; bool _hasOverridenTalent; ArbUt::StringView _overridenTalentName; std::unordered_set> _seenOpponents; ArbUt::OptionalUniquePtrList _attacks; bool _allowedExperienceGain; std::unique_ptr _status = nullptr; ScriptSet _volatile = {}; std::vector _types; private: void OnFaint(); public: Creature(const ArbUt::BorrowedPtr& library, const ArbUt::BorrowedPtr& species, const ArbUt::BorrowedPtr& variant, level_int_t level, uint32_t experience, uint32_t uid, Library::Gender gender, uint8_t coloring, ArbUt::OptionalBorrowedPtr heldItem, std::string nickname, const Library::TalentIndex& talent, const std::vector& attacks, bool allowedExperienceGain = true); virtual ~Creature() = default; virtual void Initialize() { RecalculateFlatStats(); _currentHealth = GetBoostedStat(Library::Statistic::Health); } inline const ArbUt::BorrowedPtr& GetLibrary() const noexcept { return _library; } inline const ArbUt::BorrowedPtr& GetSpecies() const noexcept { return _species; } inline const ArbUt::BorrowedPtr& GetVariant() const noexcept { return _variant; } virtual void ChangeSpecies(const ArbUt::BorrowedPtr& species, const ArbUt::BorrowedPtr& variant); virtual void ChangeVariant(const ArbUt::BorrowedPtr& variant); inline level_int_t GetLevel() const noexcept { return _level; } inline uint32_t GetExperience() const noexcept { return _experience; } inline uint32_t GetUniqueIdentifier() const noexcept { return _uniqueIdentifier; } inline Library::Gender GetGender() const noexcept { return _gender; } inline uint8_t GetColoring() const noexcept { return _coloring; } inline bool HasHeldItem(const ArbUt::BasicStringView& name) const noexcept { return _heldItem.HasValue() && _heldItem.GetValue()->GetName() == name; } inline bool HasHeldItem(uint32_t nameHash) const noexcept { return _heldItem.HasValue() && _heldItem.GetValue()->GetName() == nameHash; } inline const ArbUt::OptionalBorrowedPtr& GetHeldItem() const noexcept { return _heldItem; } void SetHeldItem(const ArbUt::BasicStringView& itemName); void SetHeldItem(uint32_t itemNameHash); inline void SetHeldItem(const ArbUt::BorrowedPtr& item) noexcept { _heldItem = item; }; inline uint32_t GetCurrentHealth() const noexcept { return _currentHealth; } void SetBattleData(const ArbUt::BorrowedPtr& battle, const ArbUt::BorrowedPtr& side); void ClearBattleData() noexcept; inline const ArbUt::OptionalBorrowedPtr& GetBattle() const { return _battle; } inline const ArbUt::OptionalBorrowedPtr& GetBattleSide() const { return _side; } inline void SetOnBattleField(bool value) { _onBattleField = value; } inline bool IsOnBattleField() const { return _onBattleField; } inline std::string_view GetNickname() const noexcept { return _nickname; } inline void SetNickname(std::string nickname) noexcept { _nickname = nickname; } const CreatureLib::Library::TalentIndex& GetRealTalent() const noexcept { return _talentIndex; } const ArbUt::StringView& GetActiveTalent() const; [[nodiscard]] bool IsFainted() const noexcept; [[nodiscard]] const std::vector& GetTypes() const noexcept; [[nodiscard]] bool HasType(uint8_t type) const noexcept; 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 RestoreAllAttackUses() noexcept; void OverrideActiveTalent(const ArbUt::StringView& talent); void AddExperience(uint32_t amount); void MarkOpponentAsSeen(ArbUt::BorrowedPtr creature) { _seenOpponents.insert(creature); } const std::unordered_set>& GetSeenOpponents() const { return _seenOpponents; } size_t ScriptCount() const override; void GetActiveScripts(ArbUt::List& scripts) override; void ClearVolatileScripts(); BattleScript* AddVolatileScript(const ArbUt::StringView& name); BattleScript* AddVolatileScript(BattleScript* script); void RemoveVolatileScript(const ArbUt::BasicStringView& name); void RemoveVolatileScript(BattleScript* script); bool HasVolatileScript(const ArbUt::BasicStringView& name) const; const ArbUt::OptionalUniquePtrList& GetAttacks() noexcept { return _attacks; } bool HasAttack(const ArbUt::StringView& name) { for (auto& a : _attacks) { if (a == nullptr) continue; if (a->GetAttack()->GetName() == name) return true; } return false; } ArbUt::OptionalBorrowedPtr GetDisplaySpecies() const noexcept; ArbUt::OptionalBorrowedPtr GetDisplayVariant() const noexcept; void SetDisplaySpecies(const ArbUt::BorrowedPtr& species) noexcept { _displaySpecies = species.GetRaw(); } void SetDisplayVariant(ArbUt::BorrowedPtr variant) noexcept { _displayVariant = variant.GetRaw(); }; inline bool AllowedExperienceGain() const noexcept { return _allowedExperienceGain; } inline void SetAllowedExperienceGain(bool allowed) noexcept { _allowedExperienceGain = allowed; } uint8_t GetAvailableAttackSlot() const noexcept; void AddAttack(LearnedAttack* attack); void ReplaceAttack(size_t index, LearnedAttack* attack); void SwapAttacks(size_t a, size_t b) { _attacks.Swap(a, b); } // 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 virtual Creature* Clone(); }; } #endif // CREATURELIB_CREATURE_HPP