Adds new run prevention script hooks.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2021-03-27 15:34:04 +01:00
parent 793daeae80
commit 5cfa174396
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
6 changed files with 48 additions and 4 deletions

View File

@ -273,3 +273,15 @@ void AngelScriptScript::OnFail(CreatureLib::Battling::Creature* target) {
void AngelScriptScript::OnOpponentFail(CreatureLib::Battling::Creature* target) { void AngelScriptScript::OnOpponentFail(CreatureLib::Battling::Creature* target) {
CALL_HOOK(OnOpponentFail, { ctx->SetArgObject(0, (void*)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);
})
}

View File

@ -101,6 +101,9 @@ public:
void OnFail(CreatureLib::Battling::Creature* target) override; void OnFail(CreatureLib::Battling::Creature* target) override;
void OnOpponentFail(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// // PkmnLib methods//
//////////////////// ////////////////////

View File

@ -136,6 +136,9 @@ public:
SCRIPT_HOOK_FUNCTION(ChangePriority, "void ChangePriority(MoveTurnChoice@ choice, int8& priority)"); SCRIPT_HOOK_FUNCTION(ChangePriority, "void ChangePriority(MoveTurnChoice@ choice, int8& priority)");
SCRIPT_HOOK_FUNCTION(OnFail, "void OnFail(Pokemon@ user)"); SCRIPT_HOOK_FUNCTION(OnFail, "void OnFail(Pokemon@ user)");
SCRIPT_HOOK_FUNCTION(OnOpponentFail, "void OnOpponentFail(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 #undef SCRIPT_HOOK_FUNCTION

View File

@ -37,8 +37,11 @@ shared abstract class PkmnScript {
void OverrideDamage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint& damage){}; void OverrideDamage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint& damage){};
void ChangePriority(MoveTurnChoice@ choice, int8& priority){}; void ChangePriority(MoveTurnChoice@ choice, int8& priority){};
void OnFail(Pokemon@ user){} void OnFail(Pokemon@ user){};
void OnOpponentFail(Pokemon@ user){} void OnOpponentFail(Pokemon@ user){};
void PreventRunAway(FleeTurnChoice@ choice, bool& result){};
void PreventOpponentRunAway(FleeTurnChoice@ choice, bool& result){};
// PkmnLib methods // PkmnLib methods
void ModifyCriticalStage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& critStage){}; void ModifyCriticalStage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& critStage){};

View File

@ -9,6 +9,7 @@ void RegisterTurnChoices::Register(asIScriptEngine* engine) {
RegisterBaseTurnChoice(engine); RegisterBaseTurnChoice(engine);
RegisterMoveTurnChoice(engine); RegisterMoveTurnChoice(engine);
RegisterSwitchTurnChoice(engine); RegisterSwitchTurnChoice(engine);
RegisterFleeTurnChoice(engine);
} }
void RegisterTurnChoices::RegisterTurnChoiceKindEnum(asIScriptEngine* engine) { void RegisterTurnChoices::RegisterTurnChoiceKindEnum(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterEnum("TurnChoiceKind"); [[maybe_unused]] int r = engine->RegisterEnum("TurnChoiceKind");
@ -78,13 +79,34 @@ void RegisterTurnChoices::RegisterSwitchTurnChoice(asIScriptEngine* engine) {
Ensure(r >= 0); Ensure(r >= 0);
r = engine->RegisterObjectMethod( r = engine->RegisterObjectMethod(
"SwitchTurnChoice", "MoveTurnChoice@ opCast()", "BaseTurnChoice", "SwitchTurnChoice@ opCast()",
asFUNCTION((refCast<CreatureLib::Battling::BaseTurnChoice, CreatureLib::Battling::SwitchTurnChoice>)), asFUNCTION((refCast<CreatureLib::Battling::BaseTurnChoice, CreatureLib::Battling::SwitchTurnChoice>)),
asCALL_CDECL_OBJLAST); asCALL_CDECL_OBJLAST);
Ensure(r >= 0); Ensure(r >= 0);
r = engine->RegisterObjectMethod( r = engine->RegisterObjectMethod(
"SwitchTurnChoice", "BaseTurnChoice@ opImplCast()", "SwitchTurnChoice", "BaseTurnChoice@ opImplCast()",
asFUNCTION((refCast<CreatureLib::Battling::AttackTurnChoice, CreatureLib::Battling::SwitchTurnChoice>)), asFUNCTION((refCast<CreatureLib::Battling::AttackTurnChoice, CreatureLib::Battling::BaseTurnChoice>)),
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<CreatureLib::Battling::BaseTurnChoice, CreatureLib::Battling::FleeTurnChoice>)),
asCALL_CDECL_OBJLAST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod(
"FleeTurnChoice", "BaseTurnChoice@ opImplCast()",
asFUNCTION((refCast<CreatureLib::Battling::FleeTurnChoice, CreatureLib::Battling::BaseTurnChoice>)),
asCALL_CDECL_OBJLAST); asCALL_CDECL_OBJLAST);
Ensure(r >= 0); Ensure(r >= 0);
} }

View File

@ -8,6 +8,7 @@ class RegisterTurnChoices {
static void RegisterBaseTurnChoice(asIScriptEngine* engine); static void RegisterBaseTurnChoice(asIScriptEngine* engine);
static void RegisterMoveTurnChoice(asIScriptEngine* engine); static void RegisterMoveTurnChoice(asIScriptEngine* engine);
static void RegisterSwitchTurnChoice(asIScriptEngine* engine); static void RegisterSwitchTurnChoice(asIScriptEngine* engine);
static void RegisterFleeTurnChoice(asIScriptEngine* engine);
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* engine);