[Bots] Add Bot scripting capabilities to the source. (#1378)

- This will allow server operators to interact with bots within a script in Perl or Lua.
This commit is contained in:
Alex
2021-06-11 14:46:30 -04:00
committed by GitHub
parent d54cd08560
commit d9d6a64941
14 changed files with 338 additions and 0 deletions
+45
View File
@@ -17,6 +17,10 @@
#include "lua_raid.h"
#include "lua_spawn.h"
#ifdef BOTS
#include "lua_bot.h"
#endif
struct Lua_Mob_List {
std::vector<Lua_Mob> entries;
};
@@ -29,6 +33,12 @@ struct Lua_Client_List {
std::vector<Lua_Client> entries;
};
#ifdef BOTS
struct Lua_Bot_List {
std::vector<Lua_Bot> entries;
};
#endif
struct Lua_Corpse_List {
std::vector<Lua_Corpse> entries;
};
@@ -345,6 +355,29 @@ Lua_Client_List Lua_EntityList::GetClientList() {
return ret;
}
#ifdef BOTS
Lua_Bot Lua_EntityList::GetBotByID(uint32 bot_id) {
Lua_Safe_Call_Class(Lua_Bot);
return Lua_Bot(self->GetBotByBotID(bot_id));
}
Lua_Bot Lua_EntityList::GetBotByName(std::string bot_name) {
Lua_Safe_Call_Class(Lua_Bot);
return Lua_Bot(self->GetBotByBotName(bot_name));
}
Lua_Bot_List Lua_EntityList::GetBotList() {
Lua_Safe_Call_Class(Lua_Bot_List);
Lua_Bot_List ret;
auto &bot_list = self->GetBotList();
for (auto bot_iterator : bot_list) {
ret.entries.push_back(Lua_Bot(bot_iterator));
}
return ret;
}
#endif
Lua_Client_List Lua_EntityList::GetShuffledClientList() {
Lua_Safe_Call_Class(Lua_Client_List);
Lua_Client_List ret;
@@ -502,6 +535,11 @@ luabind::scope lua_register_entity_list() {
.def("GetRandomClient", (Lua_Client(Lua_EntityList::*)(float, float, float, float, Lua_Client))&Lua_EntityList::GetRandomClient)
.def("GetMobList", (Lua_Mob_List(Lua_EntityList::*)(void))&Lua_EntityList::GetMobList)
.def("GetClientList", (Lua_Client_List(Lua_EntityList::*)(void))&Lua_EntityList::GetClientList)
#ifdef BOTS
.def("GetBotByID", (Lua_Bot(Lua_EntityList::*)(uint32))&Lua_EntityList::GetBotByID)
.def("GetBotByName", (Lua_Bot(Lua_EntityList::*)(std::string))&Lua_EntityList::GetBotByName)
.def("GetBotList", (Lua_Bot_List(Lua_EntityList::*)(void))&Lua_EntityList::GetBotList)
#endif
.def("GetShuffledClientList", (Lua_Client_List(Lua_EntityList::*)(void))&Lua_EntityList::GetShuffledClientList)
.def("GetNPCList", (Lua_NPC_List(Lua_EntityList::*)(void))&Lua_EntityList::GetNPCList)
.def("GetCorpseList", (Lua_Corpse_List(Lua_EntityList::*)(void))&Lua_EntityList::GetCorpseList)
@@ -522,6 +560,13 @@ luabind::scope lua_register_client_list() {
.def_readwrite("entries", &Lua_Client_List::entries, luabind::return_stl_iterator);
}
#ifdef BOTS
luabind::scope lua_register_bot_list() {
return luabind::class_<Lua_Bot_List>("BotList")
.def_readwrite("entries", &Lua_Bot_List::entries, luabind::return_stl_iterator);
}
#endif
luabind::scope lua_register_npc_list() {
return luabind::class_<Lua_NPC_List>("NPCList")
.def_readwrite("entries", &Lua_NPC_List::entries, luabind::return_stl_iterator);