mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-11 16:51:29 +00:00
[Quest API] Add NPC List Filter Methods to Perl/Lua (#4493)
* [Quest API] Add GetNPCsByNPCIDs to Perl/Lua * Push * Update entity.cpp * Separate methods.
This commit is contained in:
parent
3359839a9b
commit
a17f467b98
@ -5937,3 +5937,39 @@ void EntityList::DamageArea(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<NPC*> EntityList::GetNPCsByIDs(std::vector<uint32> npc_ids)
|
||||
{
|
||||
std::vector<NPC*> v;
|
||||
|
||||
for (const auto& e : GetNPCList()) {
|
||||
const auto& n = std::find(npc_ids.begin(), npc_ids.end(), e.second->GetNPCTypeID());
|
||||
if (e.second) {
|
||||
if (n != npc_ids.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
v.emplace_back(e.second);
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
std::vector<NPC*> EntityList::GetExcludedNPCsByIDs(std::vector<uint32> npc_ids)
|
||||
{
|
||||
std::vector<NPC*> v;
|
||||
|
||||
for (const auto& e : GetNPCList()) {
|
||||
const auto& n = std::find(npc_ids.begin(), npc_ids.end(), e.second->GetNPCTypeID());
|
||||
if (e.second) {
|
||||
if (n == npc_ids.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
v.emplace_back(e.second);
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
@ -560,6 +560,9 @@ public:
|
||||
|
||||
std::unordered_map<uint16, Mob *> &GetCloseMobList(Mob *mob, float distance = 0.0f);
|
||||
|
||||
std::vector<NPC*> GetNPCsByIDs(std::vector<uint32> npc_ids);
|
||||
std::vector<NPC*> GetExcludedNPCsByIDs(std::vector<uint32> npc_ids);
|
||||
|
||||
void DepopAll(int NPCTypeID, bool StartSpawnTimer = true);
|
||||
|
||||
uint16 GetFreeID();
|
||||
|
||||
@ -764,6 +764,66 @@ void Lua_EntityList::MassGroupBuff(Lua_Mob caster, Lua_Mob center, uint16 spell_
|
||||
self->MassGroupBuff(caster, center, spell_id, affect_caster);
|
||||
}
|
||||
|
||||
Lua_NPC_List Lua_EntityList::GetNPCsByExcludedIDs(luabind::adl::object table)
|
||||
{
|
||||
Lua_Safe_Call_Class(Lua_NPC_List);
|
||||
Lua_NPC_List ret;
|
||||
|
||||
if (luabind::type(table) != LUA_TTABLE) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (d_) {
|
||||
auto self = reinterpret_cast<NativeType*>(d_);
|
||||
|
||||
std::vector<uint32> ids;
|
||||
|
||||
int index = 1;
|
||||
while (luabind::type(table[index]) != LUA_TNIL) {
|
||||
ids.emplace_back(luabind::object_cast<uint32>(table[index]));
|
||||
index++;
|
||||
}
|
||||
|
||||
const auto& l = self->GetExcludedNPCsByIDs(ids);
|
||||
|
||||
for (const auto& e : l) {
|
||||
ret.entries.emplace_back(Lua_NPC(e));
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Lua_NPC_List Lua_EntityList::GetNPCsByIDs(luabind::adl::object table)
|
||||
{
|
||||
Lua_Safe_Call_Class(Lua_NPC_List);
|
||||
Lua_NPC_List ret;
|
||||
|
||||
if (luabind::type(table) != LUA_TTABLE) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (d_) {
|
||||
auto self = reinterpret_cast<NativeType*>(d_);
|
||||
|
||||
std::vector<uint32> ids;
|
||||
|
||||
int index = 1;
|
||||
while (luabind::type(table[index]) != LUA_TNIL) {
|
||||
ids.emplace_back(luabind::object_cast<uint32>(table[index]));
|
||||
index++;
|
||||
}
|
||||
|
||||
const auto& l = self->GetNPCsByIDs(ids);
|
||||
|
||||
for (const auto& e : l) {
|
||||
ret.entries.emplace_back(Lua_NPC(e));
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
luabind::scope lua_register_entity_list() {
|
||||
return luabind::class_<Lua_EntityList>("EntityList")
|
||||
.def(luabind::constructor<>())
|
||||
@ -829,6 +889,8 @@ luabind::scope lua_register_entity_list() {
|
||||
.def("GetNPCByNPCTypeID", (Lua_NPC(Lua_EntityList::*)(int))&Lua_EntityList::GetNPCByNPCTypeID)
|
||||
.def("GetNPCBySpawnID", (Lua_NPC(Lua_EntityList::*)(int))&Lua_EntityList::GetNPCBySpawnID)
|
||||
.def("GetNPCList", (Lua_NPC_List(Lua_EntityList::*)(void))&Lua_EntityList::GetNPCList)
|
||||
.def("GetNPCsByExcludedIDs", (Lua_NPC_List(Lua_EntityList::*)(luabind::adl::object))&Lua_EntityList::GetNPCsByExcludedIDs)
|
||||
.def("GetNPCsByIDs", (Lua_NPC_List(Lua_EntityList::*)(luabind::adl::object))&Lua_EntityList::GetNPCsByIDs)
|
||||
.def("GetObjectByDBID", (Lua_Object(Lua_EntityList::*)(uint32))&Lua_EntityList::GetObjectByDBID)
|
||||
.def("GetObjectByID", (Lua_Object(Lua_EntityList::*)(int))&Lua_EntityList::GetObjectByID)
|
||||
.def("GetObjectList", (Lua_Object_List(Lua_EntityList::*)(void))&Lua_EntityList::GetObjectList)
|
||||
|
||||
@ -156,7 +156,8 @@ public:
|
||||
void AreaTaunt(Lua_Client caster, float range, int bonus_hate);
|
||||
void MassGroupBuff(Lua_Mob caster, Lua_Mob center, uint16 spell_id);
|
||||
void MassGroupBuff(Lua_Mob caster, Lua_Mob center, uint16 spell_id, bool affect_caster);
|
||||
|
||||
Lua_NPC_List GetNPCsByIDs(luabind::adl::object npc_ids);
|
||||
Lua_NPC_List GetNPCsByExcludedIDs(luabind::adl::object npc_ids);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -739,6 +739,44 @@ void Perl_EntityList_MassGroupBuff(EntityList* self, Mob* caster, Mob* center, u
|
||||
self->MassGroupBuff(caster, center, spell_id, affect_caster);
|
||||
}
|
||||
|
||||
perl::array Perl_EntityList_GetNPCsByExcludedIDs(EntityList* self, perl::array npc_ids)
|
||||
{
|
||||
std::vector<uint32> ids;
|
||||
|
||||
for (int i = 0; i < npc_ids.size(); i++) {
|
||||
ids.emplace_back(npc_ids[i]);
|
||||
}
|
||||
|
||||
const auto& l = self->GetExcludedNPCsByIDs(ids);
|
||||
|
||||
perl::array npcs;
|
||||
|
||||
for (const auto& e : l) {
|
||||
npcs.push_back(e);
|
||||
}
|
||||
|
||||
return npcs;
|
||||
}
|
||||
|
||||
perl::array Perl_EntityList_GetNPCsByIDs(EntityList* self, perl::array npc_ids)
|
||||
{
|
||||
std::vector<uint32> ids;
|
||||
|
||||
for (int i = 0; i < npc_ids.size(); i++) {
|
||||
ids.emplace_back(npc_ids[i]);
|
||||
}
|
||||
|
||||
const auto& l = self->GetNPCsByIDs(ids);
|
||||
|
||||
perl::array npcs;
|
||||
|
||||
for (const auto& e : l) {
|
||||
npcs.push_back(e);
|
||||
}
|
||||
|
||||
return npcs;
|
||||
}
|
||||
|
||||
void perl_register_entitylist()
|
||||
{
|
||||
perl::interpreter perl(PERL_GET_THX);
|
||||
@ -804,6 +842,8 @@ void perl_register_entitylist()
|
||||
package.add("GetNPCByNPCTypeID", &Perl_EntityList_GetNPCByNPCTypeID);
|
||||
package.add("GetNPCBySpawnID", &Perl_EntityList_GetNPCBySpawnID);
|
||||
package.add("GetNPCList", &Perl_EntityList_GetNPCList);
|
||||
package.add("GetNPCsByExcludedIDs", &Perl_EntityList_GetNPCsByExcludedIDs);
|
||||
package.add("GetNPCsByIDs", &Perl_EntityList_GetNPCsByIDs);
|
||||
package.add("GetObjectByDBID", &Perl_EntityList_GetObjectByDBID);
|
||||
package.add("GetObjectByID", &Perl_EntityList_GetObjectByID);
|
||||
package.add("GetObjectList", &Perl_EntityList_GetObjectList);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user