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