feat: add RAID_TARGET_UPDATE event and GetRaidTargetIndex/SetRaidTarget

Fire RAID_TARGET_UPDATE event when raid markers (skull, cross, etc.)
are set or cleared on targets. Add two Lua API functions:
- GetRaidTargetIndex(unit) returns marker index 1-8 (or nil)
- SetRaidTarget(unit, index) sets marker 1-8 (or 0 to clear)

Enables raid marking addons and nameplate addons that display raid
icons to react to marker changes in real-time.
This commit is contained in:
Kelsi 2026-03-21 04:43:42 -07:00
parent 8e51754615
commit 1f3e362512
2 changed files with 36 additions and 0 deletions

View file

@ -948,6 +948,38 @@ static int lua_TargetNearestFriend(lua_State* L) {
return 0;
}
// GetRaidTargetIndex(unit) → icon index (1-8) or nil
static int lua_GetRaidTargetIndex(lua_State* L) {
auto* gh = getGameHandler(L);
if (!gh) { lua_pushnil(L); return 1; }
const char* uid = luaL_optstring(L, 1, "target");
std::string uidStr(uid);
for (char& c : uidStr) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
uint64_t guid = resolveUnitGuid(gh, uidStr);
if (guid == 0) { lua_pushnil(L); return 1; }
uint8_t mark = gh->getEntityRaidMark(guid);
if (mark == 0xFF) { lua_pushnil(L); return 1; }
lua_pushnumber(L, mark + 1); // WoW uses 1-indexed (1=Star, 2=Circle, ... 8=Skull)
return 1;
}
// SetRaidTarget(unit, index) — set raid marker (1-8, or 0 to clear)
static int lua_SetRaidTarget(lua_State* L) {
auto* gh = getGameHandler(L);
if (!gh) return 0;
const char* uid = luaL_optstring(L, 1, "target");
int index = static_cast<int>(luaL_checknumber(L, 2));
std::string uidStr(uid);
for (char& c : uidStr) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
uint64_t guid = resolveUnitGuid(gh, uidStr);
if (guid == 0) return 0;
if (index >= 1 && index <= 8)
gh->setRaidMark(guid, static_cast<uint8_t>(index - 1));
else if (index == 0)
gh->setRaidMark(guid, 0xFF); // clear
return 0;
}
// --- GetSpellInfo / GetSpellTexture ---
// GetSpellInfo(spellIdOrName) -> name, rank, icon, castTime, minRange, maxRange, spellId
static int lua_GetSpellInfo(lua_State* L) {
@ -3036,6 +3068,8 @@ void LuaEngine::registerCoreAPI() {
{"TargetLastTarget", lua_TargetLastTarget},
{"TargetNearestEnemy", lua_TargetNearestEnemy},
{"TargetNearestFriend", lua_TargetNearestFriend},
{"GetRaidTargetIndex", lua_GetRaidTargetIndex},
{"SetRaidTarget", lua_SetRaidTarget},
{"UnitRace", lua_UnitRace},
{"UnitPowerType", lua_UnitPowerType},
{"GetNumGroupMembers", lua_GetNumGroupMembers},

View file

@ -5022,6 +5022,8 @@ void GameHandler::handlePacket(network::Packet& packet) {
}
}
LOG_DEBUG("MSG_RAID_TARGET_UPDATE: type=", static_cast<int>(rtuType));
if (addonEventCallback_)
addonEventCallback_("RAID_TARGET_UPDATE", {});
break;
}
case Opcode::SMSG_BUY_ITEM: {