Adds script hooks for preventing runaway.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
parent
46307fe71f
commit
4dd3700352
|
@ -6,8 +6,8 @@
|
|||
|
||||
using namespace CreatureLib::Battling;
|
||||
|
||||
void TurnHandler::RunTurn(ArbUt::BorrowedPtr<ChoiceQueue> queue, ArbUt::BorrowedPtr<Battle> battle) {
|
||||
for (auto choice : queue->GetInnerQueue()) {
|
||||
void TurnHandler::RunTurn(const ArbUt::BorrowedPtr<ChoiceQueue>& queue, const ArbUt::BorrowedPtr<Battle>& battle) {
|
||||
for (const auto& choice : queue->GetInnerQueue()) {
|
||||
HOOK(OnBeforeTurn, choice, choice.get());
|
||||
}
|
||||
while (queue->HasNext() && !battle->HasEnded()) {
|
||||
|
@ -27,17 +27,19 @@ void TurnHandler::RunTurn(ArbUt::BorrowedPtr<ChoiceQueue> queue, ArbUt::Borrowed
|
|||
queue->HasCompletedQueue = true;
|
||||
}
|
||||
|
||||
void TurnHandler::ExecuteChoice(ArbUt::BorrowedPtr<BaseTurnChoice> choice) {
|
||||
void TurnHandler::ExecuteChoice(const ArbUt::BorrowedPtr<BaseTurnChoice>& choice) {
|
||||
auto choiceKind = choice->GetKind();
|
||||
if (choiceKind == TurnChoiceKind::Pass) {
|
||||
return;
|
||||
}
|
||||
auto user = choice->GetUser();
|
||||
if (!user->GetBattle().HasValue())
|
||||
if (!user->GetBattle().HasValue()) {
|
||||
return;
|
||||
auto battle = user->GetBattle().GetValue();
|
||||
if (battle->HasEnded())
|
||||
}
|
||||
auto* battle = user->GetBattle().GetValue();
|
||||
if (battle->HasEnded()) {
|
||||
return;
|
||||
}
|
||||
// If the user is fainted, we don't want to execute its choice.
|
||||
if (user->IsFainted()) {
|
||||
return;
|
||||
|
@ -248,7 +250,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo
|
|||
}
|
||||
}
|
||||
|
||||
void TurnHandler::ExecuteSwitchChoice(ArbUt::BorrowedPtr<SwitchTurnChoice> choice) {
|
||||
void TurnHandler::ExecuteSwitchChoice(const ArbUt::BorrowedPtr<SwitchTurnChoice>& choice) {
|
||||
bool preventSwitch = false;
|
||||
HOOK(PreventSelfSwitch, choice, choice.GetRaw(), &preventSwitch);
|
||||
if (preventSwitch) {
|
||||
|
@ -264,14 +266,32 @@ void TurnHandler::ExecuteSwitchChoice(ArbUt::BorrowedPtr<SwitchTurnChoice> choic
|
|||
userSide.GetValue()->SetCreature(choice->GetNewCreature(), userIndex);
|
||||
}
|
||||
}
|
||||
void TurnHandler::ExecuteFleeChoice(ArbUt::BorrowedPtr<FleeTurnChoice> choice) {
|
||||
void TurnHandler::ExecuteFleeChoice(const ArbUt::BorrowedPtr<FleeTurnChoice>& choice) {
|
||||
auto user = choice->GetUser();
|
||||
auto battle = user->GetBattle();
|
||||
if (!battle.HasValue() || !battle.GetValue()->CanFlee()) {
|
||||
return;
|
||||
}
|
||||
// TODO: If any of the creatures on the users side has a script that prevents it from running, block.
|
||||
// TODO: If any of the creatures on any other side has a script that prevents this side from running, block.
|
||||
|
||||
bool preventRun = false;
|
||||
HOOK(PreventRunAway, choice, &preventRun);
|
||||
if (preventRun) {
|
||||
return;
|
||||
}
|
||||
for (auto* side : battle.GetValue()->GetSides()) {
|
||||
if (side == user->GetBattleSide()) {
|
||||
continue;
|
||||
}
|
||||
for (const auto& creature : side->GetCreatures()) {
|
||||
if (!creature.HasValue()) {
|
||||
continue;
|
||||
}
|
||||
HOOK(PreventOpponentRunAway, creature.GetValue(), &preventRun);
|
||||
if (preventRun) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (battle.GetValue()->GetLibrary()->GetMiscLibrary()->CanFlee(choice.GetRaw())) {
|
||||
if (user->GetBattleSide().HasValue()) {
|
||||
|
|
|
@ -11,16 +11,16 @@ namespace CreatureLib::Battling {
|
|||
class Battle;
|
||||
|
||||
class TurnHandler {
|
||||
static void ExecuteChoice(ArbUt::BorrowedPtr<BaseTurnChoice> choice);
|
||||
static void ExecuteChoice(const ArbUt::BorrowedPtr<BaseTurnChoice>& choice);
|
||||
|
||||
static void ExecuteAttackChoice(const ArbUt::BorrowedPtr<AttackTurnChoice>& choice);
|
||||
static void HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::BorrowedPtr<Creature>& target);
|
||||
|
||||
static void ExecuteSwitchChoice(ArbUt::BorrowedPtr<SwitchTurnChoice> choice);
|
||||
static void ExecuteFleeChoice(ArbUt::BorrowedPtr<FleeTurnChoice> choice);
|
||||
static void ExecuteSwitchChoice(const ArbUt::BorrowedPtr<SwitchTurnChoice>& choice);
|
||||
static void ExecuteFleeChoice(const ArbUt::BorrowedPtr<FleeTurnChoice>& choice);
|
||||
|
||||
public:
|
||||
static void RunTurn(ArbUt::BorrowedPtr<ChoiceQueue> queue, ArbUt::BorrowedPtr<Battle> battle);
|
||||
static void RunTurn(const ArbUt::BorrowedPtr<ChoiceQueue>& queue, const ArbUt::BorrowedPtr<Battle>& battle);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -78,6 +78,9 @@ namespace CreatureLib::Battling {
|
|||
|
||||
virtual void OnFail([[maybe_unused]] Creature* target){};
|
||||
virtual void OnOpponentFail([[maybe_unused]] Creature* target){};
|
||||
|
||||
virtual void PreventRunAway([[maybe_unused]] bool* result){};
|
||||
virtual void PreventOpponentRunAway([[maybe_unused]] bool* result){};
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue