[Quest API] Add GetCloseMobList() and CalculateDistance() overload to Perl/Lua (#3455)

* [Quest API] Add GetCloseMobList() and CalculateDistance() overload to Perl/Lua

# Perl
- Add `$entity_list->GetCloseMobList(mob)`.
- Add `$entity_list->GetCloseMobList(mob, distance)`.
- Add `$mob->CalculateDistance(mob)`.
- Add `$mob->GetCloseMobList()`.
- Add `$mob->GetCloseMobList(distance)`.

# Lua
- Add `eq.get_entity_list():GetCloseMobList(mob)`.
- Add `eq.get_entity_list():GetCloseMobList(mob, distance)`.
- Add `mob:CalculateDistance(mob)`.
- Add `mob:GetCloseMobList()`.
- Add `mob:GetCloseMobList(distance)`.

* Ignore Self

* Update lua_entity_list.cpp

* Cleanup
This commit is contained in:
Alex King
2023-07-02 10:55:27 -04:00
committed by GitHub
parent 6a80bcecc7
commit 728ce0c519
9 changed files with 270 additions and 3 deletions
+58
View File
@@ -635,6 +635,62 @@ Lua_Bot Lua_EntityList::GetRandomBot(float x, float y, float z, float distance,
return self->GetRandomBot(glm::vec3(x, y, z), distance, exclude_bot);
}
Lua_Mob_List Lua_EntityList::GetCloseMobList(Lua_Mob mob) {
Lua_Safe_Call_Class(Lua_Mob_List);
Lua_Mob_List ret;
const auto& l = self->GetCloseMobList(mob);
ret.entries.reserve(l.size());
for (const auto& e : l) {
ret.entries.emplace_back(Lua_Mob(e.second));
}
return ret;
}
Lua_Mob_List Lua_EntityList::GetCloseMobList(Lua_Mob mob, float distance) {
Lua_Safe_Call_Class(Lua_Mob_List);
Lua_Mob_List ret;
const auto& l = self->GetCloseMobList(mob);
ret.entries.reserve(l.size());
for (const auto& e : l) {
if (mob.CalculateDistance(e.second) <= distance) {
ret.entries.emplace_back(Lua_Mob(e.second));
}
}
return ret;
}
Lua_Mob_List Lua_EntityList::GetCloseMobList(Lua_Mob mob, float distance, bool ignore_self) {
Lua_Safe_Call_Class(Lua_Mob_List);
Lua_Mob_List ret;
const auto& l = self->GetCloseMobList(mob);
ret.entries.reserve(l.size());
for (const auto& e : l) {
if (ignore_self && e.second == mob) {
continue;
}
if (mob.CalculateDistance(e.second) <= distance) {
ret.entries.emplace_back(Lua_Mob(e.second));
}
}
return ret;
}
luabind::scope lua_register_entity_list() {
return luabind::class_<Lua_EntityList>("EntityList")
.def(luabind::constructor<>())
@@ -665,6 +721,8 @@ luabind::scope lua_register_entity_list() {
.def("GetClientByName", (Lua_Client(Lua_EntityList::*)(const char*))&Lua_EntityList::GetClientByName)
.def("GetClientByWID", (Lua_Client(Lua_EntityList::*)(uint32))&Lua_EntityList::GetClientByWID)
.def("GetClientList", (Lua_Client_List(Lua_EntityList::*)(void))&Lua_EntityList::GetClientList)
.def("GetCloseMobList", (Lua_Mob_List(Lua_EntityList::*)(Lua_Mob))&Lua_EntityList::GetCloseMobList)
.def("GetCloseMobList", (Lua_Mob_List(Lua_EntityList::*)(Lua_Mob,float))&Lua_EntityList::GetCloseMobList)
.def("GetCorpseByID", (Lua_Corpse(Lua_EntityList::*)(int))&Lua_EntityList::GetCorpseByID)
.def("GetCorpseByName", (Lua_Corpse(Lua_EntityList::*)(const char*))&Lua_EntityList::GetCorpseByName)
.def("GetCorpseByOwner", (Lua_Corpse(Lua_EntityList::*)(Lua_Client))&Lua_EntityList::GetCorpseByOwner)