diff --git a/src/Battling/Flow/ChoiceQueue.hpp b/src/Battling/Flow/ChoiceQueue.hpp index 5d6975c..475f4ae 100644 --- a/src/Battling/Flow/ChoiceQueue.hpp +++ b/src/Battling/Flow/ChoiceQueue.hpp @@ -15,7 +15,7 @@ namespace CreatureLib::Battling{ explicit ChoiceQueue(std::vector queue) :_queue(std::move(queue)){} - const BaseTurnChoice* Dequeue(){ + BaseTurnChoice* Dequeue(){ auto b = _queue[_current]; _current++; return b; diff --git a/src/Battling/Flow/TurnHandler.cpp b/src/Battling/Flow/TurnHandler.cpp index 8c9bf61..52efffa 100644 --- a/src/Battling/Flow/TurnHandler.cpp +++ b/src/Battling/Flow/TurnHandler.cpp @@ -6,7 +6,6 @@ using namespace CreatureLib::Battling; void TurnHandler::RunTurn(Battle* battle, ChoiceQueue* queue) { - //HOOK: On Before Turn hook for all choices for (auto choice: queue->GetInnerQueue()){ HOOK(OnBeforeTurn, choice, choice); } @@ -21,7 +20,7 @@ void TurnHandler::RunTurn(Battle* battle, ChoiceQueue* queue) { queue->HasCompletedQueue = true; } -void TurnHandler::ExecuteChoice(const BaseTurnChoice *choice) { +void TurnHandler::ExecuteChoice(BaseTurnChoice *choice) { if (choice == nullptr) { return; @@ -48,7 +47,7 @@ void TurnHandler::ExecuteChoice(const BaseTurnChoice *choice) { switch (choiceKind){ case TurnChoiceKind::Pass: throw NotReachableException(); case TurnChoiceKind::Attack: - return ExecuteAttackChoice(dynamic_cast(choice)); + return ExecuteAttackChoice(dynamic_cast(choice)); case TurnChoiceKind::Item: case TurnChoiceKind::Switch: case TurnChoiceKind::RunAway: @@ -56,12 +55,20 @@ void TurnHandler::ExecuteChoice(const BaseTurnChoice *choice) { } } -void TurnHandler::ExecuteAttackChoice(const AttackTurnChoice *choice) { - //HOOK: Change attack - - //HOOK: Prevent attack +void TurnHandler::ExecuteAttackChoice(AttackTurnChoice *choice) { + auto attackName = choice->GetAttack()->GetAttack()->GetName(); + HOOK(ChangeAttack, choice, choice, attackName); + if (attackName != choice->GetAttack()->GetAttack()->GetName()){ + //TODO: Change attack + } + //TODO: Set ExecutingAttack data auto attack = new ExecutingAttack(); + bool prevented = false; + HOOK(PreventAttack, attack, attack, prevented); + if (prevented){ + return; + } //HOOK: override targets diff --git a/src/Battling/Flow/TurnHandler.hpp b/src/Battling/Flow/TurnHandler.hpp index ae3f172..0ebd5b8 100644 --- a/src/Battling/Flow/TurnHandler.hpp +++ b/src/Battling/Flow/TurnHandler.hpp @@ -9,9 +9,9 @@ namespace CreatureLib::Battling { class Battle; class TurnHandler { - static void ExecuteChoice(const BaseTurnChoice* choice); + static void ExecuteChoice(BaseTurnChoice* choice); - static void ExecuteAttackChoice(const AttackTurnChoice* choice); + static void ExecuteAttackChoice(AttackTurnChoice* choice); static void HandleAttackForTarget(ExecutingAttack* attack, Creature* target, const ExecutingAttack::TargetData& targetData); public: static void RunTurn(Battle* battle, ChoiceQueue* queue); diff --git a/src/Battling/ScriptHandling/Script.hpp b/src/Battling/ScriptHandling/Script.hpp index 3018a0e..815e3c0 100644 --- a/src/Battling/ScriptHandling/Script.hpp +++ b/src/Battling/ScriptHandling/Script.hpp @@ -8,6 +8,7 @@ namespace CreatureLib::Battling{ class BaseTurnChoice; + class AttackTurnChoice; class ExecutingAttack; class Creature; @@ -25,6 +26,10 @@ namespace CreatureLib::Battling{ } virtual void OnBeforeTurn(const BaseTurnChoice* choice){}; + + virtual void ChangeAttack(AttackTurnChoice* choice, std::string& attack){}; + virtual void PreventAttack(ExecutingAttack* attack,bool& result){}; + virtual void FailIncomingAttack(ExecutingAttack* attack, Creature* target, bool& result){}; virtual void IsInvulnerable(ExecutingAttack* attack, Creature* target , bool& result){}; virtual void OnAttackMiss(ExecutingAttack* attack, Creature* target){};