diff --git a/zone/entity.cpp b/zone/entity.cpp index 683d1eee6..d171c2807 100644 --- a/zone/entity.cpp +++ b/zone/entity.cpp @@ -5937,3 +5937,39 @@ void EntityList::DamageArea( } } } + +std::vector EntityList::GetNPCsByIDs(std::vector npc_ids) +{ + std::vector 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 EntityList::GetExcludedNPCsByIDs(std::vector npc_ids) +{ + std::vector 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; +} diff --git a/zone/entity.h b/zone/entity.h index 8396dd386..33313f14e 100644 --- a/zone/entity.h +++ b/zone/entity.h @@ -560,6 +560,9 @@ public: std::unordered_map &GetCloseMobList(Mob *mob, float distance = 0.0f); + std::vector GetNPCsByIDs(std::vector npc_ids); + std::vector GetExcludedNPCsByIDs(std::vector npc_ids); + void DepopAll(int NPCTypeID, bool StartSpawnTimer = true); uint16 GetFreeID(); diff --git a/zone/lua_entity_list.cpp b/zone/lua_entity_list.cpp index adf9ef34f..825b78ada 100644 --- a/zone/lua_entity_list.cpp +++ b/zone/lua_entity_list.cpp @@ -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(d_); + + std::vector ids; + + int index = 1; + while (luabind::type(table[index]) != LUA_TNIL) { + ids.emplace_back(luabind::object_cast(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(d_); + + std::vector ids; + + int index = 1; + while (luabind::type(table[index]) != LUA_TNIL) { + ids.emplace_back(luabind::object_cast(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_("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) diff --git a/zone/lua_entity_list.h b/zone/lua_entity_list.h index eb986b67b..bc4d3f576 100644 --- a/zone/lua_entity_list.h +++ b/zone/lua_entity_list.h @@ -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 diff --git a/zone/perl_entity.cpp b/zone/perl_entity.cpp index 765767a15..64860f4a2 100644 --- a/zone/perl_entity.cpp +++ b/zone/perl_entity.cpp @@ -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 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 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);