PageRenderTime 82ms CodeModel.GetById 41ms app.highlight 4ms RepoModel.GetById 36ms app.codeStats 0ms

/Tukui/modules/datatext/armor.lua

http://github.com/Asphyxia/Tukui
Lua | 55 lines | 47 code | 4 blank | 4 comment | 6 complexity | 903524e15fc1aa946ed3080ee23dee4f MD5 | raw file
 1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
 2--------------------------------------------------------------------
 3-- player Armor
 4--------------------------------------------------------------------
 5
 6if C["datatext"].armor and C["datatext"].armor > 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"].armor, Text)
15
16	local function Update(self)
17		baseArmor , effectiveArmor, armor, posBuff, negBuff = UnitArmor("player");
18		Text:SetText(L.datatext_armor..": "..T.datacolor..(effectiveArmor))
19		--Setup Armor Tooltip
20		self:SetAllPoints(Text)
21	end
22
23	Stat:RegisterEvent("UNIT_INVENTORY_CHANGED")
24	Stat:RegisterEvent("UNIT_AURA")
25	Stat:RegisterEvent("PLAYER_ENTERING_WORLD")
26	Stat:SetScript("OnMouseDown", function() ToggleCharacter("PaperDollFrame") end)
27	Stat:SetScript("OnEvent", Update)
28	Stat:SetScript("OnEnter", function(self)
29		if not InCombatLockdown() then
30			local anchor, panel, xoff, yoff = T.DataTextTooltipAnchor(Text)	
31			GameTooltip:SetOwner(panel, anchor, xoff, yoff)
32			GameTooltip:ClearLines()
33			GameTooltip:AddLine(L.datatext_mitigation)
34			local lv = 83
35			for i = 1, 4 do
36				local format = string.format
37				local mitigation = (effectiveArmor/(effectiveArmor+(467.5*lv-22167.5)));
38				if mitigation > .75 then
39					mitigation = .75
40				end
41				GameTooltip:AddDoubleLine(lv,format("%.2f", mitigation*100) .. "%",1,1,1)
42				lv = lv - 1
43			end
44			if UnitLevel("target") > 0 and UnitLevel("target") < UnitLevel("player") then
45				mitigation = (effectiveArmor/(effectiveArmor+(467.5*(UnitLevel("target"))-22167.5)));
46				if mitigation > .75 then
47					mitigation = .75
48				end
49				GameTooltip:AddDoubleLine(UnitLevel("target"),format("%.2f", mitigation*100) .. "%",1,1,1)
50			end
51			GameTooltip:Show()
52		end
53	end)
54	Stat:SetScript("OnLeave", function() GameTooltip:Hide() end)
55end