From f6f1c43bf8e0e78e0e93e1e76b09189dd35df826 Mon Sep 17 00:00:00 2001 From: Axel Cocat Date: Mon, 3 Apr 2023 22:59:10 +0200 Subject: [PATCH 1/2] feat: add Unit:GetThreatList --- src/LuaEngine/LuaFunctions.cpp | 1 + src/LuaEngine/UnitMethods.h | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/LuaEngine/LuaFunctions.cpp b/src/LuaEngine/LuaFunctions.cpp index 2425c7ebeb..67788104d1 100644 --- a/src/LuaEngine/LuaFunctions.cpp +++ b/src/LuaEngine/LuaFunctions.cpp @@ -427,6 +427,7 @@ ElunaRegister UnitMethods[] = // {"RemoveBindSightAuras", &LuaUnit::RemoveBindSightAuras}, // :RemoveBindSightAuras() - UNDOCUMENTED // {"RemoveCharmAuras", &LuaUnit::RemoveCharmAuras}, // :RemoveCharmAuras() - UNDOCUMENTED { "ClearThreatList", &LuaUnit::ClearThreatList }, + { "GetThreatList", &LuaUnit::GetThreatList }, { "ClearUnitState", &LuaUnit::ClearUnitState }, { "AddUnitState", &LuaUnit::AddUnitState }, // {"DisableMelee", &LuaUnit::DisableMelee}, // :DisableMelee([disable]) - UNDOCUMENTED - if true, enables diff --git a/src/LuaEngine/UnitMethods.h b/src/LuaEngine/UnitMethods.h index 6e26113623..a9952af697 100644 --- a/src/LuaEngine/UnitMethods.h +++ b/src/LuaEngine/UnitMethods.h @@ -2009,6 +2009,45 @@ namespace LuaUnit return 0; } + /** + * Returns the [Unit]'s threat list. + * + * @return table threatList : table of [Unit]s in the threat list + */ + int GetThreatList(lua_State* L, Unit* unit) + { + if (!unit->CanHaveThreatList()) + { + Eluna::Push(L); + return 1; + } + + ThreatContainer::StorageType const& list = unit->GetThreatMgr().GetThreatList(); + + lua_newtable(L); + int table = lua_gettop(L); + uint32 i = 1; + for (ThreatReference* item : list) + { + if (!item) + { + continue; + } + Unit* victim = item->GetVictim(); + if (!victim) + { + continue; + } + + Eluna::Push(L, victim); + lua_rawseti(L, table, i); + ++i; + } + + lua_settop(L, table); // push table to top of stack + return 1; + } + /** * Mounts the [Unit] on the given displayID/modelID. * From dd04d078af9b64f0e029420f9dab41c9b7436ca7 Mon Sep 17 00:00:00 2001 From: Axel Cocat Date: Mon, 3 Apr 2023 23:00:38 +0200 Subject: [PATCH 2/2] update README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9f5a43b0e1..222ea285eb 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,7 @@ Eluna API for AC: ### Unit - Added `Unit:ModifyThreatPct()`: https://github.com/azerothcore/mod-eluna/pull/25 +- Added `Unit:GetThreatList()`: https://github.com/azerothcore/mod-eluna/pull/117 ### GameObject - Added `GameObject:AddLoot()` to add loot at runtime to an **empty** container: https://github.com/azerothcore/mod-eluna/pull/52