Adds a bunch of helpers for evolution, as well as custom script evolution methods.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2021-07-09 13:54:42 +02:00
parent 8fc29d925b
commit 9424a209ec
16 changed files with 281 additions and 86 deletions

View File

@@ -0,0 +1,47 @@
#ifndef PKMNLIB_ANGELSCRIPTEVOLUTIONSCRIPT_HPP
#define PKMNLIB_ANGELSCRIPTEVOLUTIONSCRIPT_HPP
#include "../../Battling/Pokemon/Pokemon.hpp"
#include "../../Library/Evolutions/EvolutionData.hpp"
#include "AngelScriptFunctionCall.hpp"
class AngelScriptResolver;
class AngelScriptEvolutionScript final : public PkmnLib::Battling::EvolutionScript {
asIScriptObject* _scriptObject;
AngelScriptResolver* _resolver;
struct FunctionInfo {
bool Exists = false;
asIScriptFunction* Function = nullptr;
};
#define EVO_SCRIPT_HOOK_FUNCTION(name, decl) FunctionInfo __##name = Initialize(decl);
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};
}
EVO_SCRIPT_HOOK_FUNCTION(DoesEvolveFromLevelUp,
"void DoesEvolveFromLevelUp(bool& out, const EvolutionData@ evoData,"
"const Pokemon@ pokemon)");
public:
AngelScriptEvolutionScript(asIScriptObject* scriptObject, AngelScriptResolver* resolver)
: _scriptObject(scriptObject), _resolver(resolver) {}
~AngelScriptEvolutionScript() {
if (_scriptObject != nullptr) {
_scriptObject->Release();
}
}
void DoesEvolveFromLevelUp(const ArbUt::BorrowedPtr<const PkmnLib::Library::EvolutionData>& evolution,
const ArbUt::BorrowedPtr<const PkmnLib::Battling::Pokemon>& pokemon,
bool* out) const override;
};
#endif // PKMNLIB_ANGELSCRIPTEVOLUTIONSCRIPT_HPP