2020-01-26 14:18:04 +00:00
|
|
|
#include "RegisterPokemonClass.hpp"
|
2020-04-19 11:20:14 +00:00
|
|
|
#include <Arbutils/Assert.hpp>
|
2020-04-28 12:48:56 +00:00
|
|
|
#include <CreatureLib/Battling/Models/LearnedAttack.hpp>
|
2020-02-02 11:23:50 +00:00
|
|
|
#include "../../../../../extern/angelscript_addons/scriptarray/scriptarray.h"
|
2020-04-19 11:20:14 +00:00
|
|
|
#include "../../../../Battling/PkmnDamageSource.hpp"
|
2020-04-28 12:48:56 +00:00
|
|
|
#include "../../../../Battling/Pokemon/Pokemon.hpp"
|
2020-05-27 15:26:25 +00:00
|
|
|
#include "../HelperFile.hpp"
|
2020-01-26 14:18:04 +00:00
|
|
|
|
|
|
|
// Hack to handle AngelScript not recognizing different sized enums on fields, and returning invalid values due to it.
|
|
|
|
#define ENUM__SIZE_WRAPPER(name, type, func) \
|
|
|
|
int32_t name(type* obj) { return static_cast<int32_t>(obj->func()); }
|
|
|
|
|
|
|
|
void RegisterPokemonClass::Register(asIScriptEngine* engine) {
|
|
|
|
RegisterDamageSource(engine);
|
|
|
|
RegisterMoveLearnMethod(engine);
|
|
|
|
RegisterLearnedAttack(engine);
|
|
|
|
RegisterPokemonType(engine);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegisterPokemonClass::RegisterDamageSource(asIScriptEngine* engine) {
|
|
|
|
[[maybe_unused]] int r = engine->RegisterEnum("DamageSource");
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-04-28 12:48:56 +00:00
|
|
|
for (auto v : CreatureLib::Battling::DamageSourceHelper::GetValues()) {
|
|
|
|
r = engine->RegisterEnumValue("DamageSource", CreatureLib::Battling::DamageSourceHelper::ToString(v), (int)v);
|
2020-04-19 11:20:14 +00:00
|
|
|
}
|
2020-04-28 12:48:56 +00:00
|
|
|
for (auto v : PkmnDamageSourceHelper::GetValues()) {
|
|
|
|
r = engine->RegisterEnumValue("DamageSource", PkmnDamageSourceHelper::ToString(v), (int)v);
|
2020-04-19 11:20:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegisterPokemonClass::RegisterMoveLearnMethod(asIScriptEngine* engine) {
|
|
|
|
[[maybe_unused]] int r = engine->RegisterEnum("MoveLearnMethod");
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterEnumValue("MoveLearnMethod", "Unknown", (int)CreatureLib::Battling::AttackLearnMethod::Unknown);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterEnumValue("MoveLearnMethod", "Level", (int)CreatureLib::Battling::AttackLearnMethod::Level);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ENUM__SIZE_WRAPPER(LearnedMove_LearnMethodWrapper, CreatureLib::Battling::LearnedAttack, GetLearnMethod)
|
2020-06-02 19:52:34 +00:00
|
|
|
SMART_PTR_GETTER_FUNC(CreatureLib::Battling::LearnedAttack, const CreatureLib::Library::AttackData, GetAttack);
|
2020-01-26 14:18:04 +00:00
|
|
|
|
|
|
|
void RegisterPokemonClass::RegisterLearnedAttack(asIScriptEngine* engine) {
|
|
|
|
[[maybe_unused]] int r = engine->RegisterObjectType("LearnedMove", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterObjectMethod("LearnedMove", "const MoveData@ get_MoveData() const property",
|
2020-06-02 19:52:34 +00:00
|
|
|
asFUNCTION(GetAttackWrapper), asCALL_CDECL_OBJFIRST);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterObjectMethod("LearnedMove", "uint8 get_MaxUses() const property",
|
|
|
|
asMETHOD(CreatureLib::Battling::LearnedAttack, GetMaxUses), asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterObjectMethod("LearnedMove", "uint8 get_RemainingUses() const property",
|
|
|
|
asMETHOD(CreatureLib::Battling::LearnedAttack, GetRemainingUses), asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterObjectMethod("LearnedMove", "Gender get_LearnMethod() const property",
|
|
|
|
asFUNCTION(LearnedMove_LearnMethodWrapper), asCALL_CDECL_OBJLAST);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ENUM__SIZE_WRAPPER(Pkmn_GenderWrapper, PkmnLib::Battling::Pokemon, GetGender)
|
|
|
|
|
2020-02-02 12:57:41 +00:00
|
|
|
CScriptArray* GetMoves(const PkmnLib::Battling::Pokemon* obj) {
|
|
|
|
asIScriptContext* ctx = asGetActiveContext();
|
|
|
|
if (ctx) {
|
|
|
|
asIScriptEngine* engine = ctx->GetEngine();
|
|
|
|
asITypeInfo* t = engine->GetTypeInfoByDecl("array<LearnedMove@>");
|
|
|
|
auto a = obj->GetMoves();
|
2020-04-18 11:43:05 +00:00
|
|
|
CScriptArray* arr = CScriptArray::Create(t, a.Count());
|
|
|
|
for (size_t i = 0; i < a.Count(); i++) {
|
2020-02-02 12:57:41 +00:00
|
|
|
arr->SetValue(i, &a[i]);
|
|
|
|
}
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-04-10 14:03:15 +00:00
|
|
|
static bool HasHeldItem(const PkmnLib::Battling::Pokemon* obj, const ConstString& str) {
|
|
|
|
return obj->HasHeldItem(str.GetHash());
|
2020-04-06 18:03:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 15:26:25 +00:00
|
|
|
SMART_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const CreatureLib::Library::CreatureSpecies, GetSpecies);
|
|
|
|
SMART_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const PkmnLib::Library::PokemonForme, GetForme);
|
|
|
|
SMART_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const CreatureLib::Library::Item, GetHeldItem);
|
|
|
|
|
2020-01-26 14:18:04 +00:00
|
|
|
void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
|
2020-02-01 15:56:09 +00:00
|
|
|
[[maybe_unused]] int r = engine->RegisterObjectType("Pokemon", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "const Species@ get_Species() const property",
|
2020-05-27 15:26:25 +00:00
|
|
|
asFUNCTION(GetSpeciesWrapper), asCALL_CDECL_OBJLAST);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-05-27 15:26:25 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "const Forme@ get_Forme() const property", asFUNCTION(GetFormeWrapper),
|
|
|
|
asCALL_CDECL_OBJLAST);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "uint8 get_Level() const property",
|
|
|
|
asMETHOD(PkmnLib::Battling::Pokemon, GetLevel), asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "uint32 get_Experience() const property",
|
|
|
|
asMETHOD(PkmnLib::Battling::Pokemon, GetExperience), asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "Gender get_Gender() const property", asFUNCTION(Pkmn_GenderWrapper),
|
|
|
|
asCALL_CDECL_OBJLAST);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "uint8 get_Coloring() const property",
|
|
|
|
asMETHOD(PkmnLib::Battling::Pokemon, GetColoring), asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-02-01 15:56:09 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "bool get_Shiny() const property",
|
|
|
|
asMETHOD(PkmnLib::Battling::Pokemon, IsShiny), asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "const Item@ get_HeldItem() const property",
|
2020-05-27 15:26:25 +00:00
|
|
|
asFUNCTION(GetHeldItemWrapper), asCALL_CDECL_OBJLAST);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-04-07 10:04:23 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "bool HasHeldItem(const constString &in name) const",
|
2020-04-10 14:03:15 +00:00
|
|
|
asFUNCTION(HasHeldItem), asCALL_CDECL_OBJFIRST);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-02-27 17:59:15 +00:00
|
|
|
r = engine->RegisterObjectMethod(
|
|
|
|
"Pokemon", "void SetHeldItem(const string &in name)",
|
2020-05-27 15:26:25 +00:00
|
|
|
asMETHODPR(PkmnLib::Battling::Pokemon, SetHeldItem, (const ArbUt::CaseInsensitiveConstString&), void),
|
2020-02-27 17:59:15 +00:00
|
|
|
asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-05-27 15:26:25 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "void SetHeldItem(const Item@ item)",
|
|
|
|
asMETHODPR(PkmnLib::Battling::Pokemon, SetHeldItem,
|
|
|
|
(const ArbUt::BorrowedPtr<const CreatureLib::Library::Item>&), void),
|
|
|
|
asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "uint32 get_CurrentHealth() const property",
|
|
|
|
asMETHOD(PkmnLib::Battling::Pokemon, GetCurrentHealth), asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "const string& get_Nickname() const property",
|
|
|
|
asMETHOD(PkmnLib::Battling::Pokemon, GetNickname), asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-04-07 10:04:23 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "const constString& get_ActiveAbility() const property",
|
2020-01-26 14:18:04 +00:00
|
|
|
asMETHOD(PkmnLib::Battling::Pokemon, GetActiveTalent), asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "bool get_IsFainted() const property",
|
|
|
|
asMETHOD(PkmnLib::Battling::Pokemon, IsFainted), asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "bool HasType(uint8 type) const",
|
|
|
|
asMETHOD(PkmnLib::Battling::Pokemon, HasType), asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-02-13 14:15:07 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "uint32 get_MaxHealth() const property",
|
|
|
|
asMETHOD(PkmnLib::Battling::Pokemon, GetMaxHealth), asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "void Damage(uint32 type, DamageSource source)",
|
|
|
|
asMETHOD(PkmnLib::Battling::Pokemon, Damage), asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-02-17 16:35:14 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "void Heal(uint32 type)", asMETHOD(PkmnLib::Battling::Pokemon, Heal),
|
|
|
|
asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "void OverrideActiveAbility(const string &in ability)",
|
|
|
|
asMETHOD(PkmnLib::Battling::Pokemon, OverrideActiveTalent), asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-02-17 16:35:14 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "LearnedMove@[]@ GetMoves() const", asFUNCTION(GetMoves),
|
|
|
|
asCALL_CDECL_OBJLAST);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-02-16 15:55:46 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "void ChangeStatBoost(Statistic stat, int8 amount)",
|
2020-02-16 16:00:52 +00:00
|
|
|
asMETHOD(PkmnLib::Battling::Pokemon, ChangeStatBoost), asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "const Species@ get_DisplaySpecies() const property",
|
|
|
|
asMETHOD(PkmnLib::Battling::Pokemon, GetDisplaySpecies), asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "const Species@ get_DisplayForme() const property",
|
|
|
|
asMETHOD(PkmnLib::Battling::Pokemon, GetDisplayVariant), asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "uint32 GetFlatStat(Statistic stat) const",
|
|
|
|
asMETHOD(PkmnLib::Battling::Pokemon, GetFlatStat), asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "uint32 GetBoostedStat(Statistic stat) const",
|
|
|
|
asMETHOD(PkmnLib::Battling::Pokemon, GetBoostedStat), asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "uint32 GetBaseStat(Statistic stat) const",
|
|
|
|
asMETHOD(PkmnLib::Battling::Pokemon, GetBaseStat), asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
r = engine->RegisterObjectMethod("Pokemon", "int8 GetStatBoost(Statistic stat) const",
|
|
|
|
asMETHOD(PkmnLib::Battling::Pokemon, GetStatBoost), asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-02-22 15:10:22 +00:00
|
|
|
r = engine->RegisterObjectMethod(
|
2020-04-07 10:04:23 +00:00
|
|
|
"Pokemon", "void AddVolatile(const constString &in name) const",
|
2020-02-28 18:51:50 +00:00
|
|
|
asMETHODPR(PkmnLib::Battling::Pokemon, AddVolatileScript, (const ConstString&), void), asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-02-23 11:46:44 +00:00
|
|
|
r = engine->RegisterObjectMethod(
|
2020-04-07 10:04:23 +00:00
|
|
|
"Pokemon", "void RemoveVolatile(const constString &in name) const",
|
2020-02-28 18:51:50 +00:00
|
|
|
asMETHODPR(PkmnLib::Battling::Pokemon, RemoveVolatileScript, (const ConstString&), void), asCALL_THISCALL);
|
2020-04-19 11:20:14 +00:00
|
|
|
Assert(r >= 0);
|
2020-01-26 14:18:04 +00:00
|
|
|
}
|