Adds new script hook to prevent incoming critical hits
continuous-integration/drone/push Build is failing Details
continuous-integration/drone Build is failing Details

This commit is contained in:
Deukhoofd 2022-02-12 13:03:40 +01:00
parent 6444a8ce1c
commit 8522b93b7f
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
6 changed files with 24 additions and 0 deletions

View File

@ -8,6 +8,12 @@
bool PkmnLib::Battling::MiscLibrary::IsCritical(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target, uint8_t hit) const {
bool preventCrit = false;
PKMN_HOOK(PreventIncomingCritical, target, attack, target, hit, &preventCrit);
if (preventCrit) {
return false;
}
uint8_t critStage = 0;
PKMN_HOOK(ModifyCriticalStage, attack, attack, target, hit, &critStage);
Ensure(target->GetBattle().HasValue());

View File

@ -16,6 +16,8 @@ namespace PkmnLib::Battling {
public:
PkmnScript(const ArbUt::OptionalBorrowedPtr<void>& owner) : CreatureLib::Battling::BattleScript(owner) {}
virtual void PreventIncomingCritical(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target, uint8_t hit, bool* preventCrit){};
virtual void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target, uint8_t hit, uint8_t* critStage){};
virtual void OverrideCriticalModifier(CreatureLib::Battling::ExecutingAttack* attack,

View File

@ -249,6 +249,16 @@ void AngelScriptScript::OverrideIncomingDamage(CreatureLib::Battling::ExecutingA
ctx->SetArgAddress(3, damage);
})
}
void AngelScriptScript::PreventIncomingCritical(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target, uint8_t hit,
bool* preventCrit) {
CALL_HOOK(PreventIncomingCritical, {
ctx->SetArgObject(0, (void*)attack);
ctx->SetArgObject(1, (void*)target);
ctx->SetArgByte(2, hit);
ctx->SetArgAddress(3, preventCrit);
})
}
void AngelScriptScript::ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target, uint8_t hit, uint8_t* critStage) {
CALL_HOOK(ModifyCriticalStage, {

View File

@ -133,6 +133,8 @@ public:
// PkmnLib methods//
////////////////////
void PreventIncomingCritical(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target, uint8_t hit, bool* preventCrit) override;
void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
uint8_t hit, uint8_t* critStage) override;
void OverrideCriticalModifier(CreatureLib::Battling::ExecutingAttack* attack,

View File

@ -147,6 +147,9 @@ public:
SCRIPT_HOOK_FUNCTION(OverrideIncomingDamage,
"void OverrideIncomingDamage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, int& damage)");
SCRIPT_HOOK_FUNCTION(
PreventIncomingCritical,
"void PreventIncomingCritical(ExecutingMove@ attack, Pokemon@ target, uint8 hit, bool& preventCrit)");
SCRIPT_HOOK_FUNCTION(
ModifyCriticalStage,
"void ModifyCriticalStage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& critStage)");

View File

@ -58,6 +58,7 @@ shared abstract class PkmnScript {
void OnFaint(Pokemon@ pokemon, DamageSource damageSource){};
// PkmnLib methods
void PreventIncomingCritical(ExecutingMove@ attack, Pokemon@ target, uint8 hit, bool& preventCrit){};
void ModifyCriticalStage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& critStage){};
void OverrideCriticalModifier(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& critModifier){};
void OverrideSTABModifier(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& stabModifier){};