Support turn queue return prematurely when a creature is recalled, and the ability to resume it later.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#ifndef CREATURELIB_CHOICEQUEUE_HPP
|
||||
#define CREATURELIB_CHOICEQUEUE_HPP
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "../TurnChoices/BaseTurnChoice.hpp"
|
||||
|
||||
@@ -9,8 +10,10 @@ namespace CreatureLib::Battling{
|
||||
std::vector<const BaseTurnChoice*> _queue;
|
||||
size_t _current = 0;
|
||||
public:
|
||||
ChoiceQueue(const std::vector<const BaseTurnChoice*>& queue)
|
||||
:_queue(queue){}
|
||||
bool HasCompletedQueue = false;
|
||||
|
||||
explicit ChoiceQueue(std::vector<const BaseTurnChoice*> queue)
|
||||
:_queue(std::move(queue)){}
|
||||
|
||||
const BaseTurnChoice* Dequeue(){
|
||||
auto b = _queue[_current];
|
||||
@@ -18,7 +21,7 @@ namespace CreatureLib::Battling{
|
||||
return b;
|
||||
}
|
||||
|
||||
bool HasNext() const{
|
||||
[[nodiscard]] bool HasNext() const{
|
||||
return _current < _queue.size();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
#include "TurnHandler.hpp"
|
||||
#include "../Models/Battle.hpp"
|
||||
#include "../Models/ExecutingAttack.hpp"
|
||||
#include "../../Core/Exceptions/NotImplementedException.hpp"
|
||||
|
||||
void CreatureLib::Battling::TurnHandler::RunTurn(CreatureLib::Battling::ChoiceQueue &queue) {
|
||||
using namespace CreatureLib::Battling;
|
||||
|
||||
void TurnHandler::RunTurn(Battle* battle, ChoiceQueue* queue) {
|
||||
//HOOK: On Before Turn hook for all choices
|
||||
while (queue.HasNext()){
|
||||
auto item = queue.Dequeue();
|
||||
while (queue->HasNext()){
|
||||
if (!battle->HasRecalledSlots()){
|
||||
return;
|
||||
}
|
||||
auto item = queue->Dequeue();
|
||||
ExecuteChoice(item);
|
||||
delete item;
|
||||
}
|
||||
queue->HasCompletedQueue = true;
|
||||
}
|
||||
|
||||
void CreatureLib::Battling::TurnHandler::ExecuteChoice(const CreatureLib::Battling::BaseTurnChoice *choice) {
|
||||
void TurnHandler::ExecuteChoice(const BaseTurnChoice *choice) {
|
||||
if (choice == nullptr)
|
||||
{
|
||||
return;
|
||||
@@ -47,7 +52,7 @@ void CreatureLib::Battling::TurnHandler::ExecuteChoice(const CreatureLib::Battli
|
||||
}
|
||||
}
|
||||
|
||||
void CreatureLib::Battling::TurnHandler::ExecuteAttackChoice(const CreatureLib::Battling::AttackTurnChoice *choice) {
|
||||
void TurnHandler::ExecuteAttackChoice(const AttackTurnChoice *choice) {
|
||||
//HOOK: Change attack
|
||||
|
||||
//HOOK: Prevent attack
|
||||
@@ -71,9 +76,7 @@ void CreatureLib::Battling::TurnHandler::ExecuteAttackChoice(const CreatureLib::
|
||||
}
|
||||
}
|
||||
|
||||
void CreatureLib::Battling::TurnHandler::HandleAttackForTarget(CreatureLib::Battling::ExecutingAttack &attack,
|
||||
CreatureLib::Battling::Creature *target,
|
||||
CreatureLib::Battling::ExecutingAttack::TargetData &targetData) {
|
||||
void TurnHandler::HandleAttackForTarget(ExecutingAttack &attack, Creature *target, ExecutingAttack::TargetData &targetData) {
|
||||
//HOOK: Check if attack fails on target
|
||||
|
||||
//HOOK: Check if target is invulnerable
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace CreatureLib::Battling {
|
||||
static void ExecuteAttackChoice(const AttackTurnChoice* choice);
|
||||
static void HandleAttackForTarget(ExecutingAttack& attack, Creature* target, ExecutingAttack::TargetData& targetData);
|
||||
public:
|
||||
static void RunTurn(ChoiceQueue& queue);
|
||||
static void RunTurn(Battle* battle, ChoiceQueue* queue);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user