58 lines
1.6 KiB
C++
58 lines
1.6 KiB
C++
#include "TurnHandler.hpp"
|
|
#include "../Models/Creature.hpp"
|
|
#include "../Models/Battle.hpp"
|
|
#include "../../Core/Exceptions/NotImplementedException.hpp"
|
|
|
|
void CreatureLib::Battling::TurnHandler::RunTurn(CreatureLib::Battling::ChoiceQueue &queue) {
|
|
//HOOK: On Before Turn hook for all choices
|
|
while (queue.HasNext()){
|
|
ExecuteChoice(queue.Dequeue());
|
|
}
|
|
}
|
|
|
|
void CreatureLib::Battling::TurnHandler::ExecuteChoice(const CreatureLib::Battling::BaseTurnChoice *choice) {
|
|
if (choice == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
auto choiceKind = choice->GetKind();
|
|
if (choiceKind == TurnChoiceKind::Pass) {
|
|
return;
|
|
}
|
|
auto user = choice->GetUser();
|
|
// If the user is fainted, we don't want to execute its choice.
|
|
if (user->IsFainted()){
|
|
return;
|
|
}
|
|
auto battle = user->GetBattle();
|
|
// If the user is not in the field, we don't want to execute its choice.
|
|
if (!battle->CreatureInField(user)){
|
|
return;
|
|
}
|
|
// If the choice is not valid, we don't want to execute it.
|
|
if (!battle->CanUse(choice)){
|
|
return;
|
|
}
|
|
|
|
switch (choiceKind){
|
|
case TurnChoiceKind::Pass: return;
|
|
case TurnChoiceKind::Attack:
|
|
return ExecuteAttackChoice(static_cast<const AttackTurnChoice*>(choice));
|
|
case TurnChoiceKind::Item:
|
|
case TurnChoiceKind::Switch:
|
|
case TurnChoiceKind::RunAway:
|
|
throw NotImplementedException();
|
|
}
|
|
|
|
delete choice;
|
|
}
|
|
|
|
void CreatureLib::Battling::TurnHandler::ExecuteAttackChoice(const CreatureLib::Battling::AttackTurnChoice *choice) {
|
|
//HOOK: Change attack
|
|
|
|
//HOOK: Prevent attack
|
|
|
|
|
|
}
|
|
|