From 47e317debfaae152cc84ff75b1ed66289624955d Mon Sep 17 00:00:00 2001 From: Kelsi Date: Mon, 23 Mar 2026 01:42:57 -0700 Subject: [PATCH] feat: add UnitIsPVP, UnitIsPVPFreeForAll, and GetBattlefieldStatus UnitIsPVP(unit) checks UNIT_FLAG_PVP (0x1000) on the unit's flags field. Used by unit frame addons to show PvP status indicators. UnitIsPVPFreeForAll(unit) checks for FFA PvP flag. GetBattlefieldStatus() returns stub ("none") for addons that check BG queue state on login. Full BG scoreboard data exists in GameHandler but is rendered via ImGui. --- src/addons/lua_engine.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/addons/lua_engine.cpp b/src/addons/lua_engine.cpp index 771baf38..1caac0f1 100644 --- a/src/addons/lua_engine.cpp +++ b/src/addons/lua_engine.cpp @@ -5108,6 +5108,40 @@ void LuaEngine::registerCoreAPI() { lua_pushboolean(L, 1); // isCastable return 4; }}, + // --- PvP --- + {"UnitIsPVP", [](lua_State* L) -> int { + auto* gh = getGameHandler(L); + const char* uid = luaL_optstring(L, 1, "player"); + if (!gh) { lua_pushboolean(L, 0); return 1; } + uint64_t guid = resolveUnitGuid(gh, std::string(uid)); + if (guid == 0) { lua_pushboolean(L, 0); return 1; } + auto entity = gh->getEntityManager().getEntity(guid); + if (!entity) { lua_pushboolean(L, 0); return 1; } + // UNIT_FLAG_PVP = 0x00001000 + uint32_t flags = entity->getField(game::fieldIndex(game::UF::UNIT_FIELD_FLAGS)); + lua_pushboolean(L, (flags & 0x00001000) ? 1 : 0); + return 1; + }}, + {"UnitIsPVPFreeForAll", [](lua_State* L) -> int { + auto* gh = getGameHandler(L); + const char* uid = luaL_optstring(L, 1, "player"); + if (!gh) { lua_pushboolean(L, 0); return 1; } + uint64_t guid = resolveUnitGuid(gh, std::string(uid)); + if (guid == 0) { lua_pushboolean(L, 0); return 1; } + auto entity = gh->getEntityManager().getEntity(guid); + if (!entity) { lua_pushboolean(L, 0); return 1; } + // UNIT_FLAG_FFA_PVP = 0x00000080 in UNIT_FIELD_BYTES_2 byte 1 + uint32_t flags = entity->getField(game::fieldIndex(game::UF::UNIT_FIELD_FLAGS)); + lua_pushboolean(L, (flags & 0x00080000) ? 1 : 0); // PLAYER_FLAGS_FFA_PVP + return 1; + }}, + {"GetBattlefieldStatus", [](lua_State* L) -> int { + // Stub: return "none" for slot 1 + lua_pushstring(L, "none"); // status + lua_pushnumber(L, 0); // mapName + lua_pushnumber(L, 0); // instanceID + return 3; + }}, // --- Calendar --- {"CalendarGetDate", [](lua_State* L) -> int { // CalendarGetDate() → weekday, month, day, year