Handle executing moves.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-11-03 13:47:50 +01:00
parent fc675efdf5
commit b4e08049ce
7 changed files with 183 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
#include "TurnHandler.hpp"
#include "../Models/Creature.hpp"
#include "../Models/Battle.hpp"
#include "../Models/ExecutingAttack.hpp"
#include "../../Core/Exceptions/NotImplementedException.hpp"
void CreatureLib::Battling::TurnHandler::RunTurn(CreatureLib::Battling::ChoiceQueue &queue) {
@@ -52,6 +53,72 @@ void CreatureLib::Battling::TurnHandler::ExecuteAttackChoice(const CreatureLib::
//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
}
}

View File

@@ -3,6 +3,7 @@
#include "ChoiceQueue.hpp"
#include "../TurnChoices/AttackTurnChoice.hpp"
#include "../Models/ExecutingAttack.hpp"
namespace CreatureLib::Battling {
class Battle;
@@ -11,6 +12,7 @@ namespace CreatureLib::Battling {
static void ExecuteChoice(const BaseTurnChoice* choice);
static void ExecuteAttackChoice(const AttackTurnChoice* choice);
static void HandleAttackForTarget(ExecutingAttack& attack, Creature* target, ExecutingAttack::TargetData& targetData);
public:
static void RunTurn(ChoiceQueue& queue);
};