/Tukui/modules/datatext/dps.lua

http://github.com/Asphyxia/Tukui · Lua · 103 lines · 80 code · 17 blank · 6 comment · 18 complexity · ba326ca51911bdd0626928d16b5ab81a MD5 · raw file

  1. local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2. --------------------------------------------------------------------
  3. -- SUPPORT FOR DPS Feed...
  4. --------------------------------------------------------------------
  5. if C["datatext"].dps_text and C["datatext"].dps_text > 0 then
  6. local events = {SWING_DAMAGE = true, RANGE_DAMAGE = true, SPELL_DAMAGE = true, SPELL_PERIODIC_DAMAGE = true, DAMAGE_SHIELD = true, DAMAGE_SPLIT = true, SPELL_EXTRA_ATTACKS = true}
  7. local DPS_FEED = CreateFrame("Frame")
  8. local player_id = UnitGUID("player")
  9. local dmg_total, last_dmg_amount = 0, 0
  10. local cmbt_time = 0
  11. local pet_id = UnitGUID("pet")
  12. local dText = TukuiInfoLeft:CreateFontString(nil, "OVERLAY")
  13. dText:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  14. dText:SetText(L.datatext_dps,T.datacolor, " 0.0 ")
  15. T.PP(C["datatext"].dps_text, dText)
  16. DPS_FEED:EnableMouse(true)
  17. DPS_FEED:SetFrameStrata("HIGH")
  18. DPS_FEED:SetFrameLevel(3)
  19. DPS_FEED:Height(20)
  20. DPS_FEED:Width(100)
  21. DPS_FEED:SetAllPoints(dText)
  22. DPS_FEED:SetScript("OnEvent", function(self, event, ...) self[event](self, ...) end)
  23. DPS_FEED:RegisterEvent("PLAYER_LOGIN")
  24. DPS_FEED:SetScript("OnUpdate", function(self, elap)
  25. if UnitAffectingCombat("player") then
  26. cmbt_time = cmbt_time + elap
  27. end
  28. dText:SetText(getDPS())
  29. end)
  30. function DPS_FEED:PLAYER_LOGIN()
  31. DPS_FEED:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  32. DPS_FEED:RegisterEvent("PLAYER_REGEN_ENABLED")
  33. DPS_FEED:RegisterEvent("PLAYER_REGEN_DISABLED")
  34. DPS_FEED:RegisterEvent("UNIT_PET")
  35. player_id = UnitGUID("player")
  36. DPS_FEED:UnregisterEvent("PLAYER_LOGIN")
  37. end
  38. function DPS_FEED:UNIT_PET(unit)
  39. if unit == "player" then
  40. pet_id = UnitGUID("pet")
  41. end
  42. end
  43. -- handler for the combat log. used http://www.wowwiki.com/API_COMBAT_LOG_EVENT for api
  44. function DPS_FEED:COMBAT_LOG_EVENT_UNFILTERED(...)
  45. -- filter for events we only care about. i.e heals
  46. if not events[select(2, ...)] then return end
  47. -- only use events from the player
  48. local id = select(4, ...)
  49. if id == player_id or id == pet_id then
  50. if select(2, ...) == "SWING_DAMAGE" then
  51. if T.toc < 40200 then
  52. last_dmg_amount = select(10, ...)
  53. else
  54. last_dmg_amount = select(12, ...)
  55. end
  56. else
  57. if T.toc < 40200 then
  58. last_dmg_amount = select(13, ...)
  59. else
  60. last_dmg_amount = select(15, ...)
  61. end
  62. end
  63. dmg_total = dmg_total + last_dmg_amount
  64. end
  65. end
  66. function getDPS()
  67. if (dmg_total == 0) then
  68. return (L.datatext_dps..T.datacolor.. " 0.0 ")
  69. else
  70. return string.format(L.datatext_dps..T.datacolor.. "%.1f ", (dmg_total or 0) / (cmbt_time or 1))
  71. end
  72. end
  73. function DPS_FEED:PLAYER_REGEN_ENABLED()
  74. dText:SetText(getDPS())
  75. end
  76. function DPS_FEED:PLAYER_REGEN_DISABLED()
  77. cmbt_time = 0
  78. dmg_total = 0
  79. last_dmg_amount = 0
  80. end
  81. DPS_FEED:SetScript("OnMouseDown", function (self, button, down)
  82. cmbt_time = 0
  83. dmg_total = 0
  84. last_dmg_amount = 0
  85. end)
  86. end