2020-02-16 15:43:37 +00:00
|
|
|
#include "RegisterBattleClass.hpp"
|
|
|
|
#include <CreatureLib/Battling/Models/Battle.hpp>
|
2021-03-26 14:28:24 +00:00
|
|
|
#include <CreatureLib/Battling/Models/BattleSide.hpp>
|
2022-02-11 11:17:27 +00:00
|
|
|
#include <scripthandle/scripthandle.h>
|
2022-03-25 18:08:42 +00:00
|
|
|
#include <type_traits>
|
2020-04-18 13:35:01 +00:00
|
|
|
#include "../../../../Battling/Battle/Battle.hpp"
|
2021-03-28 14:16:47 +00:00
|
|
|
#include "../../../../Battling/Pokemon/Pokemon.hpp"
|
2021-03-28 15:55:45 +00:00
|
|
|
#include "../../AngelScriptResolver.hpp"
|
2021-09-22 17:02:01 +00:00
|
|
|
#include "../../AngelscriptUserdata.hpp"
|
2020-06-02 19:52:34 +00:00
|
|
|
#include "../HelperFile.hpp"
|
2020-02-16 15:43:37 +00:00
|
|
|
|
2022-03-25 18:08:42 +00:00
|
|
|
void RegisterBattleClass::Register(asIScriptEngine* non_null engine) {
|
2020-02-22 14:22:13 +00:00
|
|
|
RegisterChoiceQueue(engine);
|
2020-02-16 15:43:37 +00:00
|
|
|
RegisterBattleRandom(engine);
|
2021-03-26 14:28:24 +00:00
|
|
|
RegisterBattleSide(engine);
|
2020-02-16 15:43:37 +00:00
|
|
|
RegisterBattle(engine);
|
|
|
|
}
|
2020-02-22 14:22:13 +00:00
|
|
|
|
2022-03-25 18:08:42 +00:00
|
|
|
void RegisterBattleClass::RegisterChoiceQueue(asIScriptEngine* non_null engine) {
|
2020-02-22 14:22:13 +00:00
|
|
|
[[maybe_unused]] int r = engine->RegisterObjectType("ChoiceQueue", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
2020-12-13 11:32:52 +00:00
|
|
|
Ensure(r >= 0);
|
2020-02-22 14:22:13 +00:00
|
|
|
r = engine->RegisterObjectMethod("ChoiceQueue", "bool MovePokemonChoiceNext(Pokemon@ target)",
|
|
|
|
asMETHOD(CreatureLib::Battling::ChoiceQueue, MoveCreatureChoiceNext),
|
|
|
|
asCALL_THISCALL);
|
2020-12-13 11:32:52 +00:00
|
|
|
Ensure(r >= 0);
|
2020-02-22 14:26:16 +00:00
|
|
|
r = engine->RegisterObjectMethod("ChoiceQueue", "const BaseTurnChoice@ Peek() const",
|
2020-02-22 15:10:22 +00:00
|
|
|
asMETHOD(CreatureLib::Battling::ChoiceQueue, Peek), asCALL_THISCALL);
|
2020-12-13 11:32:52 +00:00
|
|
|
Ensure(r >= 0);
|
2021-11-19 15:18:40 +00:00
|
|
|
r = engine->RegisterObjectMethod("ChoiceQueue", "bool HasNext() const",
|
|
|
|
asMETHOD(CreatureLib::Battling::ChoiceQueue, HasNext), asCALL_THISCALL);
|
|
|
|
Ensure(r >= 0);
|
2020-02-22 14:22:13 +00:00
|
|
|
}
|
|
|
|
|
2022-03-25 18:08:42 +00:00
|
|
|
void RegisterBattleClass::RegisterBattleRandom(asIScriptEngine* non_null engine) {
|
2020-02-16 15:43:37 +00:00
|
|
|
[[maybe_unused]] int r = engine->RegisterObjectType("BattleRandom", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
2020-12-13 11:32:52 +00:00
|
|
|
Ensure(r >= 0);
|
2020-02-16 15:43:37 +00:00
|
|
|
r = engine->RegisterObjectMethod("BattleRandom",
|
2020-02-17 09:34:11 +00:00
|
|
|
"bool EffectChance(float chance, ExecutingMove@ move, Pokemon@ target )",
|
2020-02-16 15:43:37 +00:00
|
|
|
asMETHOD(CreatureLib::Battling::BattleRandom, EffectChance), asCALL_THISCALL);
|
2020-12-13 11:32:52 +00:00
|
|
|
Ensure(r >= 0);
|
2020-02-16 15:43:37 +00:00
|
|
|
r = engine->RegisterObjectMethod("BattleRandom", "int Get()",
|
|
|
|
asMETHODPR(CreatureLib::Battling::BattleRandom, Get, (), int32_t),
|
|
|
|
asCALL_THISCALL);
|
2020-12-13 11:32:52 +00:00
|
|
|
Ensure(r >= 0);
|
2020-02-16 15:43:37 +00:00
|
|
|
r = engine->RegisterObjectMethod("BattleRandom", "int Get(int max)",
|
|
|
|
asMETHODPR(CreatureLib::Battling::BattleRandom, Get, (int32_t), int32_t),
|
|
|
|
asCALL_THISCALL);
|
2020-12-13 11:32:52 +00:00
|
|
|
Ensure(r >= 0);
|
2020-02-16 15:43:37 +00:00
|
|
|
r = engine->RegisterObjectMethod("BattleRandom", "int Get(int min, int max)",
|
|
|
|
asMETHODPR(CreatureLib::Battling::BattleRandom, Get, (int32_t, int32_t), int32_t),
|
|
|
|
asCALL_THISCALL);
|
2020-12-13 11:32:52 +00:00
|
|
|
Ensure(r >= 0);
|
2020-02-16 15:43:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-25 18:08:42 +00:00
|
|
|
CreatureLib::Battling::BattleSide* GetBattleSideWrapper(PkmnLib::Battling::Battle* non_null battle, u8 index) {
|
|
|
|
EnsureNotNull(battle);
|
2021-03-26 14:28:24 +00:00
|
|
|
return battle->GetSides()[index];
|
|
|
|
}
|
|
|
|
|
2022-03-25 18:08:42 +00:00
|
|
|
CreatureLib::Battling::BattleParty* GetPartyWrapper(PkmnLib::Battling::Battle* non_null battle, u8 index) {
|
|
|
|
EnsureNotNull(battle);
|
2021-05-08 10:12:36 +00:00
|
|
|
return battle->GetParties()[index];
|
|
|
|
}
|
|
|
|
|
2022-03-25 18:08:42 +00:00
|
|
|
CreatureLib::Battling::BattleParty* FindPartyWrapper(PkmnLib::Battling::Battle* non_null battle,
|
|
|
|
PkmnLib::Battling::Pokemon* non_null p) {
|
|
|
|
EnsureNotNull(battle);
|
|
|
|
EnsureNotNull(p);
|
2021-05-08 10:12:36 +00:00
|
|
|
auto v = battle->FindPartyForCreature(p);
|
|
|
|
if (v.HasValue()) {
|
|
|
|
return v.GetValue();
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2022-03-25 18:08:42 +00:00
|
|
|
static CScriptHandle Battle_AddVolatileWrapper(PkmnLib::Battling::Battle* non_null obj, const ArbUt::StringView& name) {
|
|
|
|
EnsureNotNull(obj);
|
2021-03-28 15:55:45 +00:00
|
|
|
auto handle = CScriptHandle();
|
|
|
|
auto* resolver = static_cast<AngelScriptResolver*>(obj->GetLibrary()->GetScriptResolver().get());
|
|
|
|
auto script = static_cast<AngelScriptScript*>(obj->AddVolatileScript(name))->GetRawAngelscriptObject();
|
|
|
|
handle.Set(script, resolver->GetBaseType("PkmnScript"));
|
|
|
|
return handle;
|
2021-03-27 21:19:18 +00:00
|
|
|
}
|
|
|
|
|
2022-03-25 18:08:42 +00:00
|
|
|
static CScriptHandle Battle_GetVolatileWrapper(PkmnLib::Battling::Battle* non_null obj, const ArbUt::StringView& name) {
|
|
|
|
EnsureNotNull(obj);
|
2021-10-30 14:35:23 +00:00
|
|
|
auto handle = CScriptHandle();
|
|
|
|
auto* resolver = static_cast<AngelScriptResolver*>(obj->GetLibrary()->GetScriptResolver().get());
|
|
|
|
auto* s = static_cast<AngelScriptScript*>(obj->GetVolatileScript(name).GetValue());
|
|
|
|
if (s == nullptr) {
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
auto* script = s->GetRawAngelscriptObject();
|
|
|
|
handle.Set(script, resolver->GetBaseType("PkmnScript"));
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2022-03-25 18:08:42 +00:00
|
|
|
static CScriptHandle BattleSide_AddVolatileWrapper(CreatureLib::Battling::BattleSide* non_null obj,
|
2021-10-28 14:27:59 +00:00
|
|
|
const ArbUt::StringView& name) {
|
2022-03-25 18:08:42 +00:00
|
|
|
EnsureNotNull(obj);
|
2021-10-28 14:27:59 +00:00
|
|
|
auto handle = CScriptHandle();
|
|
|
|
auto* resolver = static_cast<AngelScriptResolver*>(obj->GetBattle()->GetLibrary()->GetScriptResolver().get());
|
|
|
|
auto script = static_cast<AngelScriptScript*>(obj->AddVolatileScript(name))->GetRawAngelscriptObject();
|
|
|
|
handle.Set(script, resolver->GetBaseType("PkmnScript"));
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2022-03-25 18:08:42 +00:00
|
|
|
static CScriptHandle BattleSide_GetVolatileWrapper(CreatureLib::Battling::BattleSide* non_null obj,
|
2021-10-30 14:35:23 +00:00
|
|
|
const ArbUt::StringView& name) {
|
2022-03-25 18:08:42 +00:00
|
|
|
EnsureNotNull(obj);
|
2021-10-30 14:35:23 +00:00
|
|
|
auto handle = CScriptHandle();
|
|
|
|
auto* resolver = static_cast<AngelScriptResolver*>(obj->GetBattle()->GetLibrary()->GetScriptResolver().get());
|
2022-03-25 18:08:42 +00:00
|
|
|
auto s = obj->GetVolatileScript(name).ForceAs<AngelScriptScript>();
|
|
|
|
if (!s.HasValue()) {
|
2021-10-30 14:35:23 +00:00
|
|
|
return handle;
|
|
|
|
}
|
2022-03-25 18:08:42 +00:00
|
|
|
auto* script = s.GetValue()->GetRawAngelscriptObject();
|
2021-10-30 14:35:23 +00:00
|
|
|
handle.Set(script, resolver->GetBaseType("PkmnScript"));
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2022-03-25 18:08:42 +00:00
|
|
|
static bool Battle_HasVolatileWrapper(PkmnLib::Battling::Battle* non_null obj, const ArbUt::StringView& name) {
|
|
|
|
EnsureNotNull(obj);
|
2021-10-29 19:16:47 +00:00
|
|
|
return obj->HasVolatileScript(name);
|
|
|
|
}
|
2022-03-25 18:08:42 +00:00
|
|
|
static bool BattleSide_HasVolatileWrapper(CreatureLib::Battling::BattleSide* non_null obj,
|
|
|
|
const ArbUt::StringView& name) {
|
|
|
|
EnsureNotNull(obj);
|
2021-10-29 19:16:47 +00:00
|
|
|
return obj->HasVolatileScript(name);
|
|
|
|
}
|
|
|
|
|
2022-03-25 18:08:42 +00:00
|
|
|
static u8 GetPokemonIndexWrapper(CreatureLib::Battling::BattleSide* non_null obj, PkmnLib::Battling::Pokemon* pokemon) {
|
|
|
|
EnsureNotNull(obj);
|
2021-03-28 14:16:47 +00:00
|
|
|
return obj->GetCreatureIndex(pokemon);
|
|
|
|
}
|
|
|
|
|
2022-03-25 18:08:42 +00:00
|
|
|
static PkmnLib::Battling::Pokemon* GetPokemonWrapper(CreatureLib::Battling::BattleSide* non_null obj, u8 index) {
|
|
|
|
EnsureNotNull(obj);
|
2021-08-23 19:40:20 +00:00
|
|
|
return dynamic_cast<PkmnLib::Battling::Pokemon*>(obj->GetCreature(index).GetValue());
|
|
|
|
}
|
|
|
|
|
2021-03-26 14:28:24 +00:00
|
|
|
void RegisterBattleClass::RegisterBattleSide(asIScriptEngine* engine) {
|
2021-03-26 22:05:51 +00:00
|
|
|
int r = engine->RegisterObjectMethod(
|
|
|
|
"BattleSide", "bool SwapPositions(uint8 a, uint8 b)",
|
|
|
|
asMETHODPR(CreatureLib::Battling::BattleSide, SwapPositions, (u8 a, u8 b), bool), asCALL_THISCALL);
|
2021-03-26 14:28:24 +00:00
|
|
|
Ensure(r >= 0);
|
2021-09-25 15:56:31 +00:00
|
|
|
|
|
|
|
REGISTER_GETTER("BattleSide", "uint8 get_SideIndex() const property", CreatureLib::Battling::BattleSide,
|
|
|
|
GetSideIndex);
|
2021-10-28 14:27:59 +00:00
|
|
|
REGISTER_GETTER("BattleSide", "bool get_IsDefeated() const property", CreatureLib::Battling::BattleSide,
|
|
|
|
IsDefeated);
|
|
|
|
REGISTER_GETTER("BattleSide", "bool get_HasFled() const property", CreatureLib::Battling::BattleSide, HasFled);
|
|
|
|
REGISTER_GETTER("BattleSide", "Battle@ get_Battle() const property", CreatureLib::Battling::BattleSide, GetBattle);
|
2021-09-25 15:56:31 +00:00
|
|
|
|
2021-11-20 09:24:03 +00:00
|
|
|
REGISTER_GETTER("BattleSide", "narray<Pokemon>@ get_Pokemon() const property", CreatureLib::Battling::BattleSide,
|
|
|
|
GetCreatures);
|
2021-03-26 22:05:51 +00:00
|
|
|
r = engine->RegisterObjectMethod("BattleSide", "uint8 GetPokemonIndex(const Pokemon@ pokemon) const",
|
2021-03-28 14:16:47 +00:00
|
|
|
asFUNCTION(GetPokemonIndexWrapper), asCALL_CDECL_OBJFIRST);
|
2021-03-26 14:28:24 +00:00
|
|
|
Ensure(r >= 0);
|
2021-08-23 19:40:20 +00:00
|
|
|
r = engine->RegisterObjectMethod("BattleSide", "Pokemon@ GetPokemon(uint8 index) const",
|
|
|
|
asFUNCTION(GetPokemonWrapper), asCALL_CDECL_OBJFIRST);
|
|
|
|
Ensure(r >= 0);
|
2021-10-28 14:27:59 +00:00
|
|
|
|
|
|
|
r = engine->RegisterObjectMethod("BattleSide", "ref@ AddVolatile(const constString &in name)",
|
|
|
|
asFUNCTION(BattleSide_AddVolatileWrapper), asCALL_CDECL_OBJFIRST);
|
|
|
|
Ensure(r >= 0);
|
2021-10-30 14:35:23 +00:00
|
|
|
r = engine->RegisterObjectMethod("BattleSide", "ref@ GetVolatile(const constString &in name)",
|
|
|
|
asFUNCTION(BattleSide_GetVolatileWrapper), asCALL_CDECL_OBJFIRST);
|
|
|
|
Ensure(r >= 0);
|
2021-10-28 14:27:59 +00:00
|
|
|
r = engine->RegisterObjectMethod(
|
|
|
|
"BattleSide", "void RemoveVolatile(const constString &in name) const",
|
|
|
|
asMETHODPR(CreatureLib::Battling::BattleSide, RemoveVolatileScript, (const ArbUt::BasicStringView&), void),
|
|
|
|
asCALL_THISCALL);
|
|
|
|
Ensure(r >= 0);
|
2021-10-29 19:16:47 +00:00
|
|
|
r = engine->RegisterObjectMethod("BattleSide", "bool HasVolatile(const constString &in name) const",
|
|
|
|
asFUNCTION(BattleSide_HasVolatileWrapper), asCALL_CDECL_OBJFIRST);
|
|
|
|
Ensure(r >= 0);
|
2021-03-26 14:28:24 +00:00
|
|
|
}
|
|
|
|
|
2020-02-16 15:43:37 +00:00
|
|
|
void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) {
|
2021-09-21 21:14:26 +00:00
|
|
|
REGISTER_GETTER("Battle", "const BattleLibrary@ get_Library() const property", CreatureLib::Battling::Battle,
|
|
|
|
GetLibrary);
|
2021-09-22 17:02:01 +00:00
|
|
|
REGISTER_GETTER("Battle", "bool get_CanFlee() const property", CreatureLib::Battling::Battle, CanFlee);
|
|
|
|
REGISTER_GETTER("Battle", "uint get_CurrentTurn() const property", CreatureLib::Battling::Battle, GetCurrentTurn);
|
2021-10-29 16:37:03 +00:00
|
|
|
REGISTER_GETTER("Battle", "uint8 get_PokemonPerSide() const property", CreatureLib::Battling::Battle,
|
|
|
|
GetCreaturesPerSide);
|
2021-09-22 17:02:01 +00:00
|
|
|
REGISTER_GETTER("Battle", "BattleRandom@ get_Random() const property", CreatureLib::Battling::Battle, GetRandom);
|
2021-09-21 21:14:26 +00:00
|
|
|
REGISTER_GETTER("Battle", "ChoiceQueue@ get_TurnQueue() const property", CreatureLib::Battling::Battle,
|
|
|
|
GetCurrentTurnQueue);
|
2021-09-25 15:56:31 +00:00
|
|
|
REGISTER_GETTER("Battle", "narray<BattleSide>@ get_Sides() const property", CreatureLib::Battling::Battle,
|
|
|
|
GetSides);
|
|
|
|
REGISTER_GETTER("Battle", "narray<BattleParty>@ get_Parties() const property", CreatureLib::Battling::Battle,
|
|
|
|
GetParties);
|
2021-10-28 14:27:59 +00:00
|
|
|
REGISTER_GETTER("Battle", "BattleHistory@ get_History() const property", CreatureLib::Battling::Battle, GetHistory);
|
2021-08-23 19:26:48 +00:00
|
|
|
|
2021-09-21 21:14:26 +00:00
|
|
|
auto r = engine->RegisterObjectMethod("Battle", "bool CanUse(BaseTurnChoice@ choice)",
|
2021-09-22 17:02:01 +00:00
|
|
|
asMETHOD(PkmnLib::Battling::Battle, CanUse), asCALL_THISCALL);
|
2020-12-13 11:32:52 +00:00
|
|
|
Ensure(r >= 0);
|
2021-03-28 15:55:45 +00:00
|
|
|
r = engine->RegisterObjectMethod("Battle", "ref@ AddVolatile(const constString &in name)",
|
2021-10-28 14:27:59 +00:00
|
|
|
asFUNCTION(Battle_AddVolatileWrapper), asCALL_CDECL_OBJFIRST);
|
2020-12-13 11:32:52 +00:00
|
|
|
Ensure(r >= 0);
|
2021-10-30 14:35:23 +00:00
|
|
|
r = engine->RegisterObjectMethod("Battle", "ref@ GetVolatile(const constString &in name)",
|
|
|
|
asFUNCTION(Battle_GetVolatileWrapper), asCALL_CDECL_OBJFIRST);
|
|
|
|
Ensure(r >= 0);
|
2020-02-23 11:46:44 +00:00
|
|
|
r = engine->RegisterObjectMethod(
|
2020-04-07 10:04:23 +00:00
|
|
|
"Battle", "void RemoveVolatile(const constString &in name) const",
|
2020-07-04 13:50:30 +00:00
|
|
|
asMETHODPR(PkmnLib::Battling::Battle, RemoveVolatileScript, (const ArbUt::BasicStringView&), void),
|
|
|
|
asCALL_THISCALL);
|
2020-12-13 11:32:52 +00:00
|
|
|
Ensure(r >= 0);
|
2020-07-04 13:50:30 +00:00
|
|
|
r = engine->RegisterObjectMethod(
|
2021-11-19 13:56:29 +00:00
|
|
|
"Battle", "bool SetWeather(const constString &in name) const",
|
|
|
|
asMETHODPR(PkmnLib::Battling::Battle, SetWeather, (const ArbUt::StringView&), bool), asCALL_THISCALL);
|
2020-12-13 11:32:52 +00:00
|
|
|
Ensure(r >= 0);
|
2020-04-18 13:35:01 +00:00
|
|
|
r = engine->RegisterObjectMethod("Battle", "void ClearWeather(const constString &in name) const",
|
|
|
|
asMETHODPR(PkmnLib::Battling::Battle, ClearWeather, (), void), asCALL_THISCALL);
|
2020-12-13 11:32:52 +00:00
|
|
|
Ensure(r >= 0);
|
2020-04-18 13:35:01 +00:00
|
|
|
r = engine->RegisterObjectMethod(
|
|
|
|
"Battle", "const constString& GetWeatherName() const",
|
2020-07-04 13:50:30 +00:00
|
|
|
asMETHODPR(PkmnLib::Battling::Battle, GetWeatherName, (), const ArbUt::StringView&), asCALL_THISCALL);
|
2020-12-13 11:32:52 +00:00
|
|
|
Ensure(r >= 0);
|
2021-11-19 13:56:29 +00:00
|
|
|
r = engine->RegisterObjectMethod("Battle", "void SuppressWeather() const",
|
|
|
|
asMETHOD(PkmnLib::Battling::Battle, SuppressWeather), asCALL_THISCALL);
|
|
|
|
Ensure(r >= 0);
|
|
|
|
r = engine->RegisterObjectMethod("Battle", "void UnsuppressWeather() const",
|
|
|
|
asMETHOD(PkmnLib::Battling::Battle, UnsuppressWeather), asCALL_THISCALL);
|
|
|
|
Ensure(r >= 0);
|
2021-03-26 14:28:24 +00:00
|
|
|
r = engine->RegisterObjectMethod("Battle", "BattleSide@ GetBattleSide(uint8 index)",
|
|
|
|
asFUNCTION(GetBattleSideWrapper), asCALL_CDECL_OBJFIRST);
|
|
|
|
Ensure(r >= 0);
|
2021-05-08 10:28:50 +00:00
|
|
|
r = engine->RegisterObjectMethod("Battle", "BattleParty@ GetParty(uint8 index)", asFUNCTION(GetPartyWrapper),
|
2021-05-08 10:12:36 +00:00
|
|
|
asCALL_CDECL_OBJFIRST);
|
|
|
|
Ensure(r >= 0);
|
2021-05-08 10:28:50 +00:00
|
|
|
r = engine->RegisterObjectMethod("Battle", "BattleParty@ FindPartyForPokemon(Pokemon@ pokemon)",
|
2021-05-08 10:12:36 +00:00
|
|
|
asFUNCTION(FindPartyWrapper), asCALL_CDECL_OBJFIRST);
|
|
|
|
Ensure(r >= 0);
|
2021-10-29 19:16:47 +00:00
|
|
|
r = engine->RegisterObjectMethod("Battle", "bool HasVolatile(const constString &in name) const",
|
|
|
|
asFUNCTION(Battle_HasVolatileWrapper), asCALL_CDECL_OBJFIRST);
|
|
|
|
Ensure(r >= 0);
|
2020-02-16 15:43:37 +00:00
|
|
|
}
|