Reworks OnInitialize to have battlelibrary as parameter
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2022-02-12 17:27:39 +01:00
parent 48da191dfb
commit e1d5a12ce0
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
7 changed files with 13 additions and 10 deletions

View File

@ -50,7 +50,7 @@ private:
#define ITEM_USE_SCRIPT_HOOK_FUNCTION(name, decl) FunctionInfo __##name = Initialize(decl); #define ITEM_USE_SCRIPT_HOOK_FUNCTION(name, decl) FunctionInfo __##name = Initialize(decl);
ITEM_USE_SCRIPT_HOOK_FUNCTION(OnInitialize, "void OnInitialize(const narray<EffectParameter@>@ parameters)"); ITEM_USE_SCRIPT_HOOK_FUNCTION(OnInitialize, "void OnInitialize(const BattleLibrary@ library, const narray<EffectParameter@>@ parameters)");
ITEM_USE_SCRIPT_HOOK_FUNCTION(IsItemUsable, "bool IsItemUsable()"); ITEM_USE_SCRIPT_HOOK_FUNCTION(IsItemUsable, "bool IsItemUsable()");
ITEM_USE_SCRIPT_HOOK_FUNCTION(IsPokemonUseItem, "bool IsPokemonUseItem()"); ITEM_USE_SCRIPT_HOOK_FUNCTION(IsPokemonUseItem, "bool IsPokemonUseItem()");
ITEM_USE_SCRIPT_HOOK_FUNCTION(IsUseValidForPokemon, "bool IsUseValidForPokemon(Pokemon@ target)"); ITEM_USE_SCRIPT_HOOK_FUNCTION(IsUseValidForPokemon, "bool IsUseValidForPokemon(Pokemon@ target)");

View File

@ -36,10 +36,12 @@ CScriptHandle* AngelScriptScript::GetAngelscriptOwner() {
return handle; return handle;
} }
void AngelScriptScript::OnInitialize(const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters) { void AngelScriptScript::OnInitialize(const CreatureLib::Battling::BattleLibrary* library,
const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters) {
CALL_HOOK(OnInitialize, { CALL_HOOK(OnInitialize, {
auto arr = GetEffectParameters(parameters); auto arr = GetEffectParameters(parameters);
ctx->SetArgAddress(0, arr); ctx->SetArgObject(0, (void*)library);
ctx->SetArgAddress(1, arr);
}) })
} }
void AngelScriptScript::Stack() { CALL_HOOK(Stack, ); } void AngelScriptScript::Stack() { CALL_HOOK(Stack, ); }
@ -420,7 +422,6 @@ void AngelScriptScript::ModifyOffensiveStatValue(CreatureLib::Battling::Executin
ctx->SetArgByte(2, hitIndex); ctx->SetArgByte(2, hitIndex);
ctx->SetArgAddress(3, modifier); ctx->SetArgAddress(3, modifier);
}) })
} }
void AngelScriptScript::ModifyDefensiveStatValue(CreatureLib::Battling::ExecutingAttack* attack, void AngelScriptScript::ModifyDefensiveStatValue(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target, u8 hitIndex, CreatureLib::Battling::Creature* target, u8 hitIndex,

View File

@ -47,7 +47,8 @@ public:
ContextPool* GetContextPool() { return _ctxPool; } ContextPool* GetContextPool() { return _ctxPool; }
CScriptHandle* GetAngelscriptOwner(); CScriptHandle* GetAngelscriptOwner();
void OnInitialize(const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters) override; void OnInitialize(const CreatureLib::Battling::BattleLibrary*,
const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters) override;
void Stack() override; void Stack() override;
void OnRemove() override; void OnRemove() override;

View File

@ -90,7 +90,8 @@ private:
public: public:
const FunctionInfo& GetGetOwner() const { return __GetOwner; } const FunctionInfo& GetGetOwner() const { return __GetOwner; }
SCRIPT_HOOK_FUNCTION(OnInitialize, "void OnInitialize(const narray<EffectParameter@>@ parameters)"); SCRIPT_HOOK_FUNCTION(OnInitialize,
"void OnInitialize(const BattleLibrary@ library, const narray<EffectParameter@>@ parameters)");
SCRIPT_HOOK_FUNCTION(Stack, "void Stack()"); SCRIPT_HOOK_FUNCTION(Stack, "void Stack()");
SCRIPT_HOOK_FUNCTION(OnRemove, "void OnRemove()"); SCRIPT_HOOK_FUNCTION(OnRemove, "void OnRemove()");
SCRIPT_HOOK_FUNCTION(OnBeforeTurn, "void OnBeforeTurn(BaseTurnChoice@ choice)"); SCRIPT_HOOK_FUNCTION(OnBeforeTurn, "void OnBeforeTurn(BaseTurnChoice@ choice)");

View File

@ -11,7 +11,7 @@ shared abstract class PkmnScript {
protected ref@& GetOwner() { return __owner; }; protected ref@& GetOwner() { return __owner; };
// CreatureLib methods // CreatureLib methods
void OnInitialize(const narray<EffectParameter@>@ parameters){}; void OnInitialize(const BattleLibrary@ library, const narray<EffectParameter@>@ parameters){};
void Stack(){}; void Stack(){};
void OnRemove(){}; void OnRemove(){};
void OnBeforeTurn(BaseTurnChoice@ choice){}; void OnBeforeTurn(BaseTurnChoice@ choice){};

View File

@ -15,7 +15,7 @@ uint64 length = 0;
bool boolValue = false; bool boolValue = false;
int64 intValue = 0; int64 intValue = 0;
constString stringValue; constString stringValue;
void OnInitialize(const narray<EffectParameter@>@ parameters) override { void OnInitialize(const BattleLibrary@ library, const narray<EffectParameter@>@ parameters) override {
length = parameters.Length; length = parameters.Length;
boolValue = parameters[0].AsBool(); boolValue = parameters[0].AsBool();
intValue = parameters[1].AsInt(); intValue = parameters[1].AsInt();
@ -135,7 +135,7 @@ TEST_CASE("Invoke OnInitialize script function") {
new CreatureLib::Library::EffectParameter((int64_t)684), new CreatureLib::Library::EffectParameter((int64_t)684),
new CreatureLib::Library::EffectParameter(ArbUt::StringView("foobar"))}; new CreatureLib::Library::EffectParameter(ArbUt::StringView("foobar"))};
script->OnInitialize(parameters); script->OnInitialize(mainLib, parameters);
auto ctxPool = script->GetContextPool(); auto ctxPool = script->GetContextPool();

View File

@ -19,7 +19,7 @@ class testScript1 : PkmnScript {
} }
} }
void OnInitialize(const narray<EffectParameter@>@ parameters) override{ } void OnInitialize(const BattleLibrary@ library, const narray<EffectParameter@>@ parameters) override { }
} }
} }
)"}}; )"}};