Implements creature switching as turn choice.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -43,8 +43,9 @@ void TurnHandler::ExecuteChoice(BaseTurnChoice* choice) {
|
||||
switch (choiceKind) {
|
||||
case TurnChoiceKind::Pass: throw NotReachableException();
|
||||
case TurnChoiceKind::Attack: return ExecuteAttackChoice(dynamic_cast<AttackTurnChoice*>(choice));
|
||||
case TurnChoiceKind::Switch: return ExecuteSwitchChoice(dynamic_cast<SwitchTurnChoice*>(choice));
|
||||
|
||||
case TurnChoiceKind::Item:
|
||||
case TurnChoiceKind::Switch:
|
||||
case TurnChoiceKind::RunAway: throw NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -165,3 +166,18 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
|
||||
HOOK(OnAfterHits, userSource, attack, target);
|
||||
}
|
||||
}
|
||||
|
||||
void TurnHandler::ExecuteSwitchChoice(CreatureLib::Battling::SwitchTurnChoice* choice) {
|
||||
bool preventSwitch = false;
|
||||
HOOK(PreventSelfSwitch, choice, choice, preventSwitch);
|
||||
if (preventSwitch) {
|
||||
return;
|
||||
}
|
||||
// HOOK: PreventOpponentSwitch for each opponent.
|
||||
|
||||
auto user = choice->GetUser();
|
||||
user->ClearVolatileScripts();
|
||||
auto userSide = user->GetBattleSide();
|
||||
auto userIndex = userSide->GetCreatureIndex(user);
|
||||
userSide->SetCreature(choice->GetNewCreature(), userIndex);
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "../Models/ExecutingAttack.hpp"
|
||||
#include "../TurnChoices/AttackTurnChoice.hpp"
|
||||
#include "../TurnChoices/SwitchTurnChoice.hpp"
|
||||
#include "ChoiceQueue.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
@@ -15,6 +16,8 @@ namespace CreatureLib::Battling {
|
||||
static void HandleAttackForTarget(ExecutingAttack* attack, Creature* target,
|
||||
ExecutingAttack::TargetData* targetData);
|
||||
|
||||
static void ExecuteSwitchChoice(SwitchTurnChoice* choice);
|
||||
|
||||
public:
|
||||
static void RunTurn(Battle* battle, ChoiceQueue* queue);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user