diff --git a/src/ScriptResolving/AngelScript/AngelScriptScript.cpp b/src/ScriptResolving/AngelScript/AngelScriptScript.cpp index 15a4fd8..11d3135 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptScript.cpp +++ b/src/ScriptResolving/AngelScript/AngelScriptScript.cpp @@ -273,3 +273,15 @@ void AngelScriptScript::OnFail(CreatureLib::Battling::Creature* target) { void AngelScriptScript::OnOpponentFail(CreatureLib::Battling::Creature* target) { CALL_HOOK(OnOpponentFail, { ctx->SetArgObject(0, (void*)target); }) } +void AngelScriptScript::PreventRunAway(const CreatureLib::Battling::FleeTurnChoice* choice, bool* result) { + CALL_HOOK(PreventRunAway, { + ctx->SetArgObject(0, (void*)choice); + ctx->SetArgAddress(1, result); + }) +} +void AngelScriptScript::PreventOpponentRunAway(const CreatureLib::Battling::FleeTurnChoice* choice, bool* result) { + CALL_HOOK(PreventOpponentRunAway, { + ctx->SetArgObject(0, (void*)choice); + ctx->SetArgAddress(1, result); + }) +} diff --git a/src/ScriptResolving/AngelScript/AngelScriptScript.hpp b/src/ScriptResolving/AngelScript/AngelScriptScript.hpp index 08dd636..a56ef2a 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptScript.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptScript.hpp @@ -101,6 +101,9 @@ public: void OnFail(CreatureLib::Battling::Creature* target) override; void OnOpponentFail(CreatureLib::Battling::Creature* target) override; + void PreventRunAway(const CreatureLib::Battling::FleeTurnChoice* choice, bool* result) override; + void PreventOpponentRunAway(const CreatureLib::Battling::FleeTurnChoice* choice, bool* result) override; + //////////////////// // PkmnLib methods// //////////////////// diff --git a/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp b/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp index e8840a3..0f0871d 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp @@ -136,6 +136,9 @@ public: SCRIPT_HOOK_FUNCTION(ChangePriority, "void ChangePriority(MoveTurnChoice@ choice, int8& priority)"); SCRIPT_HOOK_FUNCTION(OnFail, "void OnFail(Pokemon@ user)"); SCRIPT_HOOK_FUNCTION(OnOpponentFail, "void OnOpponentFail(Pokemon@ user)"); + + SCRIPT_HOOK_FUNCTION(PreventRunAway, "void PreventRunAway(FleeTurnChoice@ choice, bool& result)"); + SCRIPT_HOOK_FUNCTION(PreventOpponentRunAway, "void PreventOpponentRunAway(FleeTurnChoice@ choice, ool& result)"); }; #undef SCRIPT_HOOK_FUNCTION diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp index bcabad6..4d3e566 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp @@ -37,8 +37,11 @@ shared abstract class PkmnScript { void OverrideDamage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint& damage){}; void ChangePriority(MoveTurnChoice@ choice, int8& priority){}; - void OnFail(Pokemon@ user){} - void OnOpponentFail(Pokemon@ user){} + void OnFail(Pokemon@ user){}; + void OnOpponentFail(Pokemon@ user){}; + + void PreventRunAway(FleeTurnChoice@ choice, bool& result){}; + void PreventOpponentRunAway(FleeTurnChoice@ choice, bool& result){}; // PkmnLib methods void ModifyCriticalStage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& critStage){}; diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterTurnChoices.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterTurnChoices.cpp index 87272a5..6ef763d 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterTurnChoices.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterTurnChoices.cpp @@ -9,6 +9,7 @@ void RegisterTurnChoices::Register(asIScriptEngine* engine) { RegisterBaseTurnChoice(engine); RegisterMoveTurnChoice(engine); RegisterSwitchTurnChoice(engine); + RegisterFleeTurnChoice(engine); } void RegisterTurnChoices::RegisterTurnChoiceKindEnum(asIScriptEngine* engine) { [[maybe_unused]] int r = engine->RegisterEnum("TurnChoiceKind"); @@ -78,13 +79,34 @@ void RegisterTurnChoices::RegisterSwitchTurnChoice(asIScriptEngine* engine) { Ensure(r >= 0); r = engine->RegisterObjectMethod( - "SwitchTurnChoice", "MoveTurnChoice@ opCast()", + "BaseTurnChoice", "SwitchTurnChoice@ opCast()", asFUNCTION((refCast)), asCALL_CDECL_OBJLAST); Ensure(r >= 0); r = engine->RegisterObjectMethod( "SwitchTurnChoice", "BaseTurnChoice@ opImplCast()", - asFUNCTION((refCast)), + asFUNCTION((refCast)), + asCALL_CDECL_OBJLAST); + Ensure(r >= 0); +} +void RegisterTurnChoices::RegisterFleeTurnChoice(asIScriptEngine* engine) { + [[maybe_unused]] int r = engine->RegisterObjectType("FleeTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT); + Ensure(r >= 0); + r = engine->RegisterObjectMethod("FleeTurnChoice", "TurnChoiceKind get_Kind() const property", + asMETHOD(CreatureLib::Battling::FleeTurnChoice, GetKind), asCALL_THISCALL); + Ensure(r >= 0); + r = engine->RegisterObjectMethod("FleeTurnChoice", "Pokemon@ get_User() const property", + asMETHOD(CreatureLib::Battling::FleeTurnChoice, GetUser), asCALL_THISCALL); + Ensure(r >= 0); + + r = engine->RegisterObjectMethod( + "BaseTurnChoice", "FleeTurnChoice@ opCast()", + asFUNCTION((refCast)), + asCALL_CDECL_OBJLAST); + Ensure(r >= 0); + r = engine->RegisterObjectMethod( + "FleeTurnChoice", "BaseTurnChoice@ opImplCast()", + asFUNCTION((refCast)), asCALL_CDECL_OBJLAST); Ensure(r >= 0); } diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterTurnChoices.hpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterTurnChoices.hpp index 1dc5448..2ae11aa 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterTurnChoices.hpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterTurnChoices.hpp @@ -8,6 +8,7 @@ class RegisterTurnChoices { static void RegisterBaseTurnChoice(asIScriptEngine* engine); static void RegisterMoveTurnChoice(asIScriptEngine* engine); static void RegisterSwitchTurnChoice(asIScriptEngine* engine); + static void RegisterFleeTurnChoice(asIScriptEngine* engine); public: static void Register(asIScriptEngine* engine);