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