2019-11-03 12:47:50 +00:00
|
|
|
#ifndef CREATURELIB_EXECUTINGATTACK_HPP
|
|
|
|
#define CREATURELIB_EXECUTINGATTACK_HPP
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <vector>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include "Creature.hpp"
|
|
|
|
|
|
|
|
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{
|
|
|
|
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:
|
|
|
|
HitData(){}
|
|
|
|
|
2019-11-05 07:06:12 +00:00
|
|
|
[[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;}
|
2019-11-03 12:47:50 +00:00
|
|
|
|
|
|
|
inline void SetCritical(bool value) {_critical = value;}
|
|
|
|
inline void SetBasePower(uint8_t value) { _basePower = value; }
|
|
|
|
inline void SetEffectiveness(float value) {_effectiveness = value;}
|
2019-11-05 13:31:54 +00:00
|
|
|
inline void SetDamage(uint32_t value) { _damage = value;}
|
2019-11-05 07:06:12 +00:00
|
|
|
inline void SetType(uint8_t value) {_type = value;}
|
2019-11-03 12:47:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class TargetData {
|
|
|
|
bool _isHit = true;
|
|
|
|
std::vector<HitData> _hits;
|
|
|
|
public:
|
2019-11-05 07:06:12 +00:00
|
|
|
explicit TargetData(uint8_t numberOfHits) : _hits(numberOfHits)
|
2019-11-03 12:47:50 +00:00
|
|
|
{
|
|
|
|
for (uint8_t i = 0; i < numberOfHits; i++){
|
|
|
|
_hits[i] = HitData();
|
|
|
|
}
|
|
|
|
}
|
2019-11-05 07:06:12 +00:00
|
|
|
TargetData()= default;
|
2019-11-03 12:47:50 +00:00
|
|
|
|
2019-11-09 12:18:45 +00:00
|
|
|
const HitData& GetHit(uint8_t index) const{
|
2019-11-03 12:47:50 +00:00
|
|
|
return _hits[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
HitData* GetHitPtr(uint8_t index){
|
|
|
|
return &_hits[index];
|
|
|
|
}
|
|
|
|
|
2019-11-09 12:18:45 +00:00
|
|
|
uint8_t GetNumberOfHits() const{
|
2019-11-03 12:47:50 +00:00
|
|
|
return _hits.size();
|
|
|
|
}
|
|
|
|
|
2019-11-09 12:18:45 +00:00
|
|
|
bool IsHit() const{
|
2019-11-03 12:47:50 +00:00
|
|
|
return _isHit;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::unordered_map<Creature*, TargetData> _targets;
|
|
|
|
Creature* _user;
|
|
|
|
LearnedAttack* _attack;
|
2019-11-09 11:55:48 +00:00
|
|
|
Script* _script;
|
2019-11-03 12:47:50 +00:00
|
|
|
public:
|
2019-11-24 10:06:51 +00:00
|
|
|
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)});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-10 13:33:26 +00:00
|
|
|
virtual ~ExecutingAttack() = default;
|
2019-11-03 12:47:50 +00:00
|
|
|
|
|
|
|
TargetData& GetAttackDataForTarget(Creature* creature){
|
|
|
|
return _targets[creature];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsCreatureTarget(Creature* creature){
|
|
|
|
return _targets.find(creature) != _targets.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::unordered_map<Creature*, TargetData>& GetTargets(){
|
|
|
|
return _targets;
|
|
|
|
}
|
|
|
|
|
|
|
|
Creature* GetUser(){
|
|
|
|
return _user;
|
|
|
|
}
|
|
|
|
|
|
|
|
LearnedAttack* GetAttack(){
|
|
|
|
return _attack;
|
|
|
|
}
|
2019-11-09 11:55:48 +00:00
|
|
|
|
2019-11-10 16:08:42 +00:00
|
|
|
protected:
|
|
|
|
void GetActiveScripts(std::vector<ScriptWrapper> &scripts) override {
|
|
|
|
scripts.emplace_back(&_script);
|
|
|
|
GetUser()->GetActiveScripts(scripts);
|
2019-11-09 11:55:48 +00:00
|
|
|
}
|
2019-11-03 12:47:50 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //CREATURELIB_EXECUTINGATTACK_HPP
|