93 lines
3.1 KiB
C++
93 lines
3.1 KiB
C++
#ifndef CREATURELIB_EXECUTINGATTACK_HPP
|
|
#define CREATURELIB_EXECUTINGATTACK_HPP
|
|
|
|
#include <cstdint>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
#include "Creature.hpp"
|
|
|
|
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() {}
|
|
|
|
[[nodiscard]] inline bool IsCritical() const { return _critical; }
|
|
[[nodiscard]] inline uint8_t GetBasePower() const { return _basePower; }
|
|
[[nodiscard]] inline float GetEffectiveness() const { return _effectiveness; }
|
|
[[nodiscard]] inline uint32_t GetDamage() const { return _damage; }
|
|
[[nodiscard]] inline uint8_t GetType() const { return _type; }
|
|
|
|
inline void SetCritical(bool value) { _critical = value; }
|
|
inline void SetBasePower(uint8_t value) { _basePower = value; }
|
|
inline void SetEffectiveness(float value) { _effectiveness = value; }
|
|
inline void SetDamage(uint32_t value) { _damage = value; }
|
|
inline void SetType(uint8_t value) { _type = value; }
|
|
};
|
|
|
|
class TargetData {
|
|
bool _isHit = true;
|
|
std::vector<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]; }
|
|
|
|
HitData* GetHitPtr(uint8_t index) { return &_hits[index]; }
|
|
|
|
uint8_t GetNumberOfHits() const { return _hits.size(); }
|
|
|
|
bool IsHit() const { return _isHit; }
|
|
};
|
|
|
|
private:
|
|
std::unordered_map<Creature*, TargetData> _targets;
|
|
Creature* _user;
|
|
LearnedAttack* _attack;
|
|
Script* _script;
|
|
|
|
public:
|
|
ExecutingAttack(const std::vector<Creature*>& targets, uint8_t numberHits, Creature* user,
|
|
LearnedAttack* attack, Script* script)
|
|
: _user(user), _attack(attack), _script(script) {
|
|
_targets.reserve(targets.size());
|
|
for (auto target : targets) {
|
|
_targets.insert({target, TargetData(numberHits)});
|
|
}
|
|
}
|
|
|
|
virtual ~ExecutingAttack() = default;
|
|
|
|
TargetData& GetAttackDataForTarget(Creature* creature) { return _targets[creature]; }
|
|
|
|
bool IsCreatureTarget(Creature* creature) { return _targets.find(creature) != _targets.end(); }
|
|
|
|
std::unordered_map<Creature*, TargetData>& GetTargets() { return _targets; }
|
|
|
|
Creature* GetUser() { return _user; }
|
|
|
|
LearnedAttack* GetAttack() { return _attack; }
|
|
|
|
protected:
|
|
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override {
|
|
scripts.emplace_back(&_script);
|
|
GetUser()->GetActiveScripts(scripts);
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif // CREATURELIB_EXECUTINGATTACK_HPP
|