#ifndef PKMNLIB_ANGELSCRIPTITEMUSESCRIPT_HPP #define PKMNLIB_ANGELSCRIPTITEMUSESCRIPT_HPP #include #include #include "TypeRegistry/NativeArray.hpp" class AngelScriptResolver; class AngelScriptItemUseScript final : public CreatureLib::Battling::ItemUseScript { public: AngelScriptItemUseScript(asIScriptObject* scriptObject, AngelScriptResolver* resolver) : _scriptObject(scriptObject), _resolver(resolver) {} ~AngelScriptItemUseScript() { if (_scriptObject != nullptr) { _scriptObject->Release(); } } void OnInitialize(const ArbUt::List& parameters) override; [[nodiscard]] bool IsItemUsable() const override; [[nodiscard]] bool IsCreatureUseItem() const override; bool IsUseValidForCreature(CreatureLib::Battling::Creature* creature) const override; bool IsHoldable() const override; void OnUse() const override; void OnCreatureUse(CreatureLib::Battling::Creature* creature) const override; private: asIScriptObject* _scriptObject; AngelScriptResolver* _resolver; struct FunctionInfo { bool Exists = false; asIScriptFunction* Function = nullptr; }; FunctionInfo Initialize(const std::string& decl) { auto val = _scriptObject->GetObjectType()->GetMethodByDecl(decl.c_str(), false); if (val == nullptr) { return FunctionInfo{.Exists = false, .Function = nullptr}; } return FunctionInfo{.Exists = true, .Function = val}; } NativeArray>* GetEffectParameters(const ArbUt::List& ls); #define ITEM_USE_SCRIPT_HOOK_FUNCTION(name, decl) FunctionInfo __##name = Initialize(decl); ITEM_USE_SCRIPT_HOOK_FUNCTION(OnInitialize, "void OnInitialize(const narray@ parameters)"); ITEM_USE_SCRIPT_HOOK_FUNCTION(IsItemUsable, "bool IsItemUsable()"); ITEM_USE_SCRIPT_HOOK_FUNCTION(IsPokemonUseItem, "bool IsPokemonUseItem()"); ITEM_USE_SCRIPT_HOOK_FUNCTION(IsUseValidForPokemon, "bool IsUseValidForPokemon(Pokemon@ target)"); ITEM_USE_SCRIPT_HOOK_FUNCTION(IsHoldable, "bool IsHoldable()"); ITEM_USE_SCRIPT_HOOK_FUNCTION(OnUse, "void OnUse()"); ITEM_USE_SCRIPT_HOOK_FUNCTION(OnPokemonUse, "void OnPokemonUse(Pokemon@ target)"); }; #endif // PKMNLIB_ANGELSCRIPTITEMUSESCRIPT_HPP