-
Notifications
You must be signed in to change notification settings - Fork 0
/
cooldown_tracker.lua
340 lines (276 loc) · 8.8 KB
/
cooldown_tracker.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
local ZAF = Zed_ArenaFrames
local addon = "Zed_ArenaFrames"
local UnitExists = UnitExists
local UnitName = UnitName
local UnitHealth, UnitHealthMax=UnitHealth, UnitHealthMax
local UnitPower, UnitPowerMax = UnitPower, UnitPowerMax
local UnitCastingInfo = UnitCastingInfo
local UnitChannelInfo = UnitChannelInfo
local UnitClass = UnitClass
local UnitGUID = UnitGUID
local select = select
local ipairs = ipairs
local unpack = unpack
local pairs = pairs
local _G = _G
local stringsub = string.sub
local stringmatch = string.match
local tinsert = table.insert
local floor = math.floor
ZAF.Cooldowns = CreateFrame("Frame")
ZAF.Cooldowns.GUID = {}
ZAF.NameGUIDs = {}
local CooldownModule = ZAF.Cooldowns
local latency_modifier = 0.05 -- not used currently
local CooldownByGUID = {}
-- GetSpellInfo(NUMBER) returns localized name of spell, english strings of the spells do not work on non english clients
ZAF.spell_cooldown = {
-- General
["Release of Light"] = 120, -- bauble of true blood
["PvP Trinket"] = 120,
["Every Man for Himself"] = 120,
-- Mage
[GetSpellInfo(2139)] = 24, -- counterspell
[GetSpellInfo(44572)] = 30, -- deep freeze
[GetSpellInfo(1953)] = 15, -- blink
["Ice Barrier"] = 60,
["Frost Nova"] = 24,
-- Warlock
[GetSpellInfo(19647)] = 24, -- spell lock
[GetSpellInfo(30283)] = 20, -- Shadowfury
["Demonic Circle: Teleport"] = 28,
-- DK
[GetSpellInfo(49203)] = 60, -- hungering cold
[GetSpellInfo(48707)] = 45, -- AMS
[GetSpellInfo(47528)] = 10, -- MF
[GetSpellInfo(49576)] = 25, -- grip
[GetSpellInfo(49206)] = 180, -- Gargoyle
-- Hunter
[GetSpellInfo(19503)] = 30, -- scatter
[GetSpellInfo(33490)] = 20, -- silencing shot
[GetSpellInfo(19263)] = 90, -- Deterence
["Readiness"] = 180,
-- Rogue
[GetSpellInfo(1766)] = 10, -- kick
[GetSpellInfo(31224)] = 60, -- cloak
[GetSpellInfo(36554)] = 20, -- step
[GetSpellInfo(51713)] = 60, -- sdance
["Blind"] = 120,
["Preparation"] = 300, -- no idea what's the cd they use it only once anyways
["Dismantle"] = 60,
-- Warrior
[GetSpellInfo(72)] = 12, -- shield bash
[GetSpellInfo(6552)] = 10 , -- pummel
[GetSpellInfo(23920)] = 10, -- reflect 23920
[GetSpellInfo(46924)] = 90, -- bstorm
["Disarm"] = 60,
-- Paladin
[GetSpellInfo(642)] = 300, -- bubble
["Holy Shock"] = 5, -- holy shock 48825
[GetSpellInfo(10278)] = 300, -- hand of protection
[GetSpellInfo(10308)] = 40, -- hammer of justice
[GetSpellInfo(1044)] = 25, -- freedom
[GetSpellInfo(64205)] = 120, -- divine sac
-- Priest
[GetSpellInfo(10890)] = 24, -- psychic scream
[GetSpellInfo(53007)]= 8, -- penance 53007
[GetSpellInfo(33206)] = 180, -- pain suppress
[GetSpellInfo(19236)] = 120, -- desp prayer
[GetSpellInfo(15487)] = 45, -- silence
[GetSpellInfo(47585)] = 75, -- dispersion (glyphed)
[GetSpellInfo(64044)] = 120, -- psychic horror
-- Shaman
[GetSpellInfo(57994)] = 5, -- wind shear
[GetSpellInfo(2484)] = 10.3, -- earthbind totem (elemental)
[GetSpellInfo(8177)] = 15, -- grounding totem seems like default is 15
["Lava Burst"] = 6,
["Hex"] = 45,
-- Druid
[GetSpellInfo(22812)] = 60, -- barkskin
}
ZAF.Cooldowns.Shared_Cooldowns = {
["Shield Bash"] = {GetSpellInfo(6552)},
["Pummel"] = {GetSpellInfo(72)},
["PvP Trinket"] = { GetSpellInfo(59752)},
["Every Man For Himself"] = {"PvP Trinket", nil, "Interface\\Icons\\INV_Jewelry_TrinketPVP_02" },
}
local resetCooldowns = {
["Preparation"] = {
["Vanish"] = true,
["Shadowstep"] = true,
["Kick"] = true,
["Sprint"] = true,
},
["Cold Snap"] = {
["Deep Freeze"] = true,
["Ice Block"] = true,
["Frost Nova"] = true,
["Ice Barrier"] = true,
},
["Readiness"] = {
["Scatter Shot"] = true,
["Deterrence"] = true,
["Silencing"] = true,
}, -- readiness 23989
}
function GetCooldownByGUID(guid)
local cooldown = not CooldownModule.GUID[guid] and 0 or not CooldownModule.GUID[guid][spell] and 0 or CooldownModule.GUID[guid][spell]
return cooldown
end
local exceptions = { -- spell icon table
["Penance"] = select(3,GetSpellInfo(53007)),
}
local guidDB = ZAF.NameGUIDs
function CooldownModule:COMBAT_LOG_EVENT_UNFILTERED(event,...)
local _ , subType, sourceGUID, sourceName = ...
if subType == "SPELL_CAST_SUCCESS" then
local spellID = select(9,...)
local spell,_,icon = GetSpellInfo(spellID)
--local sourceGUID = select(3,...)
--local sourceName = select(4,...)
if ZAF.spell_cooldown[spell] then
local start = GetTime()
local currentTime = start
local iconTexture = exceptions[spell] or icon
if not self.GUID[sourceGUID] then
self.GUID[sourceGUID] = {}
end
if not CooldownByGUID[sourceGUID] then
CooldownByGUID[sourceGUID] = {}
end
if not CooldownByGUID[sourceGUID][spell] then
CooldownByGUID[sourceGUID][spell] = ZAF.spell_cooldown[spell]
end
if self.GUID[sourceGUID][spell]
and currentTime <= self.GUID[sourceGUID][spell].finish then -- Cooldown did not expire yet and this GUID used it; it's shorter
local differenceInOldNew = self.GUID[sourceGUID][spell].finish - currentTime
CooldownByGUID[sourceGUID][spell] = CooldownByGUID[sourceGUID][spell] - differenceInOldNew
end
local finish = start + CooldownByGUID[sourceGUID][spell] --ZAF.spell_cooldown[spell]
local shared_cd_spell = self.Shared_Cooldowns[spell]
self.GUID[sourceGUID][spell] = {
start = start,
finish = finish,
icon = icon,
}
if shared_cd_spell then
local finish = start + ZAF.spell_cooldown[spell]
local icon = shared_cd_spell[3]
self.GUID[sourceGUID][shared_cd_spell[1]] = {
start = start,
finish = finish,
icon = icon,
}
self:Callbacks(sourceGUID, shared_cd_spell[1], start, finish, icon)
end
self:Callbacks(sourceGUID, spell, start, finish, icon)
end
end
if sourceName and sourceGUID then
guidDB[sourceName] = sourceGUID -- update guid in data base for improved nameplate functionality
end
end
function CooldownModule:UNIT_SPELLCAST_SUCCEEDED(event,...)
local unit, spell = ...
if exceptions[spell] and ZAF.spell_cooldown[spell] then -- bugged icon, change it
local sourceGUID = UnitGUID(unit)
if not self.GUID[sourceGUID] then
self.GUID[sourceGUID] = {}
end
local start = GetTime()
local finish = GetTime()+ ZAF.spell_cooldown[spell]
local icon = exceptions[spell]
ZAF.Cooldowns.GUID[sourceGUID][spell] = {
start =start,
finish = finish,
icon = icon,
}
self:Callbacks(sourceGUID, spell, start, finish, icon)
end
if resetCooldowns[spell] then
local sourceGUID = UnitGUID(unit)
if ZAF.Cooldowns.GUID[sourceGUID] then
for cd,_ in pairs(ZAF.Cooldowns.GUID[sourceGUID]) do
if resetCooldowns[spell][cd] then
ZAF.Cooldowns.GUID[sourceGUID][cd] = nil
self:Callbacks(sourceGUID, cd, GetTime(), GetTime(), nil)
end
end
end
end
end
CooldownModule.Registered = {}
function CooldownModule:Callbacks(sourceGUID, spell, start, finish, icon)
for frame, val in pairs(self.Registered) do
frame:Callback(sourceGUID, spell, start, finish, icon)
end
end
function CooldownModule:Register(frame,val)
self.Registered[frame] = true
end
function CooldownModule:PLAYER_LEAVING_WORLD()
wipe(self.GUID) -- reset GUIDs
wipe(ZAF.NameGUIDs)
end
function CooldownModule:CHAT_MSG_SYSTEM(event,arg1)
if arg1:match("Replay") then
wipe(self.GUID) -- reset GUIDs
wipe(ZAF.NameGUIDs)
end
end
local function eventHandler(self, event,...)
self[event](self,event,...)
end
local function DeleteExpiredCooldowns(self, elapsed)
local GUID_cooldowns = self.GUID
for guid, GUID_table in pairs(GUID_cooldowns) do
for spell, spell_table in pairs(GUID_table) do
if GetTime() >= spell_table.finish then
self.GUID[guid][spell] = nil
end
end
end
end
function ZAF:GetUnitCooldowns(unit)
local unitID = UnitGUID(unit)
local cds = {}
local hasCooldown
if self.Cooldowns.GUID[unitID] then
for spell, spellTable in pairs(self.Cooldowns.GUID[unitID]) do
if spell then
hasCooldown = true
cds[spell]= spellTable
end
end
end
if hasCooldown then return cds end
end
function ZAF:GetUnitSpellCD(unit,arg)
local unitID = UnitGUID(unit)
if self.Cooldowns.GUID[unitID] then
for spell, spellTable in pairs(self.Cooldowns.GUID[unitID]) do
if spell == arg then
return spellTable
end
end
end
end
function ZAF:Init_Cooldowns()
ZAF.Cooldowns:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
ZAF.Cooldowns:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
ZAF.Cooldowns:RegisterEvent("PLAYER_LEAVING_WORLD")
ZAF.Cooldowns:RegisterEvent("CHAT_MSG_SYSTEM")
ZAF.Cooldowns:SetScript("OnEvent", eventHandler)
ZAF.Cooldowns:SetScript("OnUpdate", DeleteExpiredCooldowns)
end
function CooldownModule:Disable()
ZAF.Cooldowns:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
ZAF.Cooldowns:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED")
ZAF.Cooldowns:SetScript("OnUpdate", nil)
end
function CooldownModule:Enable()
ZAF.Cooldowns:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
ZAF.Cooldowns:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
ZAF.Cooldowns:SetScript("OnUpdate", DeleteExpiredCooldowns)
end
ZAF:Init_Cooldowns()