Files
CreatureLib/src/Battling/Models/ExecutingAttack.hpp
Deukhoofd 70fc8d2d5f
All checks were successful
continuous-integration/drone/push Build is passing
Add C interface for ExecutingAttack.
2020-04-06 17:05:32 +02:00

97 lines
3.4 KiB
C++

#ifndef CREATURELIB_EXECUTINGATTACK_HPP
#define CREATURELIB_EXECUTINGATTACK_HPP
#include <Arbutils/Assert.hpp>
#include <Arbutils/Collections/Dictionary.hpp>
#include <Arbutils/Collections/List.hpp>
#include <cstdint>
#include <unordered_map>
#include <vector>
#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<HitData> _hits;
public:
explicit TargetData(uint8_t numberOfHits) : _hits(numberOfHits) {
for (uint8_t i = 0; i < numberOfHits; i++) {
_hits[i] = 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<Creature*, TargetData> _targets;
Creature* _user;
LearnedAttack* _attack;
Script* _script;
public:
ExecutingAttack(const List<Creature*>& 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<Creature*, TargetData>& GetTargets() noexcept { return _targets; }
Creature* GetUser() noexcept { return _user; }
LearnedAttack* GetAttack() noexcept { return _attack; }
protected:
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
scripts.Append(&_script);
_user->GetActiveScripts(scripts);
}
};
}
#endif // CREATURELIB_EXECUTINGATTACK_HPP