From 2a9a7fe04e884faab7d11bb144c8726304c1de01 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Fri, 20 Mar 2026 18:25:39 -0700 Subject: [PATCH] feat: add UnitClassification Lua API for nameplate and boss mod addons Returns WoW-standard classification strings: "normal", "elite", "rareelite", "worldboss", or "rare" based on creature rank from CreatureCache. Used by nameplate addons (Plater, TidyPlates) and boss mods (DBM) to detect elite/ boss/rare mobs for special handling. --- src/addons/lua_engine.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/addons/lua_engine.cpp b/src/addons/lua_engine.cpp index 9cd5b743..d63357de 100644 --- a/src/addons/lua_engine.cpp +++ b/src/addons/lua_engine.cpp @@ -1194,6 +1194,33 @@ static int lua_UnitCreatureType(lua_State* L) { return 1; } +// UnitClassification(unit) → "normal", "elite", "rareelite", "worldboss", "rare" +static int lua_UnitClassification(lua_State* L) { + auto* gh = getGameHandler(L); + if (!gh) { lua_pushstring(L, "normal"); return 1; } + const char* uid = luaL_optstring(L, 1, "target"); + std::string uidStr(uid); + for (char& c : uidStr) c = static_cast(std::tolower(static_cast(c))); + uint64_t guid = resolveUnitGuid(gh, uidStr); + if (guid == 0) { lua_pushstring(L, "normal"); return 1; } + auto entity = gh->getEntityManager().getEntity(guid); + if (!entity || entity->getType() == game::ObjectType::PLAYER) { + lua_pushstring(L, "normal"); + return 1; + } + auto unit = std::dynamic_pointer_cast(entity); + if (!unit) { lua_pushstring(L, "normal"); return 1; } + int rank = gh->getCreatureRank(unit->getEntry()); + switch (rank) { + case 1: lua_pushstring(L, "elite"); break; + case 2: lua_pushstring(L, "rareelite"); break; + case 3: lua_pushstring(L, "worldboss"); break; + case 4: lua_pushstring(L, "rare"); break; + default: lua_pushstring(L, "normal"); break; + } + return 1; +} + // --- Frame System --- // Minimal WoW-compatible frame objects with RegisterEvent/SetScript/GetScript. // Frames are Lua tables with a metatable that provides methods. @@ -1558,6 +1585,7 @@ void LuaEngine::registerCoreAPI() { {"UnitIsFriend", lua_UnitIsFriend}, {"UnitIsEnemy", lua_UnitIsEnemy}, {"UnitCreatureType", lua_UnitCreatureType}, + {"UnitClassification", lua_UnitClassification}, // Container/bag API {"GetContainerNumSlots", lua_GetContainerNumSlots}, {"GetContainerItemInfo", lua_GetContainerItemInfo},