-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalEnemyCD.lua
201 lines (185 loc) · 4.77 KB
/
alEnemyCD.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
-- Config start
local anchor = "CENTER"
local x, y = -70, -70
local size = 26
local spacing = 5
local direction = "UP"
local show = {
["none"] = true,
["pvp"] = true,
["arena"] = true,
}
-- Config end
local spells = {
[1766] = 10, -- Kick
[6552] = 10, -- Pummel
[2139] = 24, -- Counterspell
[19647] = 24, -- Spell Lock
[8122] = 30, -- Psychic Scream
[47476] = 120, -- Strangulate
[47528] = 10, -- Mind Freeze
[29166] = 180, -- Innervate
[49039] = 120, -- Lichborne
[54428] = 120, -- Divine Plea
[1022] = 300, -- Hand of Protection
[16190] = 180, -- Mana Tide Totem
[51514] = 45, -- Hex
[15487] = 45, -- Silence
[2094] = 180, -- Blind
}
local cfg = {}
if IsAddOnLoaded("alInterface") then
local config = {
general = {
size = {
order = 1,
value = size,
type = "range",
min = 10,
max = 50,
},
spacing = {
order = 2,
value = spacing,
type = "range",
min = 0,
max = 30,
},
direction = {
order = 3,
value = direction,
type = "select",
select = {"UP", "DOWN", "LEFT", "RIGHT"},
},
},
showin = {
world = {
order = 1,
value = true,
},
bg = {
order = 2,
value = true,
},
arena = {
order = 3,
value = true,
},
},
}
UIConfigGUI.enemycd = config
UIConfig.enemycd = cfg
local frame = CreateFrame("Frame")
frame:RegisterEvent("VARIABLES_LOADED")
frame:SetScript("OnEvent", function(self, event)
size = cfg.general.size
spacing = cfg.general.spacing
direction = cfg.general.direction
show = {
["none"] = cfg.showin.world,
["pvp"] = cfg.showin.bg,
["arena"] = cfg.showin.arena,
}
end)
end
local backdrop = {
bgFile = [=[Interface\ChatFrame\ChatFrameBackground]=],
edgeFile = [=[Interface\ChatFrame\ChatFrameBackground]=], edgeSize = 1,
insets = {top = 0, left = 0, bottom = 0, right = 0},
}
local icons = {}
local band = bit.band
local anchorframe = CreateFrame("Frame", "EnemyCD", UIParent)
anchorframe:SetSize(size, size)
anchorframe:SetPoint(anchor, x, y)
if UIMovableFrames then tinsert(UIMovableFrames, anchorframe) end
local CreateBG = CreateBG or function(parent)
local bg = CreateFrame("Frame", nil, parent)
bg:SetPoint("TOPLEFT", -1, 1)
bg:SetPoint("BOTTOMRIGHT", 1, -1)
bg:SetFrameLevel(parent:GetFrameLevel() - 1)
bg:SetBackdrop(backdrop)
bg:SetBackdropColor(0, 0, 0, 0.5)
bg:SetBackdropBorderColor(0, 0, 0, 1)
return bg
end
local UpdatePositions = function()
for i = 1, #icons do
icons[i]:ClearAllPoints()
if i == 1 then
icons[i]:SetPoint("CENTER", anchorframe, 0, 0)
else
if direction == "UP" then
icons[i]:SetPoint("BOTTOM", icons[i-1], "TOP", 0, spacing)
elseif direction == "DOWN" then
icons[i]:SetPoint("TOP", icons[i-1], "BOTTOM", 0, -spacing)
elseif direction == "RIGHT" then
icons[i]:SetPoint("LEFT", icons[i-1], "RIGHT", spacing, 0)
elseif direction == "LEFT" then
icons[i]:SetPoint("RIGHT", icons[i-1], "LEFT", -spacing, 0)
end
end
icons[i].id = i
end
end
local StopTimer = function(icon)
icon:SetScript("OnUpdate", nil)
icon:Hide()
tremove(icons, icon.id)
UpdatePositions()
end
local IconUpdate = function(self, elapsed)
if (self.endTime < GetTime()) then
StopTimer(self)
end
end
local CreateIcon = function()
local icon = CreateFrame("frame", nil, UIParent)
icon:SetWidth(size)
icon:SetHeight(size)
icon.bg = CreateBG(icon)
icon.Cooldown = CreateFrame("Cooldown", nil, icon)
icon.Cooldown:SetAllPoints(icon)
icon.Texture = icon:CreateTexture(nil, "BORDER")
icon.Texture:SetAllPoints(icon)
return icon
end
local StartTimer = function(sID)
local _,_,texture = GetSpellInfo(sID)
local icon = CreateIcon()
icon.Texture:SetTexture(texture)
icon.Texture:SetTexCoord(0.07, 0.93, 0.07, 0.93)
icon.endTime = GetTime() + spells[sID]
icon:Show()
icon:SetScript("OnUpdate", IconUpdate)
CooldownFrame_SetTimer(icon.Cooldown, GetTime(), spells[sID], 1)
tinsert(icons, icon)
UpdatePositions()
end
local OnEvent = function(self, event, ...)
if event == "COMBAT_LOG_EVENT_UNFILTERED" then
local timestamp, eventType, _, sourceGUID, sourceName, sourceFlags, _, _, _, _, _, spellID, spellName = ...
if eventType == "SPELL_CAST_SUCCESS" and band(sourceFlags, COMBATLOG_OBJECT_REACTION_HOSTILE) == COMBATLOG_OBJECT_REACTION_HOSTILE then
if sourceName ~= UnitName("player") then
if spells[spellID] and show[select(2, IsInInstance())] then
StartTimer(spellID)
end
end
end
elseif (event == "ZONE_CHANGED_NEW_AREA") then
for k, v in pairs(icons) do
StopTimer(v)
end
end
end
local addon = CreateFrame("frame")
addon:SetScript('OnEvent', OnEvent)
addon:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
addon:RegisterEvent("ZONE_CHANGED_NEW_AREA")
SlashCmdList["EnemyCD"] = function(msg)
StartTimer(47528)
StartTimer(19647)
StartTimer(47476)
StartTimer(51514)
end
SLASH_EnemyCD1 = "/enemycd"