From 2e9dd01d122d664afad627818e8eb7e471d8d1fd Mon Sep 17 00:00:00 2001 From: Kelsi Date: Mon, 23 Mar 2026 02:17:16 -0700 Subject: [PATCH] feat: add battleground scoreboard API for PvP addons GetNumBattlefieldScores() returns player count in the BG scoreboard. GetBattlefieldScore(index) returns 12-field WoW API signature: name, killingBlows, honorableKills, deaths, honorGained, faction, rank, race, class, classToken, damageDone, healingDone. GetBattlefieldWinner() returns winning faction (0=Horde, 1=Alliance) or nil if BG is still in progress. RequestBattlefieldScoreData() sends MSG_PVP_LOG_DATA to refresh the scoreboard from the server. Uses existing BgScoreboardData from MSG_PVP_LOG_DATA handler. Enables BG scoreboard addons and PvP tracking. --- src/addons/lua_engine.cpp | 48 +++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/src/addons/lua_engine.cpp b/src/addons/lua_engine.cpp index 1caac0f1..be4b8e5f 100644 --- a/src/addons/lua_engine.cpp +++ b/src/addons/lua_engine.cpp @@ -5136,12 +5136,52 @@ void LuaEngine::registerCoreAPI() { 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 + lua_pushstring(L, "none"); + lua_pushnumber(L, 0); + lua_pushnumber(L, 0); return 3; }}, + {"GetNumBattlefieldScores", [](lua_State* L) -> int { + auto* gh = getGameHandler(L); + const auto* sb = gh ? gh->getBgScoreboard() : nullptr; + lua_pushnumber(L, sb ? sb->players.size() : 0); + return 1; + }}, + {"GetBattlefieldScore", [](lua_State* L) -> int { + // GetBattlefieldScore(index) → name, killingBlows, honorableKills, deaths, honorGained, faction, rank, race, class, classToken, damageDone, healingDone + auto* gh = getGameHandler(L); + int index = static_cast(luaL_checknumber(L, 1)); + const auto* sb = gh ? gh->getBgScoreboard() : nullptr; + if (!sb || index < 1 || index > static_cast(sb->players.size())) { + lua_pushnil(L); return 1; + } + const auto& p = sb->players[index - 1]; + lua_pushstring(L, p.name.c_str()); // name + lua_pushnumber(L, p.killingBlows); // killingBlows + lua_pushnumber(L, p.honorableKills); // honorableKills + lua_pushnumber(L, p.deaths); // deaths + lua_pushnumber(L, p.bonusHonor); // honorGained + lua_pushnumber(L, p.team); // faction (0=Horde,1=Alliance) + lua_pushnumber(L, 0); // rank + lua_pushstring(L, ""); // race + lua_pushstring(L, ""); // class + lua_pushstring(L, "WARRIOR"); // classToken + lua_pushnumber(L, 0); // damageDone + lua_pushnumber(L, 0); // healingDone + return 12; + }}, + {"GetBattlefieldWinner", [](lua_State* L) -> int { + auto* gh = getGameHandler(L); + const auto* sb = gh ? gh->getBgScoreboard() : nullptr; + if (sb && sb->hasWinner) lua_pushnumber(L, sb->winner); + else lua_pushnil(L); + return 1; + }}, + {"RequestBattlefieldScoreData", [](lua_State* L) -> int { + auto* gh = getGameHandler(L); + if (gh) gh->requestPvpLog(); + return 0; + }}, // --- Calendar --- {"CalendarGetDate", [](lua_State* L) -> int { // CalendarGetDate() → weekday, month, day, year