Adds script hook for preventing the opponent from switching out.
continuous-integration/drone/push Build is passing Details

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2021-03-27 22:54:51 +01:00
parent 1ddbfd2357
commit acacd02ef9
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 22 additions and 1 deletions

View File

@ -251,14 +251,33 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo
}
void TurnHandler::ExecuteSwitchChoice(const ArbUt::BorrowedPtr<SwitchTurnChoice>& choice) {
auto user = choice->GetUser();
auto battle = user->GetBattle();
if (!battle.HasValue()) {
return;
}
bool preventSwitch = false;
HOOK(PreventSelfSwitch, choice, choice.GetRaw(), &preventSwitch);
if (preventSwitch) {
return;
}
// HOOK: PreventOpponentSwitch for each opponent.
for (auto* side : battle.GetValue()->GetSides()) {
if (side == user->GetBattleSide()) {
continue;
}
for (const auto& creature : side->GetCreatures()) {
if (!creature.HasValue()) {
continue;
}
HOOK(PreventOpponentSwitch, creature.GetValue(), choice, &preventSwitch);
if (preventSwitch) {
return;
}
}
}
auto user = choice->GetUser();
user->ClearVolatileScripts();
auto userSide = user->GetBattleSide();
if (userSide.HasValue()) {

View File

@ -71,6 +71,8 @@ namespace CreatureLib::Battling {
virtual void PreventSelfSwitch([[maybe_unused]] const SwitchTurnChoice* choice,
[[maybe_unused]] bool* outResult){};
virtual void PreventOpponentSwitch([[maybe_unused]] const SwitchTurnChoice* choice,
[[maybe_unused]] bool* outResult){};
virtual void ModifyEffectChance([[maybe_unused]] const ExecutingAttack* attack,
[[maybe_unused]] Creature* target, [[maybe_unused]] float* chance){};