PkmnLib/src/ScriptResolving/AngelScript/AngelScriptItemUseScript.hpp

61 lines
2.4 KiB
C++
Raw Normal View History

#ifndef PKMNLIB_ANGELSCRIPTITEMUSESCRIPT_HPP
#define PKMNLIB_ANGELSCRIPTITEMUSESCRIPT_HPP
#include <CreatureLib/Battling/ScriptHandling/ItemUseScript.hpp>
#include "../../../extern/angelscript_addons/scriptarray/scriptarray.h"
class AngelScriptResolver;
class AngelScriptItemUseScript final : public CreatureLib::Battling::ItemUseScript {
public:
AngelScriptItemUseScript(asIScriptObject* scriptObject, AngelScriptResolver* resolver)
: _scriptObject(scriptObject), _resolver(resolver) {}
~AngelScriptItemUseScript() {
if (_scriptObject != nullptr) {
2021-03-07 17:20:42 +00:00
_scriptObject->Release();
}
}
void OnInitialize(const ArbUt::List<CreatureLib::Library::EffectParameter*>& 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};
}
CScriptArray* GetEffectParameters(const ArbUt::List<CreatureLib::Library::EffectParameter*>& ls);
#define ITEM_USE_SCRIPT_HOOK_FUNCTION(name, decl) FunctionInfo __##name = Initialize(decl);
ITEM_USE_SCRIPT_HOOK_FUNCTION(OnInitialize, "void OnInitialize(const array<EffectParameter@> &in 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