Handle executing moves.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
fc675efdf5
commit
b4e08049ce
|
@ -1,6 +1,7 @@
|
||||||
#include "TurnHandler.hpp"
|
#include "TurnHandler.hpp"
|
||||||
#include "../Models/Creature.hpp"
|
#include "../Models/Creature.hpp"
|
||||||
#include "../Models/Battle.hpp"
|
#include "../Models/Battle.hpp"
|
||||||
|
#include "../Models/ExecutingAttack.hpp"
|
||||||
#include "../../Core/Exceptions/NotImplementedException.hpp"
|
#include "../../Core/Exceptions/NotImplementedException.hpp"
|
||||||
|
|
||||||
void CreatureLib::Battling::TurnHandler::RunTurn(CreatureLib::Battling::ChoiceQueue &queue) {
|
void CreatureLib::Battling::TurnHandler::RunTurn(CreatureLib::Battling::ChoiceQueue &queue) {
|
||||||
|
@ -52,6 +53,72 @@ void CreatureLib::Battling::TurnHandler::ExecuteAttackChoice(const CreatureLib::
|
||||||
|
|
||||||
//HOOK: Prevent attack
|
//HOOK: Prevent attack
|
||||||
|
|
||||||
|
auto attack = ExecutingAttack();
|
||||||
|
|
||||||
|
//HOOK: override targets
|
||||||
|
|
||||||
|
if (!choice->GetAttack()->TryUse(1)){
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//HOOK: check if attack fails
|
||||||
|
|
||||||
|
//HOOK: Check if attack stops after decreasing PP
|
||||||
|
|
||||||
|
//HOOK: On Before Attack
|
||||||
|
|
||||||
|
for (auto kv: attack.GetTargets()){
|
||||||
|
HandleAttackForTarget(attack, kv.first, kv.second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreatureLib::Battling::TurnHandler::HandleAttackForTarget(CreatureLib::Battling::ExecutingAttack &attack,
|
||||||
|
CreatureLib::Battling::Creature *target,
|
||||||
|
CreatureLib::Battling::ExecutingAttack::TargetData &targetData) {
|
||||||
|
//HOOK: Check if attack fails on target
|
||||||
|
|
||||||
|
//HOOK: Check if target is invulnerable
|
||||||
|
|
||||||
|
|
||||||
|
if (!targetData.IsHit()){
|
||||||
|
//HOOK: On attack miss.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto numHits = targetData.GetNumberOfHits();
|
||||||
|
if (numHits == 0)
|
||||||
|
return;
|
||||||
|
auto user = attack.GetUser();
|
||||||
|
auto attackData = attack.GetAttack()->GetAttack();
|
||||||
|
for (uint8_t hitIndex = 0; hitIndex < numHits; hitIndex++){
|
||||||
|
if (user->IsFainted()){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (target->IsFainted()){
|
||||||
|
// STOP, STOP! HE'S ALREADY DEAD ;_;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
auto hit = targetData.GetHit(hitIndex);
|
||||||
|
//TODO: calculate data for hit
|
||||||
|
if (attackData->GetCategory() == Library::AttackCategory::Status){
|
||||||
|
//HOOK: Status attack
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
auto damage = hit.GetDamage();
|
||||||
|
if (damage > target->GetCurrentHealth()){
|
||||||
|
damage = target->GetCurrentHealth();
|
||||||
|
hit.OverrideDamage(damage);
|
||||||
|
}
|
||||||
|
if (damage > 0){
|
||||||
|
target->Damage(damage, DamageSource::AttackDamage);
|
||||||
|
//HOOK: Prevent secondary effects
|
||||||
|
|
||||||
|
//HOOK: On Move Hit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!user->IsFainted()){
|
||||||
|
//HOOK: On After Hits
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "ChoiceQueue.hpp"
|
#include "ChoiceQueue.hpp"
|
||||||
#include "../TurnChoices/AttackTurnChoice.hpp"
|
#include "../TurnChoices/AttackTurnChoice.hpp"
|
||||||
|
#include "../Models/ExecutingAttack.hpp"
|
||||||
|
|
||||||
namespace CreatureLib::Battling {
|
namespace CreatureLib::Battling {
|
||||||
class Battle;
|
class Battle;
|
||||||
|
@ -11,6 +12,7 @@ namespace CreatureLib::Battling {
|
||||||
static void ExecuteChoice(const BaseTurnChoice* choice);
|
static void ExecuteChoice(const BaseTurnChoice* choice);
|
||||||
|
|
||||||
static void ExecuteAttackChoice(const AttackTurnChoice* choice);
|
static void ExecuteAttackChoice(const AttackTurnChoice* choice);
|
||||||
|
static void HandleAttackForTarget(ExecutingAttack& attack, Creature* target, ExecutingAttack::TargetData& targetData);
|
||||||
public:
|
public:
|
||||||
static void RunTurn(ChoiceQueue& queue);
|
static void RunTurn(ChoiceQueue& queue);
|
||||||
};
|
};
|
||||||
|
|
|
@ -116,3 +116,11 @@ Battling::BattleSide *Battling::Creature::GetBattleSide() const {
|
||||||
bool Battling::Creature::IsFainted() const {
|
bool Battling::Creature::IsFainted() const {
|
||||||
return this->__CurrentHealth <= 0;
|
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 "../../GenericTemplates.cpp"
|
||||||
#include "../Library/BattleLibrary.hpp"
|
#include "../Library/BattleLibrary.hpp"
|
||||||
#include "LearnedAttack.hpp"
|
#include "LearnedAttack.hpp"
|
||||||
|
#include "DamageSource.hpp"
|
||||||
|
|
||||||
namespace CreatureLib::Battling{
|
namespace CreatureLib::Battling{
|
||||||
// Forward declare battle class
|
// Forward declare battle class
|
||||||
|
@ -45,11 +46,10 @@ namespace CreatureLib::Battling{
|
||||||
|
|
||||||
const std::string& GetNickname() const;
|
const std::string& GetNickname() const;
|
||||||
const std::string& GetTalent() const;
|
const std::string& GetTalent() const;
|
||||||
|
|
||||||
void ChangeLevel(int8_t amount);
|
void ChangeLevel(int8_t amount);
|
||||||
|
void Damage(uint32_t damage, DamageSource source);
|
||||||
|
|
||||||
void SetBattleData(Battle* battle, BattleSide* side);
|
void SetBattleData(Battle* battle, BattleSide* side);
|
||||||
|
|
||||||
Battle* GetBattle() const;
|
Battle* GetBattle() const;
|
||||||
BattleSide* GetBattleSide() const;
|
BattleSide* GetBattleSide() const;
|
||||||
|
|
||||||
|
@ -71,6 +71,8 @@ namespace CreatureLib::Battling{
|
||||||
void RecalculateFlatStat(Core::Statistic);
|
void RecalculateFlatStat(Core::Statistic);
|
||||||
void RecalculateBoostedStat(Core::Statistic);
|
void RecalculateBoostedStat(Core::Statistic);
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
@ -0,0 +1 @@
|
||||||
|
#include "ExecutingAttack.hpp"
|
|
@ -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
|
Loading…
Reference in New Issue