Guest User

Untitled

a guest
May 4th, 2015
243
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CHC = {}
  2.  
  3. local isDebug = true
  4.  
  5. local rawChainHealData = {
  6.     totalCasts = 0,
  7.     history = {
  8.         targets = 0,
  9.         multistrikes = 0,
  10.         data = {
  11.         }
  12.     }
  13. }
  14.  
  15. -- Utility functions
  16. local print = function (msg)
  17.     if isDebug == true then
  18.         DEFAULT_CHAT_FRAME:AddMessage(msg)
  19.     end
  20. end
  21.  
  22. -- Register Frame
  23. function CHC:registerFrame()
  24.     local CHCatcher_EventFrame = CreateFrame("Frame")
  25.     CHC:setEventHandlers(CHCatcher_EventFrame)
  26. end
  27.  
  28. -- Register Events
  29. function CHC:setEventHandlers(Catcher)
  30.     print("EventListener activated")
  31.     Catcher:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
  32.     Catcher:RegisterEvent("COMBAT_LOG_EVENT")
  33.     CHC:handleEvents(Catcher)
  34. end
  35.  
  36. function CHC:handleEvents(Catcher)
  37.     Catcher:SetScript("OnEvent", function(self, event, ...)
  38.         if event == "UNIT_SPELLCAST_SUCCEEDED" then
  39.             CHC:spellCast_Succeeded(...)
  40.         elseif event == "COMBAT_LOG_EVENT" then
  41.             CHC:filterTheCombatLog(...)
  42.         end
  43.     end)
  44. end
  45.  
  46. function CHC:spellCast_Succeeded(...)
  47.     local unitID, spell, rank, lineID, spellID = select(1, ...)
  48.  
  49.     -- Only do stuff on chain heal casts that succeed
  50.     if spellId == 1064 or spell == "Chain Heal" then
  51.         print("Finished casting " .. spell)
  52.     end
  53. end
  54.  
  55. function CHC:filterTheCombatLog(...)
  56.     local type = select(2, ...)
  57.  
  58.     -- Check if combat log event is a heal
  59.     if type == "SPELL_HEAL" then
  60.         local spellId, spellName, spellSchool = select(12, ...)
  61.  
  62.         -- If the heal event matches chain heal and all that.
  63.         if spellId == 1064 or spellName == "Chain Heal" then
  64.  
  65.             -- Check if the heal was a multistrike
  66.             -- Save those separately
  67.             if select(19, ...) == true then
  68.                 rawChainHealData.history.multistrikes = rawChainHealData.history.multistrikes + 1
  69.                 print("Multistrike #" .. rawChainHealData.history.multistrikes)
  70.             else
  71.                 rawChainHealData.history.targets = rawChainHealData.history.targets + 1
  72.                 print("Hit #" .. rawChainHealData.history.targets .. " at " .. select(1, ...))
  73.             end
  74.  
  75.             -- Save some of the data for later use.
  76.             local spellData = {
  77.                 timestamp = select(1, ...),
  78.                 target = select(9, ...),
  79.                 source = select(5, ...),
  80.                 amount = select(15, ...),
  81.                 overhealing = select(16, ...),
  82.                 multistrike = select(19, ...)
  83.             }
  84.             table.insert(rawChainHealData.history.data, spellData)
  85.         end
  86.     end
  87. end
  88.  
  89. CHC:registerFrame()
RAW Paste Data