I'm currently writing an addon to report encounter progress to whispers during a boss fight. It would be cool to be able to return Encounter Journal links to the whisperers. My current NYI strat for this is
- EJ_GetCurrentInstance() - for instanceID
- EJ_GetEncounterInfoByIndex(index, instanceID) - for encounter name, id and link
- EJ_GetCreatureInfo(index, encounterID) - for creature name
I'd then compare the list of creatures to the names of the currently visible boss frames by name to get the current encounter in progress.
My questions about this:
- Is there an easier way of get the current encounter in progress?
- Is there a way to construct a creature link?
Another problem is a boss like Jandice Barov. She disappears at 66% and 33% health, so does her boss frame. I check for a boss presence at INSTANCE_ENCOUNTER_ENGAGE_UNIT and issue a whisper reply if there is a boss frame present. Any idea on how to handle this case? Currently I'm settled on just returning a EJ link to the current encounter, which I could cache at the start of the fight, but it would be nice to be able to return the current health of the boss too.
Here my current WIP (EJ functionality NYI). Code is based on SimpleBossWhisperer by Rabbit:
lua Code:
local addon = ...
local prefix = "<RBW>: "
local dndMsg = prefix .. "I'm busy fighting %s."
local combatEndedMsg = prefix .. "Combat ended."
local bossFormat = "%s (%d%%)" -- name (health%)
local playerName = UnitName("player")
local disableChatFilter = true
local numBosses = 0
local whisperers = {}
local frame = CreateFrame("Frame")
frame:SetScript("OnEvent", function(self, event, msg, ...) self[event](self, msg, ...) end)
frame:RegisterEvent("INSTANCE_ENCOUNTER_ENGAGE_UNIT")
frame:RegisterEvent("PLAYER_REGEN_ENABLED")
frame:RegisterEvent("CHAT_MSG_WHISPER")
frame:RegisterEvent("CHAT_MSG_BN_WHISPER")
frame:RegisterEvent("ADDON_LOADED")
local function GetReply(sender, msg, presenceID, client)
if (not client or client == "WoW") and (type(sender) ~= "string" or playerName == sender or UnitInRaid(sender) or UnitInParty(sender)) then return end
if not whisperers[presenceID or sender] or msg == "status" then
whisperers[presenceID or sender] = true
local str = ""
for i = 1, MAX_BOSS_FRAMES do
local unit = "boss" .. i
if UnitExists(unit) then
str = str .. string.format(bossFormat, UnitName(unit), math.floor(UnitHealth(unit) / UnitHealthMax(unit) * 100 + 0.5))
end
end
-- TODO: message length should not be > 255 characters (utf8 aware)
-- SendChatMessage truncates to 255 chars, BNSendWhisper fails silently
-- use strlenutf8()
return string.format(dndMsg, str)
end
end
-- XXX: fires when a boss frame toggles visibility
-- does not fire after reloadui
function frame:INSTANCE_ENCOUNTER_ENGAGE_UNIT()
numBosses = 0
for i = 1, MAX_BOSS_FRAMES do
-- Shado-Pan Garrison daily quests display your companion as a boss
-- TODO: use UnitClassification instead of UnitIsFriend because there are friendly bosses as well
-- I don't need UnitExists as UnitClassification returns "normal" for non-present units
if UnitExists("boss" .. i) and not UnitIsFriend("boss" .. i, "player") then
numBosses = numBosses + 1
end
end
print(prefix, numBosses)
end
function frame:PLAYER_REGEN_ENABLED()
for player in pairs(whisperers) do
local presenceID = tonumber(player)
if presenceID then
BNSendWhisper(presenceID, combatEndedMsg)
else
SendChatMessage(combatEndedMsg, "WHISPER", nil, player)
end
end
numBosses = 0
wipe(whisperers)
end
function frame:CHAT_MSG_WHISPER(msg, sender, _, _, _, flag)
if flag == "GM" or numBosses == 0 then return end
local reply = GetReply(sender, msg)
if reply then
SendChatMessage(reply, "WHISPER", nil, sender)
end
end
function frame:CHAT_MSG_BN_WHISPER(msg, sender, _, _, _, _, _, _, _, _, _, _, presenceID)
if numBosses == 0 then return end
local _, _, _, _, toonName, _, client = BNGetFriendInfoByID(presenceID) -- client: WoW, D3
local reply = GetReply(toonName, msg, presenceID, client)
if reply then
BNSendWhisper(presenceID, reply)
end
end
function frame:ADDON_LOADED(name)
if name ~= addon then return end
self:UnregisterEvent("ADDON_LOADED")
if not disableChatFilter then
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_INFORM", function(self, event, msg)
if string.find(msg, "^" .. prefix) then return true end
end)
ChatFrame_AddMessageEventFilter("CHAT_MSG_BN_WHISPER_INFORM", function(self, event, msg)
if string.find(msg, "^" .. prefix) then return true end
end)
end
end