From 44dbb5601f196c16a3e6146df13e031d0f4df790 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 21 Nov 2021 10:46:02 +0100 Subject: [PATCH] Adds hook to prevent critical hits. --- src/Battling/Flow/TurnHandler.cpp | 8 +++++++- src/Battling/ScriptHandling/BattleScript.hpp | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Battling/Flow/TurnHandler.cpp b/src/Battling/Flow/TurnHandler.cpp index d603cd9..d97be83 100644 --- a/src/Battling/Flow/TurnHandler.cpp +++ b/src/Battling/Flow/TurnHandler.cpp @@ -224,7 +224,13 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo auto effectiveness = typeLibrary->GetEffectiveness(hitType, target->GetTypes()); HOOK(ChangeEffectiveness, attack, attack, target.GetRaw(), hitIndex, &effectiveness) hit.SetEffectiveness(effectiveness); - hit.SetCritical(miscLibrary->IsCritical(attack, target.GetRaw(), hitIndex)); + bool canBeCritical = true; + HOOK(BlockCritical, attack, attack, target.GetRaw(), hitIndex, &canBeCritical); + if (canBeCritical) { + hit.SetCritical(miscLibrary->IsCritical(attack, target.GetRaw(), hitIndex)); + } else { + hit.SetCritical(false); + } hit.SetBasePower(dmgLibrary->GetBasePower(attack, target.GetRaw(), hitIndex, hit)); hit.SetDamage(dmgLibrary->GetDamage(attack, target.GetRaw(), hitIndex, hit)); diff --git a/src/Battling/ScriptHandling/BattleScript.hpp b/src/Battling/ScriptHandling/BattleScript.hpp index 899f726..13d244b 100644 --- a/src/Battling/ScriptHandling/BattleScript.hpp +++ b/src/Battling/ScriptHandling/BattleScript.hpp @@ -62,6 +62,8 @@ namespace CreatureLib::Battling { [[maybe_unused]] u8 hitNumber, [[maybe_unused]] u8* outType){}; virtual void ChangeEffectiveness([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target, [[maybe_unused]] u8 hitNumber, [[maybe_unused]] float* effectiveness){}; + virtual void BlockCritical([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target, + [[maybe_unused]] u8 hitNumber, [[maybe_unused]] bool* canBeCritical){}; virtual void OverrideBasePower([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target, [[maybe_unused]] u8 hitIndex, [[maybe_unused]] u8* basePower){};