Implements most script hooks
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
#define PKMNLIB_ANGELSCRIPTSCRIPT_HPP
|
||||
#include <Battling/ScriptHandling/Script.hpp>
|
||||
#define ANGELSCRIPT_DLL_LIBRARY_IMPORT
|
||||
#include <angelscript.h>
|
||||
#include <Core/Exceptions/NotImplementedException.hpp>
|
||||
#include <angelscript.h>
|
||||
#include "AngelScriptTypeInfo.hpp"
|
||||
#include "ContextPool.hpp"
|
||||
|
||||
@@ -46,11 +46,11 @@ public:
|
||||
void Stack() override { CALLHOOK(Stack, {}); }
|
||||
|
||||
void OnBeforeTurn(const CreatureLib::Battling::BaseTurnChoice* choice) override {
|
||||
throw NotImplementedException(); //TODO
|
||||
throw NotImplementedException(); // TODO
|
||||
}
|
||||
|
||||
void ChangeAttack(CreatureLib::Battling::AttackTurnChoice* choice, std::string* outAttack) override {
|
||||
throw NotImplementedException(); //TODO
|
||||
throw NotImplementedException(); // TODO
|
||||
}
|
||||
|
||||
void PreventAttack(CreatureLib::Battling::ExecutingAttack* attack, bool* outResult) override {
|
||||
@@ -74,41 +74,82 @@ public:
|
||||
})
|
||||
}
|
||||
|
||||
void OnBeforeAttack(CreatureLib::Battling::ExecutingAttack* attack) override { Script::OnBeforeAttack(attack); }
|
||||
void OnBeforeAttack(CreatureLib::Battling::ExecutingAttack* attack) override {
|
||||
CALLHOOK(OnBeforeAttack, { ctx->SetArgObject(0, (void*)attack); })
|
||||
}
|
||||
|
||||
void FailIncomingAttack(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
||||
bool* outResult) override {
|
||||
Script::FailIncomingAttack(attack, target, outResult);
|
||||
CALLHOOK(FailIncomingAttack, {
|
||||
ctx->SetArgObject(0, (void*)attack);
|
||||
ctx->SetArgObject(1, (void*)target);
|
||||
ctx->SetArgAddress(2, outResult);
|
||||
})
|
||||
}
|
||||
void IsInvulnerable(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
||||
bool* outResult) override {
|
||||
Script::IsInvulnerable(attack, target, outResult);
|
||||
CALLHOOK(IsInvulnerable, {
|
||||
ctx->SetArgObject(0, (void*)attack);
|
||||
ctx->SetArgObject(1, (void*)target);
|
||||
ctx->SetArgAddress(2, outResult);
|
||||
})
|
||||
}
|
||||
void OnAttackMiss(CreatureLib::Battling::ExecutingAttack* attack,
|
||||
CreatureLib::Battling::Creature* target) override {
|
||||
Script::OnAttackMiss(attack, target);
|
||||
CALLHOOK(OnAttackMiss, {
|
||||
ctx->SetArgObject(0, (void*)attack);
|
||||
ctx->SetArgObject(1, (void*)target);
|
||||
})
|
||||
}
|
||||
|
||||
void ChangeAttackType(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
||||
uint8_t hitNumber, uint8_t* outType) override {
|
||||
Script::ChangeAttackType(attack, target, hitNumber, outType);
|
||||
CALLHOOK(ChangeAttackType, {
|
||||
ctx->SetArgObject(0, (void*)attack);
|
||||
ctx->SetArgObject(1, (void*)target);
|
||||
ctx->SetArgByte(2, hitNumber);
|
||||
ctx->SetArgAddress(3, outType);
|
||||
})
|
||||
}
|
||||
|
||||
void OnStatusMove(const CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
||||
uint8_t hitNumber) override {
|
||||
Script::OnStatusMove(attack, target, hitNumber);
|
||||
CALLHOOK(OnStatusMove, {
|
||||
ctx->SetArgObject(0, (void*)attack);
|
||||
ctx->SetArgObject(1, (void*)target);
|
||||
ctx->SetArgByte(2, hitNumber);
|
||||
})
|
||||
}
|
||||
|
||||
void PreventSecondaryEffects(const CreatureLib::Battling::ExecutingAttack* attack,
|
||||
CreatureLib::Battling::Creature* target, uint8_t hitNumber, bool* outResult) override {
|
||||
Script::PreventSecondaryEffects(attack, target, hitNumber, outResult);
|
||||
CALLHOOK(PreventSecondaryEffects, {
|
||||
ctx->SetArgObject(0, (void*)attack);
|
||||
ctx->SetArgObject(1, (void*)target);
|
||||
ctx->SetArgByte(2, hitNumber);
|
||||
ctx->SetArgAddress(3, outResult);
|
||||
})
|
||||
}
|
||||
|
||||
void OnSecondaryEffect(const CreatureLib::Battling::ExecutingAttack* attack,
|
||||
CreatureLib::Battling::Creature* target, uint8_t hitNumber) override {
|
||||
Script::OnSecondaryEffect(attack, target, hitNumber);
|
||||
CALLHOOK(OnSecondaryEffect, {
|
||||
ctx->SetArgObject(0, (void*)attack);
|
||||
ctx->SetArgObject(1, (void*)target);
|
||||
ctx->SetArgByte(2, hitNumber);
|
||||
})
|
||||
}
|
||||
|
||||
void OnAfterHits(const CreatureLib::Battling::ExecutingAttack* attack,
|
||||
CreatureLib::Battling::Creature* target) override {
|
||||
Script::OnAfterHits(attack, target);
|
||||
CALLHOOK(OnAfterHits, {
|
||||
ctx->SetArgObject(0, (void*)attack);
|
||||
ctx->SetArgObject(1, (void*)target);
|
||||
})
|
||||
}
|
||||
|
||||
void PreventSelfSwitch(const CreatureLib::Battling::SwitchTurnChoice* choice, bool* outResult) override {
|
||||
Script::PreventSelfSwitch(choice, outResult);
|
||||
throw NotImplementedException(); // TODO
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@ private:
|
||||
|
||||
FunctionInfo Initialize(const std::string& decl) {
|
||||
auto val = _type->GetMethodByDecl(decl.c_str(), false);
|
||||
if (val == nullptr){
|
||||
if (val == nullptr) {
|
||||
return FunctionInfo{.Exists = false, .Function = nullptr};
|
||||
}
|
||||
if (!val->IsOverride()){
|
||||
if (!val->IsOverride()) {
|
||||
return FunctionInfo{.Exists = false, .Function = nullptr};
|
||||
}
|
||||
return FunctionInfo{.Exists = true, .Function = val};
|
||||
@@ -62,15 +62,31 @@ public:
|
||||
return obj;
|
||||
}
|
||||
|
||||
#define SCRIPT_HOOK_FUNCTION(name, decl) \
|
||||
private: FunctionInfo __##name = Initialize(decl); \
|
||||
public: const FunctionInfo& Get##name() const { return __##name; }
|
||||
|
||||
SCRIPT_HOOK_FUNCTION(Stack, "void Stack()");
|
||||
SCRIPT_HOOK_FUNCTION(PreventAttack, "void PreventAttack(ExecutingMove@ attack, bool& result)");
|
||||
SCRIPT_HOOK_FUNCTION(FailAttack, "void FailAttack(ExecutingMove@ attack, bool& result)");
|
||||
SCRIPT_HOOK_FUNCTION(StopBeforeAttack, "void StopBeforeAttack(ExecutingMove@ attack, bool& result)");
|
||||
#define SCRIPT_HOOK_FUNCTION(name, decl) \
|
||||
private: \
|
||||
FunctionInfo __##name = Initialize(decl); \
|
||||
\
|
||||
public: \
|
||||
const FunctionInfo& Get##name() const { return __##name; }
|
||||
|
||||
SCRIPT_HOOK_FUNCTION(Stack, "void Stack()");
|
||||
SCRIPT_HOOK_FUNCTION(PreventAttack, "void PreventAttack(ExecutingMove@ attack, bool& result)");
|
||||
SCRIPT_HOOK_FUNCTION(FailAttack, "void FailAttack(ExecutingMove@ attack, bool& result)");
|
||||
SCRIPT_HOOK_FUNCTION(StopBeforeAttack, "void StopBeforeAttack(ExecutingMove@ attack, bool& result)");
|
||||
SCRIPT_HOOK_FUNCTION(OnBeforeAttack, "void OnBeforeAttack(ExecutingMove@ attack)");
|
||||
SCRIPT_HOOK_FUNCTION(FailIncomingAttack,
|
||||
"void FailIncomingAttack(ExecutingMove@ attack, Pokemon@ target, bool& result)");
|
||||
SCRIPT_HOOK_FUNCTION(IsInvulnerable, "void IsInvulnerable(ExecutingMove@ attack, Pokemon@ target, bool& result)");
|
||||
SCRIPT_HOOK_FUNCTION(OnAttackMiss, "void OnAttackMiss(ExecutingMove@ attack, Pokemon@ target)");
|
||||
SCRIPT_HOOK_FUNCTION(ChangeAttackType,
|
||||
"void ChangeAttackType(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& outType)");
|
||||
SCRIPT_HOOK_FUNCTION(OnStatusMove, "void OnStatusMove(ExecutingMove@ attack, Pokemon@ target, uint8 hit)");
|
||||
SCRIPT_HOOK_FUNCTION(
|
||||
PreventSecondaryEffects,
|
||||
"void PreventSecondaryEffects(ExecutingMove@ attack, Pokemon@ target, uint8 hit, bool& outResult)");
|
||||
SCRIPT_HOOK_FUNCTION(OnSecondaryEffect,
|
||||
"void OnSecondaryEffect(ExecutingMove@ attack, Pokemon@ target, uint8 hit)");
|
||||
SCRIPT_HOOK_FUNCTION(OnAfterHits, "void OnAfterHits(ExecutingMove@ attack, Pokemon@ target)");
|
||||
};
|
||||
|
||||
#undef SCRIPT_HOOK_FUNCTION
|
||||
|
||||
@@ -2,12 +2,24 @@
|
||||
#include <cassert>
|
||||
|
||||
void BasicScriptClass::Register(asIScriptEngine* engine) {
|
||||
// As far as I am aware at the moment you can't create an abstract class with virtual members through the application
|
||||
// registry interface. As such, we just create it from string.
|
||||
[[maybe_unused]] int r = engine->GetModuleByIndex(0)->AddScriptSection("PkmnScript", R"(
|
||||
shared abstract class PkmnScript {
|
||||
void Stack(){};
|
||||
void PreventAttack(ExecutingMove@ attack, bool& result){};
|
||||
void FailAttack(ExecutingMove@ attack, bool& result){};
|
||||
void StopBeforeAttack(ExecutingMove@ attack, bool& result){};
|
||||
void OnBeforeAttack(ExecutingMove@ attack){};
|
||||
void FailIncomingAttack(ExecutingMove@ attack, Pokemon@ target, bool& result){};
|
||||
void IsInvulnerable(ExecutingMove@ attack, Pokemon@ target, bool& result){};
|
||||
void OnAttackMiss(ExecutingMove@ attack, Pokemon@ target){};
|
||||
void ChangeAttackType(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& outType){};
|
||||
void OnStatusMove(ExecutingMove@ attack, Pokemon@ target, uint8 hit){};
|
||||
void PreventSecondaryEffects(ExecutingMove@ attack, Pokemon@ target, uint8 hit, bool& outResult){};
|
||||
void OnSecondaryEffect(ExecutingMove@ attack, Pokemon@ target, uint8 hit){};
|
||||
void OnAfterHits(ExecutingMove@ attack, Pokemon@ target){};
|
||||
|
||||
}
|
||||
)");
|
||||
assert(r >= 0);
|
||||
|
||||
Reference in New Issue
Block a user