Added more script hooks
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2019-11-23 11:53:00 +01:00
parent 49bd4813f6
commit f6415fba27
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
4 changed files with 22 additions and 10 deletions

View File

@ -15,7 +15,7 @@ namespace CreatureLib::Battling{
explicit ChoiceQueue(std::vector<BaseTurnChoice*> queue)
:_queue(std::move(queue)){}
const BaseTurnChoice* Dequeue(){
BaseTurnChoice* Dequeue(){
auto b = _queue[_current];
_current++;
return b;

View File

@ -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<const AttackTurnChoice*>(choice));
return ExecuteAttackChoice(dynamic_cast<AttackTurnChoice*>(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

View File

@ -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);

View File

@ -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){};