PageRenderTime 162ms CodeModel.GetById 80ms app.highlight 5ms RepoModel.GetById 76ms app.codeStats 0ms

/Tukui/modules/datatext/dps.lua

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