mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-11 16:51:29 +00:00
Add lua entity_list function GetShuffledClientList()
There is cases where we need to get a random client, but GetRandomClient() is not sufficient enough due to complex predicates required on what tells us is a valid client. This way we can just loop over a shuffled list and verify a client is valid instead of multiple GetRandomClient() calls.
This commit is contained in:
parent
93749bc509
commit
e3c01d4143
@ -340,6 +340,22 @@ Lua_Client_List Lua_EntityList::GetClientList() {
|
||||
return ret;
|
||||
}
|
||||
|
||||
Lua_Client_List Lua_EntityList::GetShuffledClientList() {
|
||||
Lua_Safe_Call_Class(Lua_Client_List);
|
||||
Lua_Client_List ret;
|
||||
auto &t_list = self->GetClientList();
|
||||
|
||||
auto iter = t_list.begin();
|
||||
while(iter != t_list.end()) {
|
||||
ret.entries.push_back(Lua_Client(iter->second));
|
||||
++iter;
|
||||
}
|
||||
|
||||
zone->random.Shuffle(ret.entries.begin(), ret.entries.end());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Lua_NPC_List Lua_EntityList::GetNPCList() {
|
||||
Lua_Safe_Call_Class(Lua_NPC_List);
|
||||
Lua_NPC_List ret;
|
||||
@ -480,6 +496,7 @@ 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)
|
||||
.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)
|
||||
.def("GetObjectList", (Lua_Object_List(Lua_EntityList::*)(void))&Lua_EntityList::GetObjectList)
|
||||
|
||||
@ -101,6 +101,7 @@ public:
|
||||
Lua_Client GetRandomClient(float x, float y, float z, float dist, Lua_Client exclude);
|
||||
Lua_Mob_List GetMobList();
|
||||
Lua_Client_List GetClientList();
|
||||
Lua_Client_List GetShuffledClientList();
|
||||
Lua_NPC_List GetNPCList();
|
||||
Lua_Corpse_List GetCorpseList();
|
||||
Lua_Object_List GetObjectList();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user