Avoidance.lua 3.29 KB
Newer Older
Tukz's avatar
Tukz committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
local T, C, L = select(2, ...):unpack()

local DataText = T["DataTexts"]
local format = format
local abs = abs

local Dodge, Parry, Block, Avoidance, TargetLevel, PlayerLevel, BaseMissChance, LevelDifference
local MyRace = select(2, UnitRace("Player"))
local GetBlockChance = GetBlockChance
local GetParryChance = GetParryChance
local GetDodgeChance = GetDodgeChance

local Update = function(self)
	TargetLevel = UnitLevel("target")
	PlayerLevel = UnitLevel("player")
	local BaseMissChance, LevelDifference, Avoidance
Tukz's avatar
Tukz committed
17

Tukz's avatar
Tukz committed
18
	if TargetLevel == -1 then
Azilroka's avatar
Azilroka committed
19
		BaseMissChance = (5 - (3 * .2)) --Boss Value
Tukz's avatar
Tukz committed
20 21
		LevelDifference = 3
	elseif TargetLevel > PlayerLevel then
Resike's avatar
Resike committed
22
		BaseMissChance = (5 - ((TargetLevel - PlayerLevel) * .2)) --Mobs above player level
Tukz's avatar
Tukz committed
23 24
		LevelDifference = (TargetLevel - PlayerLevel)
	elseif TargetLevel < PlayerLevel and TargetLevel > 0 then
Resike's avatar
Resike committed
25
		BaseMissChance = (5 + ((PlayerLevel - TargetLevel) * .2)) --Mobs below player level
Tukz's avatar
Tukz committed
26 27 28 29 30
		LevelDifference = (TargetLevel - PlayerLevel)
	else
		BaseMissChance = 5 --Sets miss chance of attacker level if no target exists, lv80=5, 81=4.2, 82=3.4, 83=2.6
		LevelDifference = 0
	end
Tukz's avatar
Tukz committed
31

Tukz's avatar
Tukz committed
32 33 34 35 36 37 38 39 40
	if (MyRace == "NightElf") then
		BaseMissChance = BaseMissChance + 2
	end

	if (LevelDifference >= 0) then
		Dodge = (GetDodgeChance() - LevelDifference * 0.2)
		Parry = (GetParryChance() - LevelDifference * 0.2)
		Block = (GetBlockChance() - LevelDifference * 0.2)
		Avoidance = (Dodge + Parry + Block)
Tukz's avatar
Tukz committed
41

Tukz's avatar
Tukz committed
42 43 44 45 46 47
		self.Text:SetText(DataText.NameColor..L.DataText.AvoidanceShort.."|r"..DataText.ValueColor..format("%.2f", Avoidance).."|r")
	else
		Dodge = (GetDodgeChance() + abs(LevelDifference * 0.2))
		Parry = (GetParryChance() + abs(LevelDifference * 0.2))
		Block = (GetBlockChance() + abs(LevelDifference * 0.2))
		Avoidance = (Dodge + Parry + Block)
Tukz's avatar
Tukz committed
48

Tukz's avatar
Tukz committed
49 50 51 52 53 54 55 56
		self.Text:SetText(DataText.NameColor..L.DataText.AvoidanceShort.."|r"..DataText.ValueColor..format("%.2f", Avoidance).."|r")
	end
end

local OnEnter = function(self)
	if (not InCombatLockdown()) then
		GameTooltip:SetOwner(self:GetTooltipAnchor())
		GameTooltip:ClearLines()
Tukz's avatar
Tukz committed
57

Tukz's avatar
Tukz committed
58 59 60 61 62 63 64
		if (TargetLevel > 1) then
			GameTooltip:AddDoubleLine(L.DataText.AvoidanceBreakdown.." ("..L.DataText.Level.." "..TargetLevel..")")
		elseif (TargetLevel == -1) then
			GameTooltip:AddDoubleLine(L.DataText.AvoidanceBreakdown.." ("..L.DataText.Boss..")")
		else
			GameTooltip:AddDoubleLine(L.DataText.AvoidanceBreakdown.." ("..L.DataText.Level.." "..TargetLevel..")")
		end
Tukz's avatar
Tukz committed
65

Tukz's avatar
Tukz committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
		GameTooltip:AddDoubleLine(L.DataText.Dodge, format("%.2f", Dodge) .. "%", 1, 1, 1, 1, 1, 1)
		GameTooltip:AddDoubleLine(L.DataText.Parry, format("%.2f", Parry) .. "%", 1, 1, 1, 1, 1, 1)
		GameTooltip:AddDoubleLine(L.DataText.Block, format("%.2f", Block) .. "%", 1, 1, 1, 1, 1, 1)
		GameTooltip:Show()
	end
end

local OnLeave = function()
	GameTooltip:Hide()
end

local Enable = function(self)
	self:RegisterEvent("UNIT_AURA")
	self:RegisterEvent("UNIT_INVENTORY_CHANGED")
	self:RegisterEvent("PLAYER_TARGET_CHANGED")
	self:RegisterEvent("PLAYER_ENTERING_WORLD")
	self:SetScript("OnEvent", Update)
	self:SetScript("OnEnter", OnEnter)
	self:SetScript("OnLeave", OnLeave)
	self:Update()
end

local Disable = function(self)
	self.Text:SetText("")
	self:UnregisterAllEvents()
	self:SetScript("OnEvent", nil)
	self:SetScript("OnEnter", nil)
	self:SetScript("OnLeave", nil)
end

Tukz's avatar
Tukz committed
96
DataText:Register(L.DataText.Avoidance, Enable, Disable, Update)