PageRenderTime 30ms CodeModel.GetById 20ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/Tukui/modules/datatext/avoidance.lua

http://github.com/Asphyxia/Tukui
Lua | 85 lines | 72 code | 9 blank | 4 comment | 7 complexity | a8630cefc30ac9e187ed3c55cecaa8b9 MD5 | raw file
 1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
 2--------------------------------------------------------------------
 3-- Player Avoidance
 4--------------------------------------------------------------------
 5
 6if C["datatext"].avd and C["datatext"].avd > 0 then
 7	local Stat = CreateFrame("Frame")
 8	Stat:EnableMouse(true)
 9	Stat:SetFrameStrata("HIGH")
10	Stat:SetFrameLevel(3)
11
12	local Text  = TukuiInfoLeft:CreateFontString(nil, "OVERLAY")
13	Text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
14	T.PP(C["datatext"].avd, Text)
15	
16	local targetlv
17	local playerlv
18
19	local function Update(self)
20		local format = string.format
21		targetlv, playerlv = UnitLevel("target"), UnitLevel("player")
22		
23		if targetlv == -1 then
24			basemisschance = (5 - (3*.2))  --Boss Value
25			leveldifference = 3
26		elseif targetlv > playerlv then
27			basemisschance = (5 - ((targetlv - playerlv)*.2)) --Mobs above player level
28			leveldifference = (targetlv - playerlv)
29		elseif targetlv < playerlv and targetlv > 0 then
30			basemisschance = (5 + ((playerlv - targetlv)*.2)) --Mobs below player level
31			leveldifference = (targetlv - playerlv)
32		else
33			basemisschance = 5 --Sets miss chance of attacker level if no target exists, lv80=5, 81=4.2, 82=3.4, 83=2.6
34			leveldifference = 0
35		end
36
37		if leveldifference >= 0 then
38			dodge = (GetDodgeChance()-leveldifference*.2)
39			parry = (GetParryChance()-leveldifference*.2)
40			block = (GetBlockChance()-leveldifference*.2)
41			MissChance = (basemisschance + 1/(0.0625 + 0.956/(GetCombatRating(CR_DEFENSE_SKILL)/4.91850*0.04)))
42			avoidance = (dodge+parry+block+MissChance)
43			Text:SetText(L.datatext_playeravd..T.datacolor..format("%.2f", avoidance))
44		else
45			dodge = (GetDodgeChance()+abs(leveldifference*.2))
46			parry = (GetParryChance()+abs(leveldifference*.2))
47			block = (GetBlockChance()+abs(leveldifference*.2))
48			MissChance = (basemisschance + 1/(0.0625 + 0.956/(GetCombatRating(CR_DEFENSE_SKILL)/4.91850*0.04)))
49			avoidance = (dodge+parry+block+MissChance)
50			Text:SetText(L.datatext_playeravd..T.datacolor..format("%.2f", avoidance))
51		end
52
53		--Setup Avoidance Tooltip
54		self:SetAllPoints(Text)
55	end
56
57
58	Stat:RegisterEvent("UNIT_AURA")
59	Stat:RegisterEvent("UNIT_INVENTORY_CHANGED")
60	Stat:RegisterEvent("PLAYER_TARGET_CHANGED")
61	Stat:RegisterEvent("PLAYER_ENTERING_WORLD")
62	Stat:SetScript("OnEvent", Update)
63	Stat:SetScript("OnEnter", function(self)
64		if not InCombatLockdown() then
65			local anchor, yoff = T.DataTextTooltipAnchor(Text)
66			GameTooltip:SetOwner(self, anchor, 0, yoff)
67			GameTooltip:ClearAllPoints()
68			GameTooltip:SetPoint("BOTTOM", self, "TOP", 0, T.mult)
69			GameTooltip:ClearLines()
70			if targetlv > 1 then
71				GameTooltip:AddDoubleLine(L.datatext_avoidancebreakdown.." ("..L.datatext_lvl.." "..targetlv..")")
72			elseif targetlv == -1 then
73				GameTooltip:AddDoubleLine(L.datatext_avoidancebreakdown.." ("..L.datatext_boss..")")
74			else
75				GameTooltip:AddDoubleLine(L.datatext_avoidancebreakdown.." ("..L.datatext_lvl.." "..targetlv..")")
76			end
77			GameTooltip:AddDoubleLine(L.datatext_miss,format("%.2f",MissChance) .. "%",1,1,1,  1,1,1)
78			GameTooltip:AddDoubleLine(L.datatext_dodge,format("%.2f",dodge) .. "%",1,1,1,  1,1,1)
79			GameTooltip:AddDoubleLine(L.datatext_parry,format("%.2f",parry) .. "%",1,1,1,  1,1,1)
80			GameTooltip:AddDoubleLine(L.datatext_block,format("%.2f",block) .. "%",1,1,1,  1,1,1)
81			GameTooltip:Show()
82		end
83	end)
84	Stat:SetScript("OnLeave", function() GameTooltip:Hide() end)
85end