-
Notifications
You must be signed in to change notification settings - Fork 1
/
XiconPlateBuffs.lua
180 lines (153 loc) · 6.91 KB
/
XiconPlateBuffs.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
local ADDON_NAME = "XiconPlateBuffs"
local select, tonumber, tostring = select, tonumber, tostring
local XiconDebuffModule
local VERSION = "v1.0.1-Release"
local print = function(s)
local str = s
if s == nil then str = "nil" end
if type(str) == "boolean" then
if str then
str = "true"
else
str = "false"
end
end
DEFAULT_CHAT_FRAME:AddMessage("|cffa0f6aa[".. ADDON_NAME .."]|r: " .. str)
end
---------------------------------------------------------------------------------------------
-- CORE
---------------------------------------------------------------------------------------------
local XiconPlateBuffs = CreateFrame("Frame", "XiconPlateBuffs", UIParent)
LibStub("AceAddon-3.0"):NewAddon(XiconPlateBuffs, ADDON_NAME)
XiconPlateBuffs.modules = {}
function XiconPlateBuffs:OnInitialize()
self.knownNameplates = {}
self.numKnownNameplates = 0
self.Aloft = IsAddOnLoaded("Aloft")
self.SoHighPlates = IsAddOnLoaded("SoHighPlates")
self.ElvUI = IsAddOnLoaded("ElvUI")
self.ShaguPlates = IsAddOnLoaded("ShaguPlates-tbc") or IsAddOnLoaded("ShaguPlates")
XiconPlateBuffs:CreateOptions()
for _,module in pairs(self.modules) do
module:OnInitialize()
end
XiconDebuffModule = self.modules["XiconDebuffModule"]
LibStub("AceConsole-3.0"):RegisterChatCommand("xpb", function() LibStub("AceConfigDialog-3.0"):Open("XiconPlateBuffs") end)
LibStub("AceConsole-3.0"):RegisterChatCommand("xpbconfig", function() LibStub("AceConfigDialog-3.0"):Open("XiconPlateBuffs") end)
print(VERSION .. " loaded")
print("write /xpb or /xpbconfig for options")
print("look out for updates under https://github.com/XiconQoo/XiconPlateBuffs")
end
function XiconPlateBuffs:NewModule(name)
local module = CreateFrame("Frame", name)
self.modules[name] = module
return module
end
---------------------------------------------------------------------------------------------
-- TABLE & MATH FUNCTIONS
---------------------------------------------------------------------------------------------
function table.removekey(table, key)
local element = table[key]
table[key] = nil
return element
end
function XiconPlateBuffs:GetNamePlateName(namePlate)
local name
if self.Aloft then
if namePlate.aloftData then
name = namePlate.aloftData.name
end
elseif self.SoHighPlates then
if namePlate.oldname or namePlate.name then
name = (namePlate.oldname and namePlate.oldname:GetText()) or (namePlate.name and namePlate.name:GetText())
end
else
if self.ElvUI then
if namePlate.UnitFrame then
name = namePlate.UnitFrame.oldName:GetText()
end
end
if not name then
local _, _, _, _, nameRegion1, nameRegion2 = namePlate:GetRegions()
if strmatch(nameRegion1:GetText(), "%d") then
name = nameRegion2:GetText()
else
name = nameRegion1:GetText()
end
end
end
return name
end
---------------------------------------------------------------------------------------------
-- EVENT HANDLERS
---------------------------------------------------------------------------------------------
local events = {} -- store event functions to be assigned to reputation frame
function events:PLAYER_ENTERING_WORLD()
XiconPlateBuffs.numKnownNameplates = 0
XiconPlateBuffs.knownNameplates = {}
end
---------------------------------------------------------------------------------------------
-- REGISTER EVENTS
---------------------------------------------------------------------------------------------
XiconPlateBuffs:SetScript("OnEvent", function(self, event, ...)
events[event](self, ...); -- call one of the functions above
end);
for k, _ in pairs(events) do
XiconPlateBuffs:RegisterEvent(k); -- Register all events for which handlers have been defined
end
---------------------------------------------------------------------------------------------
-- ON_UPDATE (periodically update nameplates)
---------------------------------------------------------------------------------------------
local NameplateFrame = CreateFrame("Frame")
NameplateFrame:SetScript("OnUpdate", function(self, elapsed)
local num = WorldFrame:GetNumChildren()
if XiconPlateBuffs.numKnownNameplates < num then
XiconPlateBuffs.numKnownNameplates = num
for i = 1, num do
local namePlate = select(i, WorldFrame:GetChildren())
if namePlate:GetNumRegions() > 2 and namePlate:GetNumChildren() >= 1 and not XiconPlateBuffs.knownNameplates[namePlate] then
namePlate.xiconFrameLevel = i
XiconPlateBuffs.knownNameplates[namePlate] = true
end
end
end
end)
local updateInterval, lastUpdate = .01, 0
XiconPlateBuffs:SetScript("OnUpdate", function(self, elapsed)
lastUpdate = lastUpdate + elapsed
if lastUpdate > updateInterval then
-- do stuff
for namePlate,_ in pairs(self.knownNameplates) do
if namePlate:IsVisible() then
local name = self:GetNamePlateName(namePlate)
if name then
if self.testMode then
local dstGUID = "0x00001312031"
XiconDebuffModule:addDebuff(string.gsub(name, "%s+", ""), dstGUID, 29166, 15) -- innervate
XiconDebuffModule:addDebuff(string.gsub(name, "%s+", ""), dstGUID, 642, 12) -- divine shield
XiconDebuffModule:addDebuff(string.gsub(name, "%s+", ""), dstGUID, 22570, 3) -- maim
XiconDebuffModule:addDebuff(string.gsub(name, "%s+", ""), dstGUID, 25274, 6) -- Intercept Stun
XiconDebuffModule:addDebuff(string.gsub(name, "%s+", ""), dstGUID, 14309, 9) -- freezing trap
XiconDebuffModule:addDebuff(string.gsub(name, "%s+", ""), dstGUID, 12826, 12) -- polymorph
end
-- check if namePlate is target or mouseover
local border, castborder, casticon, highlight, nameText, levelText, levelIcon, raidIcon = namePlate:GetRegions()
local target = UnitExists("target") and namePlate:GetAlpha() == 1 or nil
local mouseover = UnitExists("mouseover") and highlight:IsShown() or nil
if target then
XiconDebuffModule:updateNameplate("target", namePlate, name)
elseif mouseover then
XiconDebuffModule:updateNameplate("mouseover", namePlate, name)
else
XiconDebuffModule:assignDebuffs(name, namePlate, false)
end
end
else
XiconDebuffModule.hideIcons(namePlate)
end
end
self.testMode = false
-- end do stuff
lastUpdate = 0;
end
end)