/
lowAvoidance.lua
133 lines (102 loc) · 4.27 KB
/
lowAvoidance.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
local L = setmetatable({}, {__index=function(t,i) return i end})
local result = {
miss = 0,
dodge = 0,
parry = 0,
block = 0,
critical = 0,
hit = 0,
}
local talentedcritreduct = 0;
local dataobj = LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject("lowAvoidance", {icon = "Interface\\Icons\\Ability_Defend", text = "|cffff0000"..L["Critable"].."|r"})
local f = CreateFrame("Frame")
f:SetScript("OnEvent", function(self, event, ...) if self[event] then return self[event](self, event, ...) end end)
local function UpdateHitTable()
local defbase, defbonus = UnitDefense("player");
local defskillmod = GetDodgeBlockParryChanceFromDefense() - 0.6;
result.miss = math.max(5 + defskillmod, 0);
result.dodge = math.max(0, GetDodgeChance() - 0.6);
result.parry = math.max(0, GetParryChance() - 0.6);
result.block = math.max(0, GetBlockChance() - 0.6);
result.critical = math.max(5 - defskillmod - talentedcritreduct - GetCombatRatingBonus(CR_CRIT_TAKEN_MELEE), 0);
result.hit = 0;
local mainhand = GetInventoryItemLink("player", 16);
if not mainhand then result.parry = 0; else
local _, _, _, _, _, _, _, _, mainhandtype = GetItemInfo(mainhand);
if (mainhandtype ~= "INVTYPE_WEAPON") and (mainhandtype ~= "INVTYPE_WEAPONMAINHAND") and (mainhandtype ~= "INVTYPE_2HWEAPON") then
result.parry = 0;
end
end
local offhand = GetInventoryItemLink("player", 17);
if not offhand then result.block = 0; else
local _, _, _, _, _, _, _, _, offhandtype = GetItemInfo(offhand);
if offhandtype ~= "INVTYPE_SHIELD" then
result.block = 0;
end
end
local leftover = 100;
result.miss = min(result.miss, leftover);
leftover = leftover - result.miss;
result.dodge = min(result.dodge, leftover);
leftover = leftover - result.dodge;
result.parry = min(result.parry, leftover);
leftover = leftover - result.parry;
result.block = min(result.block, leftover);
leftover = leftover - result.block;
result.critical = min(result.critical, leftover);
leftover = leftover - result.critical;
result.hit = leftover;
if result.critical > 0 then
dataobj.text = "|cffff0000"..L["Critable"].."|r";
else
dataobj.text = "|cff00ff00"..L["Uncritable"].."|r";
end
end
function f:PLAYER_LOGIN()
self:RegisterEvent("UNIT_INVENTORY_CHANGED");
self:RegisterEvent("UNIT_AURA");
self:RegisterEvent("PLAYER_TARGET_CHANGED");
self:UnregisterEvent("PLAYER_LOGIN")
self.PLAYER_LOGIN = nil
local _, class = UnitClass("player");
-- SoTF
if ( class == "DRUID" ) then
function self:CHARACTER_POINTS_CHANGED() talentedcritreduct = select(5, GetTalentInfo(2, 16)) end
self:RegisterEvent("CHARACTER_POINTS_CHANGED")
self:CHARACTER_POINTS_CHANGED()
-- SoH
elseif ( class == "ROGUE" ) then
function self:CHARACTER_POINTS_CHANGED() talentedcritreduct = select(5, GetTalentInfo(3, 3)) end
self:RegisterEvent("CHARACTER_POINTS_CHANGED")
self:CHARACTER_POINTS_CHANGED()
end
UpdateHitTable()
end
f.UNIT_INVENTORY_CHANGED = UpdateHitTable
f.UNIT_AURA = UpdateHitTable
f.PLAYER_TARGET_CHANGED = UpdateHitTable
local function GetTipAnchor(frame)
local x,y = frame:GetCenter()
if not x or not y then return "TOPLEFT", "BOTTOMLEFT" end
local hhalf = (x > UIParent:GetWidth() * 2 / 3) and "RIGHT" or (x < UIParent:GetWidth() / 3) and "LEFT" or ""
local vhalf = (y > UIParent:GetHeight() / 2) and "TOP" or "BOTTOM"
return vhalf..hhalf, frame, (vhalf == "TOP" and "BOTTOM" or "TOP")..hhalf
end
function dataobj.OnLeave() GameTooltip:Hide() end
function dataobj.OnEnter(self)
GameTooltip:SetOwner(self, "ANCHOR_NONE")
GameTooltip:SetPoint(GetTipAnchor(self))
GameTooltip:ClearLines()
GameTooltip:AddLine("lowAvoidance")
GameTooltip:AddLine(" ")
GameTooltip:AddLine(L["Defensive Combat Table vs Boss Level Mob"])
GameTooltip:AddLine(" ")
GameTooltip:AddDoubleLine(L["Miss"], string.format("%.2f%%", result.miss))
GameTooltip:AddDoubleLine(L["Dodge"], string.format("%.2f%%", result.dodge))
GameTooltip:AddDoubleLine(L["Parry"], string.format("%.2f%%", result.parry))
GameTooltip:AddDoubleLine(L["Block"], string.format("%.2f%%", result.block))
GameTooltip:AddDoubleLine(L["Critical"], string.format("%.2f%%", result.critical))
GameTooltip:AddDoubleLine(L["Hit"], string.format("%.2f%%", result.hit))
GameTooltip:Show()
end
if IsLoggedIn() then f:PLAYER_LOGIN() else f:RegisterEvent("PLAYER_LOGIN") end