51 lines
1.9 KiB
C++
51 lines
1.9 KiB
C++
|
#ifndef PKMNLIB_ANGELSCRIPTITEMUSESCRIPT_HPP
|
||
|
#define PKMNLIB_ANGELSCRIPTITEMUSESCRIPT_HPP
|
||
|
|
||
|
#include <CreatureLib/Battling/ScriptHandling/ItemUseScript.hpp>
|
||
|
#include "AngelScriptFunctionCall.hpp"
|
||
|
|
||
|
class AngelScriptResolver;
|
||
|
|
||
|
class AngelScriptItemUseScript final : public CreatureLib::Battling::ItemUseScript {
|
||
|
public:
|
||
|
AngelScriptItemUseScript(asIScriptObject* scriptObject, const AngelScriptResolver* resolver)
|
||
|
: _scriptObject(scriptObject), _resolver(resolver) {}
|
||
|
|
||
|
[[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;
|
||
|
const 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};
|
||
|
}
|
||
|
|
||
|
#define ITEM_USE_SCRIPT_HOOK_FUNCTION(name, decl) FunctionInfo __##name = Initialize(decl);
|
||
|
|
||
|
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
|