Handle executing moves.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -116,3 +116,11 @@ Battling::BattleSide *Battling::Creature::GetBattleSide() const {
|
||||
bool Battling::Creature::IsFainted() const {
|
||||
return this->__CurrentHealth <= 0;
|
||||
}
|
||||
|
||||
void Battling::Creature::Damage(uint32_t damage, Battling::DamageSource source) {
|
||||
if (damage > __CurrentHealth){
|
||||
damage = __CurrentHealth;
|
||||
}
|
||||
// HOOK: On Damage
|
||||
__CurrentHealth -= damage;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "../../GenericTemplates.cpp"
|
||||
#include "../Library/BattleLibrary.hpp"
|
||||
#include "LearnedAttack.hpp"
|
||||
#include "DamageSource.hpp"
|
||||
|
||||
namespace CreatureLib::Battling{
|
||||
// Forward declare battle class
|
||||
@@ -45,11 +46,10 @@ namespace CreatureLib::Battling{
|
||||
|
||||
const std::string& GetNickname() const;
|
||||
const std::string& GetTalent() const;
|
||||
|
||||
void ChangeLevel(int8_t amount);
|
||||
void Damage(uint32_t damage, DamageSource source);
|
||||
|
||||
void SetBattleData(Battle* battle, BattleSide* side);
|
||||
|
||||
Battle* GetBattle() const;
|
||||
BattleSide* GetBattleSide() const;
|
||||
|
||||
@@ -71,6 +71,8 @@ namespace CreatureLib::Battling{
|
||||
void RecalculateFlatStat(Core::Statistic);
|
||||
void RecalculateBoostedStat(Core::Statistic);
|
||||
//endregion
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
12
src/Battling/Models/DamageSource.hpp
Normal file
12
src/Battling/Models/DamageSource.hpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef CREATURELIB_DAMAGESOURCE_HPP
|
||||
#define CREATURELIB_DAMAGESOURCE_HPP
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
enum class DamageSource : uint8_t {
|
||||
AttackDamage,
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_DAMAGESOURCE_HPP
|
||||
1
src/Battling/Models/ExecutingAttack.cpp
Normal file
1
src/Battling/Models/ExecutingAttack.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include "ExecutingAttack.hpp"
|
||||
89
src/Battling/Models/ExecutingAttack.hpp
Normal file
89
src/Battling/Models/ExecutingAttack.hpp
Normal file
@@ -0,0 +1,89 @@
|
||||
#ifndef CREATURELIB_EXECUTINGATTACK_HPP
|
||||
#define CREATURELIB_EXECUTINGATTACK_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include "Creature.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class ExecutingAttack {
|
||||
public:
|
||||
class HitData{
|
||||
bool _critical = false;
|
||||
uint8_t _basePower = 0;
|
||||
float _effectiveness = 1;
|
||||
uint32_t _damage = 0;
|
||||
public:
|
||||
HitData(){}
|
||||
|
||||
inline bool IsCritical() const{ return _critical;}
|
||||
inline uint8_t GetBasePower() const{ return _basePower;}
|
||||
inline float GetEffectiveness() const{ return _effectiveness;}
|
||||
inline uint32_t GetDamage() const{ return _damage;}
|
||||
|
||||
inline void SetCritical(bool value) {_critical = value;}
|
||||
inline void SetBasePower(uint8_t value) { _basePower = value; }
|
||||
inline void SetEffectiveness(float value) {_effectiveness = value;}
|
||||
inline void OverrideDamage(uint32_t value) {_damage = value;}
|
||||
};
|
||||
|
||||
class TargetData {
|
||||
bool _isHit = true;
|
||||
std::vector<HitData> _hits;
|
||||
public:
|
||||
TargetData(uint8_t numberOfHits) : _hits(numberOfHits)
|
||||
{
|
||||
for (uint8_t i = 0; i < numberOfHits; i++){
|
||||
_hits[i] = HitData();
|
||||
}
|
||||
}
|
||||
TargetData(){}
|
||||
|
||||
HitData& GetHit(uint8_t index){
|
||||
return _hits[index];
|
||||
}
|
||||
|
||||
HitData* GetHitPtr(uint8_t index){
|
||||
return &_hits[index];
|
||||
}
|
||||
|
||||
uint8_t GetNumberOfHits(){
|
||||
return _hits.size();
|
||||
}
|
||||
|
||||
bool IsHit(){
|
||||
return _isHit;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private:
|
||||
std::unordered_map<Creature*, TargetData> _targets;
|
||||
Creature* _user;
|
||||
LearnedAttack* _attack;
|
||||
public:
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_EXECUTINGATTACK_HPP
|
||||
Reference in New Issue
Block a user