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, bool PkmnLib::Battling::MiscLibrary::IsCritical(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target, uint8_t hit) const { 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; uint8_t critStage = 0;
PKMN_HOOK(ModifyCriticalStage, attack, attack, target, hit, &critStage); PKMN_HOOK(ModifyCriticalStage, attack, attack, target, hit, &critStage);
Ensure(target->GetBattle().HasValue()); Ensure(target->GetBattle().HasValue());

View File

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

View File

@ -249,6 +249,16 @@ void AngelScriptScript::OverrideIncomingDamage(CreatureLib::Battling::ExecutingA
ctx->SetArgAddress(3, damage); 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, void AngelScriptScript::ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target, uint8_t hit, uint8_t* critStage) { CreatureLib::Battling::Creature* target, uint8_t hit, uint8_t* critStage) {
CALL_HOOK(ModifyCriticalStage, { CALL_HOOK(ModifyCriticalStage, {

View File

@ -133,6 +133,8 @@ public:
// PkmnLib methods// // 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, void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
uint8_t hit, uint8_t* critStage) override; uint8_t hit, uint8_t* critStage) override;
void OverrideCriticalModifier(CreatureLib::Battling::ExecutingAttack* attack, void OverrideCriticalModifier(CreatureLib::Battling::ExecutingAttack* attack,

View File

@ -147,6 +147,9 @@ public:
SCRIPT_HOOK_FUNCTION(OverrideIncomingDamage, SCRIPT_HOOK_FUNCTION(OverrideIncomingDamage,
"void OverrideIncomingDamage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, int& damage)"); "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( SCRIPT_HOOK_FUNCTION(
ModifyCriticalStage, ModifyCriticalStage,
"void ModifyCriticalStage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& critStage)"); "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){}; void OnFaint(Pokemon@ pokemon, DamageSource damageSource){};
// PkmnLib methods // PkmnLib methods
void PreventIncomingCritical(ExecutingMove@ attack, Pokemon@ target, uint8 hit, bool& preventCrit){};
void ModifyCriticalStage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& critStage){}; void ModifyCriticalStage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& critStage){};
void OverrideCriticalModifier(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& critModifier){}; void OverrideCriticalModifier(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& critModifier){};
void OverrideSTABModifier(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& stabModifier){}; void OverrideSTABModifier(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& stabModifier){};