Thread Tools Display Modes
Prev Previous Post   Next Post Next
10-18-13, 08:31 AM   #1
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Encounter Detection

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
  1. EJ_GetCurrentInstance() - for instanceID
  2. EJ_GetEncounterInfoByIndex(index, instanceID) - for encounter name, id and link
  3. 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:
  1. Is there an easier way of get the current encounter in progress?
  2. 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:
  1. local addon = ...
  2. local prefix = "<RBW>: "
  3. local dndMsg = prefix .. "I'm busy fighting %s."
  4. local combatEndedMsg = prefix .. "Combat ended."
  5. local bossFormat = "%s (%d%%)" -- name (health%)
  6.  
  7. local playerName = UnitName("player")
  8. local disableChatFilter = true
  9.  
  10. local numBosses = 0
  11. local whisperers = {}
  12.  
  13. local frame = CreateFrame("Frame")
  14. frame:SetScript("OnEvent", function(self, event, msg, ...) self[event](self, msg, ...) end)
  15. frame:RegisterEvent("INSTANCE_ENCOUNTER_ENGAGE_UNIT")
  16. frame:RegisterEvent("PLAYER_REGEN_ENABLED")
  17. frame:RegisterEvent("CHAT_MSG_WHISPER")
  18. frame:RegisterEvent("CHAT_MSG_BN_WHISPER")
  19. frame:RegisterEvent("ADDON_LOADED")
  20.  
  21. local function GetReply(sender, msg, presenceID, client)
  22.     if (not client or client == "WoW") and (type(sender) ~= "string" or playerName == sender or UnitInRaid(sender) or UnitInParty(sender)) then return end
  23.  
  24.     if not whisperers[presenceID or sender] or msg == "status" then
  25.         whisperers[presenceID or sender] = true
  26.         local str = ""
  27.         for i = 1, MAX_BOSS_FRAMES do
  28.             local unit = "boss" .. i
  29.             if UnitExists(unit) then
  30.                 str = str .. string.format(bossFormat, UnitName(unit), math.floor(UnitHealth(unit) / UnitHealthMax(unit) * 100 + 0.5))
  31.             end
  32.         end
  33.         -- TODO: message length should not be > 255 characters (utf8 aware)
  34.         --       SendChatMessage truncates to 255 chars, BNSendWhisper fails silently
  35.         --       use strlenutf8()
  36.         return string.format(dndMsg, str)
  37.     end
  38. end
  39.  
  40. -- XXX: fires when a boss frame toggles visibility
  41. --      does not fire after reloadui
  42. function frame:INSTANCE_ENCOUNTER_ENGAGE_UNIT()
  43.     numBosses = 0
  44.     for i = 1, MAX_BOSS_FRAMES do
  45.         -- Shado-Pan Garrison daily quests display your companion as a boss
  46.         -- TODO: use UnitClassification instead of UnitIsFriend because there are friendly bosses as well
  47.         --       I don't need UnitExists as UnitClassification returns "normal" for non-present units
  48.         if UnitExists("boss" .. i) and not UnitIsFriend("boss" .. i, "player") then
  49.             numBosses = numBosses + 1
  50.         end
  51.     end
  52.     print(prefix, numBosses)
  53. end
  54.  
  55. function frame:PLAYER_REGEN_ENABLED()
  56.     for player in pairs(whisperers) do
  57.         local presenceID = tonumber(player)
  58.         if presenceID then
  59.             BNSendWhisper(presenceID, combatEndedMsg)
  60.         else
  61.             SendChatMessage(combatEndedMsg, "WHISPER", nil, player)
  62.         end
  63.     end
  64.     numBosses = 0
  65.     wipe(whisperers)
  66. end
  67.  
  68. function frame:CHAT_MSG_WHISPER(msg, sender, _, _, _, flag)
  69.     if flag == "GM" or numBosses == 0 then return end
  70.  
  71.     local reply = GetReply(sender, msg)
  72.     if reply then
  73.         SendChatMessage(reply, "WHISPER", nil, sender)
  74.     end
  75. end
  76.  
  77. function frame:CHAT_MSG_BN_WHISPER(msg, sender, _, _, _, _, _, _, _, _, _, _, presenceID)
  78.     if numBosses == 0 then return end
  79.  
  80.     local _, _, _, _, toonName, _, client = BNGetFriendInfoByID(presenceID) -- client: WoW, D3
  81.     local reply = GetReply(toonName, msg, presenceID, client)
  82.     if reply then
  83.         BNSendWhisper(presenceID, reply)
  84.     end
  85. end
  86.  
  87. function frame:ADDON_LOADED(name)
  88.     if name ~= addon then return end
  89.  
  90.     self:UnregisterEvent("ADDON_LOADED")
  91.  
  92.     if not disableChatFilter then
  93.         ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_INFORM", function(self, event, msg)
  94.             if string.find(msg, "^" .. prefix) then return true end
  95.         end)
  96.         ChatFrame_AddMessageEventFilter("CHAT_MSG_BN_WHISPER_INFORM", function(self, event, msg)
  97.             if string.find(msg, "^" .. prefix) then return true end
  98.         end)
  99.     end
  100. end
  Reply With Quote
 

WoWInterface » Developer Discussions » General Authoring Discussion » Encounter Detection


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off