mirror of
https://github.com/azerothcore/mod-ale
synced 2025-11-29 15:38:17 +08:00
feat: add Unit:GetThreatList (#117)
This commit is contained in:
@@ -102,6 +102,7 @@ Eluna API for AC:
|
||||
### Unit
|
||||
- Added `Unit:ModifyThreatPct()`: https://github.com/azerothcore/mod-eluna/pull/25
|
||||
- Added `Unit:GetAttackers()`: https://github.com/azerothcore/mod-eluna/pull/116
|
||||
- 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
|
||||
|
||||
@@ -428,6 +428,7 @@ ElunaRegister<Unit> 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
|
||||
|
||||
@@ -2037,6 +2037,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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user