#ifndef CREATURELIB_EXECUTINGATTACK_HPP #define CREATURELIB_EXECUTINGATTACK_HPP #include #include #include #include #include #include #include "Creature.hpp" using namespace Arbutils::Collections; namespace CreatureLib::Battling { class ExecutingAttack : public ScriptSource { public: class HitData { bool _critical = false; uint8_t _basePower = 0; float _effectiveness = 1; uint32_t _damage = 0; uint8_t _type = 0; public: HitData() noexcept {} [[nodiscard]] inline bool IsCritical() const noexcept { return _critical; } [[nodiscard]] inline uint8_t GetBasePower() const noexcept { return _basePower; } [[nodiscard]] inline float GetEffectiveness() const noexcept { return _effectiveness; } [[nodiscard]] inline uint32_t GetDamage() const noexcept { return _damage; } [[nodiscard]] inline uint8_t GetType() const noexcept { return _type; } inline void SetCritical(bool value) noexcept { _critical = value; } inline void SetBasePower(uint8_t value) noexcept { _basePower = value; } inline void SetEffectiveness(float value) noexcept { _effectiveness = value; } inline void SetDamage(uint32_t value) noexcept { _damage = value; } inline void SetType(uint8_t value) noexcept { _type = value; } }; class TargetData { bool _isHit = true; List _hits; public: explicit TargetData(uint8_t numberOfHits) : _hits(numberOfHits) { _hits.Resize(numberOfHits, HitData()); } TargetData() = default; HitData* GetHit(uint8_t index) { return &_hits[index]; } uint8_t GetNumberOfHits() const noexcept { return _hits.Count(); } bool IsHit() const noexcept { return _isHit; } }; private: Dictionary _targets; Creature* _user; LearnedAttack* _attack; Script* _script; public: ExecutingAttack(const List& targets, uint8_t numberHits, Creature* user, LearnedAttack* attack, Script* script) : _targets(targets.Count()), _user(user), _attack(attack), _script(script) { AssertNotNull(user) AssertNotNull(attack) for (auto target : targets) { _targets.Insert(target, TargetData(numberHits)); } } virtual ~ExecutingAttack() noexcept { delete _script; }; TargetData* GetAttackDataForTarget(Creature* creature) { return &_targets[creature]; } bool IsCreatureTarget(Creature* creature) noexcept { return _targets.Has(creature); } Dictionary& GetTargets() noexcept { return _targets; } Creature* GetUser() noexcept { return _user; } LearnedAttack* GetAttack() noexcept { return _attack; } protected: void GetActiveScripts(Arbutils::Collections::List& scripts) override { scripts.Append(ScriptWrapper::FromScript(&_script)); _user->GetActiveScripts(scripts); } }; } #endif // CREATURELIB_EXECUTINGATTACK_HPP