CreatureLib/src/Battling/Models/ExecutingAttack.hpp

93 lines
3.3 KiB
C++
Raw Normal View History

2019-11-03 12:47:50 +00:00
#ifndef CREATURELIB_EXECUTINGATTACK_HPP
#define CREATURELIB_EXECUTINGATTACK_HPP
2020-03-22 12:42:26 +00:00
#include <Arbutils/Assert.hpp>
#include <Arbutils/Collections/Dictionary.hpp>
#include <Arbutils/Collections/List.hpp>
2019-11-03 12:47:50 +00:00
#include <cstdint>
#include <unordered_map>
#include <vector>
2019-11-03 12:47:50 +00:00
#include "Creature.hpp"
using namespace Arbutils::Collections;
2019-11-03 12:47:50 +00:00
namespace CreatureLib::Battling {
2019-11-09 11:55:48 +00:00
class ExecutingAttack : public ScriptSource {
2019-11-03 12:47:50 +00:00
public:
class HitData {
2019-11-03 12:47:50 +00:00
bool _critical = false;
uint8_t _basePower = 0;
float _effectiveness = 1;
uint32_t _damage = 0;
2019-11-05 07:06:12 +00:00
uint8_t _type = 0;
2019-11-03 12:47:50 +00:00
public:
2020-04-06 15:05:32 +00:00
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; }
2019-11-03 12:47:50 +00:00
};
class TargetData {
bool _isHit = true;
List<HitData> _hits;
2019-11-03 12:47:50 +00:00
public:
2020-04-25 08:41:15 +00:00
explicit TargetData(uint8_t numberOfHits) : _hits(numberOfHits) { _hits.Resize(numberOfHits, HitData()); }
TargetData() = default;
2019-11-03 12:47:50 +00:00
HitData* GetHit(uint8_t index) { return &_hits[index]; }
2019-11-03 12:47:50 +00:00
2020-04-06 15:05:32 +00:00
uint8_t GetNumberOfHits() const noexcept { return _hits.Count(); }
2019-11-03 12:47:50 +00:00
2020-04-06 15:05:32 +00:00
bool IsHit() const noexcept { return _isHit; }
2019-11-03 12:47:50 +00:00
};
private:
Dictionary<Creature*, TargetData> _targets;
2019-11-03 12:47:50 +00:00
Creature* _user;
LearnedAttack* _attack;
2019-11-09 11:55:48 +00:00
Script* _script;
2019-11-03 12:47:50 +00:00
public:
ExecutingAttack(const List<Creature*>& targets, uint8_t numberHits, Creature* user, LearnedAttack* attack,
Script* script)
: _targets(targets.Count()), _user(user), _attack(attack), _script(script) {
2020-03-22 12:42:26 +00:00
AssertNotNull(user)
AssertNotNull(attack)
for (auto target : targets) {
_targets.Insert(target, TargetData(numberHits));
2019-11-24 10:06:51 +00:00
}
}
2020-04-06 15:05:32 +00:00
virtual ~ExecutingAttack() noexcept { delete _script; };
2019-11-03 12:47:50 +00:00
TargetData* GetAttackDataForTarget(Creature* creature) { return &_targets[creature]; }
2019-11-03 12:47:50 +00:00
2020-04-06 15:05:32 +00:00
bool IsCreatureTarget(Creature* creature) noexcept { return _targets.Has(creature); }
2019-11-03 12:47:50 +00:00
2020-04-06 15:05:32 +00:00
Dictionary<Creature*, TargetData>& GetTargets() noexcept { return _targets; }
2019-11-03 12:47:50 +00:00
2020-04-06 15:05:32 +00:00
Creature* GetUser() noexcept { return _user; }
2019-11-03 12:47:50 +00:00
2020-04-06 15:05:32 +00:00
LearnedAttack* GetAttack() noexcept { return _attack; }
2019-11-09 11:55:48 +00:00
protected:
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
2020-04-23 21:23:58 +00:00
scripts.Append(ScriptWrapper::FromScript(&_script));
_user->GetActiveScripts(scripts);
2019-11-09 11:55:48 +00:00
}
2019-11-03 12:47:50 +00:00
};
}
#endif // CREATURELIB_EXECUTINGATTACK_HPP