/Tukui/modules/datatext/hps.lua

http://github.com/Asphyxia/Tukui · Lua · 90 lines · 67 code · 16 blank · 7 comment · 13 complexity · fe3bc2a761fb4239662ae52824e3cd28 MD5 · raw file

  1. local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2. --------------------------------------------------------------------
  3. -- SUPPORT FOR HPS Feed...
  4. --------------------------------------------------------------------
  5. if C["datatext"].hps_text and C["datatext"].hps_text > 0 then
  6. local events = {SPELL_HEAL = true, SPELL_PERIODIC_HEAL = true}
  7. local HPS_FEED = CreateFrame("Frame")
  8. local player_id = UnitGUID("player")
  9. local actual_heals_total, cmbt_time = 0
  10. local hText = TukuiInfoLeft:CreateFontString(nil, "OVERLAY")
  11. hText:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  12. hText:SetText(L.datatext_hps,T.datacolor, " 0.0 ")
  13. T.PP(C["datatext"].hps_text, hText)
  14. HPS_FEED:EnableMouse(true)
  15. HPS_FEED:SetFrameStrata("HIGH")
  16. HPS_FEED:SetFrameLevel(3)
  17. HPS_FEED:Height(20)
  18. HPS_FEED:Width(100)
  19. HPS_FEED:SetAllPoints(hText)
  20. HPS_FEED:SetScript("OnEvent", function(self, event, ...) self[event](self, ...) end)
  21. HPS_FEED:RegisterEvent("PLAYER_LOGIN")
  22. HPS_FEED:SetScript("OnUpdate", function(self, elap)
  23. if UnitAffectingCombat("player") then
  24. HPS_FEED:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  25. cmbt_time = cmbt_time + elap
  26. else
  27. HPS_FEED:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  28. end
  29. hText:SetText(get_hps())
  30. end)
  31. function HPS_FEED:PLAYER_LOGIN()
  32. HPS_FEED:RegisterEvent("PLAYER_REGEN_ENABLED")
  33. HPS_FEED:RegisterEvent("PLAYER_REGEN_DISABLED")
  34. player_id = UnitGUID("player")
  35. HPS_FEED:UnregisterEvent("PLAYER_LOGIN")
  36. end
  37. -- handler for the combat log. used http://www.wowwiki.com/API_COMBAT_LOG_EVENT for api
  38. function HPS_FEED:COMBAT_LOG_EVENT_UNFILTERED(...)
  39. -- filter for events we only care about. i.e heals
  40. if not events[select(2, ...)] then return end
  41. if event == "PLAYER_REGEN_DISABLED" then return end
  42. -- only use events from the player
  43. local id = select(4, ...)
  44. if id == player_id then
  45. if T.toc < 40200 then
  46. amount_healed = select(13, ...)
  47. amount_over_healed = select(14, ...)
  48. else
  49. amount_healed = select(15, ...)
  50. amount_over_healed = select(16, ...)
  51. end
  52. -- add to the total the healed amount subtracting the overhealed amount
  53. actual_heals_total = actual_heals_total + math.max(0, amount_healed - amount_over_healed)
  54. end
  55. end
  56. function HPS_FEED:PLAYER_REGEN_ENABLED()
  57. hText:SetText(get_hps)
  58. end
  59. function HPS_FEED:PLAYER_REGEN_DISABLED()
  60. cmbt_time = 0
  61. actual_heals_total = 0
  62. end
  63. HPS_FEED:SetScript("OnMouseDown", function (self, button, down)
  64. cmbt_time = 0
  65. actual_heals_total = 0
  66. end)
  67. function get_hps()
  68. if (actual_heals_total == 0) then
  69. return (L.datatext_hps..T.datacolor.. " 0.0 ")
  70. else
  71. return string.format(L.datatext_hps..T.datacolor.. "%.1f ", (actual_heals_total or 0) / (cmbt_time or 1))
  72. end
  73. end
  74. end