-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAuras.lua
413 lines (400 loc) · 12.4 KB
/
Auras.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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
local _G = getglobal
local tinsert = table.insert
local tremove = table.remove
local UN = UnitName
local strform = string.format
local flr = floor
local strgfind = string.gfind
local strfind = string.find
local GT = GetTime
local tnbr = tonumber
local UnitIsDeadOrGhost = UnitIsDeadOrGhost
local UnitAffectingCombat = UnitAffectingCombat
local UnitInRaid = UnitInRaid
local UnitBuff = UnitBuff
local UnitDebuff = UnitDebuff
local UnitMana = UnitMana
local strsub = strsub
local strlower = strlower
local GetComboPoints = GetComboPoints
local GetSpellCooldown = GetSpellCooldown
local GetInventoryItemCooldown = GetInventoryItemCooldown
local GetContainerItemCooldown = GetContainerItemCooldown
local GetContainerItemLink = GetContainerItemLink
local GetInventoryItemLink = GetInventoryItemLink
local GetContainerNumSlots = GetContainerNumSlots
local GetSpellName = GetSpellName
local UnitIsFriend = UnitIsFriend
local UpdateTime, LastUpdate = 0.05, 0
local cdset = {}
function MPOWA:OnUpdate(elapsed)
LastUpdate = LastUpdate + elapsed
if LastUpdate >= UpdateTime then
local p1, p2
for cat, val in pairs(self.NeedUpdate) do
if val then
local path = self.SAVE[cat]
if path["enemytarget"] and not UN("target") and not UnitIsFriend("player", "target") then return end
p1, p2 = self:TernaryReturn(cat, "inparty", self:InParty()), self:TernaryReturn(cat, "inraid", UnitInRaid("player"))
if not self.active[cat] and self:TernaryReturn(cat, "alive", self:Reverse(UnitIsDeadOrGhost("player")))
and self:TernaryReturn(cat, "mounted", self.mounted) and self:TernaryReturn(cat, "incombat", UnitAffectingCombat("player"))
and (((p1 or p2) and ((path["inparty"]==0 or path["inparty"]==true) and (path["inraid"]==0 or path["inraid"]==true))) or (p1 and p2))
and self:TernaryReturn(cat, "inbattleground", self.bg) and self:TernaryReturn(cat, "inraidinstance", self.instance) then
self.frames[cat][4]:Hide()
if path["cooldown"] then
local duration = self:GetCooldown(path["buffname"]) or 0
if path["cdclockanimout"] and duration<=path["animduration"]+0.4 and duration>=path["animduration"] and (not cdset[cat] or cdset[cat]+0.5<GT()) then
cdset[cat] = GT()
self.frames[cat][5]:SetCooldown(GT(), path["animduration"])
end
if path["timer"] then
if duration > 0 then
self.frames[cat][3]:SetText(self:FormatDuration(duration, path))
if path["inverse"] then
self:FHide(cat)
self.frames[cat][3]:Hide()
else
if path["secsleft"] then
if duration<=path["secsleftdur"] then
self:FShow(cat)
self.frames[cat][3]:Show()
else
self:FHide(cat)
self.frames[cat][3]:Hide()
end
else
self:FShow(cat)
self.frames[cat][3]:Show()
end
end
else
if path["inverse"] then
self:FShow(cat)
else
self:FHide(cat)
end
self.frames[cat][3]:Hide()
end
else
if path["inverse"] then
if duration > 0 then
self:FHide(cat)
else
self:FShow(cat)
end
else
if path["secsleft"] then
if duration<=path["secsleftdur"] then
self:FShow(cat)
else
self:FHide(cat)
end
else
if duration > 0 then
self:FShow(cat)
else
self:FHide(cat)
end
end
end
end
else
self:FShow(cat)
end
else
if path["inverse"] or path["cooldown"] then
self:FHide(cat)
end
end
end
end
for cat, val in pairs(self.active) do
if val then
local path = self.SAVE[cat]
local text, count, timeLeft = "", 0, 0, 0
if val[3] then
_, _, text, count, _, _, timeLeft = UnitDebuff(val[1], val[2]);
else
_, _, text, count, _, timeLeft = UnitBuff(val[1], val[2]);
end
self:SetTexture(cat, text)
if self:IsStacks(count or 0, cat, "stacks") then
if (count or 0)>1 and not path["hidestacks"] then
self.frames[cat][4]:SetText(count)
self.frames[cat][4]:Show()
else
self.frames[cat][4]:Hide()
end
-- Duration
timeLeft = timeLeft or 0
if path["cdclockanimout"] and timeLeft<=path["animduration"]+0.4 and timeLeft>=path["animduration"] and (not cdset[cat] or cdset[cat]+0.5<GT()) then
cdset[cat] = GT()
self.frames[cat][5]:SetCooldown(GT(), path["animduration"])
end
if path["timer"] then
if timeLeft > 0 then
self.frames[cat][3]:SetText(self:FormatDuration(timeLeft, path))
else
self.frames[cat][3]:Hide()
end
end
self:Flash(elapsed, cat, timeLeft)
if (path["inverse"] and path["buffname"] ~= "unitpower") then
self:FHide(cat)
else
if path["secsleft"] then
if timeLeft<=path["secsleftdur"] then
self:FShow(cat)
else
self:FHide(cat)
end
else
self:FShow(cat)
end
end
else
self:FHide(cat)
end
else
if not self.NeedUpdate[cat] then
self:FHide(cat)
end
end
end
LastUpdate = 0
end
end
function MPOWA:SetTexture(key, texture)
local p = self.SAVE[key]
if texture and p["texture"] == "Interface\\AddOns\\zzzModifiedPowerAuras\\images\\dummy.tga" then
p["texture"] = texture
self.frames[key][2]:SetTexture(texture)
end
end
function MPOWA:FormatDuration(duration, path)
if path["minutes"] and duration >60 then
return ceil(duration/60).."m"
elseif path["hundredth"] then
return strform("%.2f", duration)
end
return flr(duration)
end
function MPOWA:GetCooldown(buff)
-- Get Spellcooldown
local start, duration, enabled = GetSpellCooldown(self:GetSpellSlot(buff), "spell")
-- Get Inventory Cooldown
if start == 0 and duration == 0 then
for i=1, 22 do
start, duration, enable = GetInventoryItemCooldown("player", i)
local _,_,name = strfind(GetInventoryItemLink("player",i) or "","^.*%[(.*)%].*$")
if (name) then
if strfind(strlower(buff), strlower(name)) then
if duration>2 then
return ((start or 0)+(duration or 0))-GT()
else
return 0
end
elseif i == 22 and start == 0 and duration == 0 then
-- Get Container Item Cooldown
for p=0, 4 do
for u=1, GetContainerNumSlots(p) do
start, duration, enable = GetContainerItemCooldown(p,u)
_,_,name=strfind(GetContainerItemLink(p,u) or "","^.*%[(.*)%].*$")
if (not name) then break end
if strfind(strlower(buff), strlower(name)) then
if duration>2 then
return ((start or 0)+(duration or 0))-GT()
else
return 0
end
elseif p == 4 and u == GetContainerNumSlots(p) then
if duration>2 then
return ((start or 0)+(duration or 0))-GT()
else
return 0
end
else
return 0
end
end
end
end
end
end
else
if duration>2 then
return ((start or 0)+(duration or 0))-GT()
else
return 0
end
end
end
function MPOWA:GetSpellSlot(buff)
if not buff then
return 0
end
local i = 1
while true do
local name, rank = GetSpellName(i, "spell")
if (not name) or strfind(strlower(name), strlower(buff)) then
return i
end
if i > 1000 then
return 0 -- Lets give up at this point
end
i = i + 1
end
return 0
end
local BuffExist = {}
function MPOWA:Iterate(unit)
BuffExist = {}
if unit=="player" then
self:IsMounted()
--self:InParty()
self:InBG()
self:InInstance()
end
for cat, val in pairs(self.SAVE) do
if (val["buffname"] == "unitpower") then
local unit = arg1
if (unit == "target") then
self:Push("unitpower", unit, 45, false)
elseif (string.find(unit,"raid")) then
local st = string.sub(unit, 5)
if st and tonumber(st) then
self:Push("unitpower", unit, (tonumber(st) or 0)+45, false)
end
elseif (string.find(unit,"party")) then
local st = string.sub(unit, 6)
if st and tonumber(st) then
self:Push("unitpower", unit, (tonumber(st) or 0)+45, false)
end
end
end
end
for i=1, 40 do
local buff, debuff, castbyme
buff,_,_,_,_,_,castbyme = UnitBuff(unit, i)
self:Push(buff, unit, i, false, castbyme)
if i<17 then
debuff,_,_,_,_,_,_,castbyme = UnitDebuff(unit, i)
self:Push(debuff, unit, i, true,castbyme)
end
if not buff and not debuff then break end
end
for cat, val in pairs(self.active) do
if val then
if not BuffExist[cat] then
local p = self.SAVE[cat]
if ((p["friendlytarget"] or p["enemytarget"]) and unit=="target") or (not p["raidgroupmember"] and not p["friendlytarget"] and not p["enemytarget"] and unit=="player") or p["raidgroupmember"] then
self.active[cat] = false
self.frames[cat][3]:Hide()
if not p["inverse"] and not p["cooldown"] then
self.frames[cat][1]:SetAlpha(p["alpha"])
self:FHide(cat)
end
end
end
end
end
end
function MPOWA:Push(aura, unit, i, isdebuff, castbyme)
if self.auras[aura] then
for cat, val in pairs(self.auras[aura]) do
local path = self.SAVE[val]
local bypass = self.active[val]
local tex = ""
if path["secondspecifier"] then
if path["isdebuff"] then
_,_,tex = UnitDebuff(unit, i)
else
_,_,tex = UnitBuff(unit, i)
end
tex = strlower(strsub(tex, strfind(tex, "Icons")+6))
end
BuffExist[val] = true
if (not path["castbyme"] or (path["castbyme"] and castbyme)) and path["isdebuff"]==isdebuff and ((path["secondspecifier"] and (strlower(path["secondspecifiertext"])==tex)) or not path["secondspecifier"]) then
local p1, p2 = self:TernaryReturn(val, "inparty", self:InParty()), self:TernaryReturn(val, "inraid", UnitInRaid("player"))
if self:TernaryReturn(val, "alive", self:Reverse(UnitIsDeadOrGhost("player"))) and self:TernaryReturn(val, "mounted", self.mounted)
and self:TernaryReturn(val, "incombat", UnitAffectingCombat("player"))
and (((p1 or p2) and ((path["inparty"]==0 or path["inparty"]==true) and (path["inraid"]==0 or path["inraid"]==true))) or (p1 and p2))
and self:TernaryReturn(val, "inbattleground", self.bg) and self:TernaryReturn(val, "inraidinstance", self.instance)
and not path["cooldown"] and self:IsStacks(GetComboPoints("player", "target"), val, "cpstacks") then
if path["enemytarget"] and unit == "target" then
self.active[val] = {unit, i, isdebuff}
elseif path["friendlytarget"] and unit == "target" then
self.active[val] = {unit, i, isdebuff}
elseif path["raidgroupmember"] then -- have to check those vars
self.active[val] = {unit, i, isdebuff}
elseif not path["enemytarget"] and not path["friendlytarget"] and not path["raidgroupmember"] and unit == "player" then
self.active[val] = {unit, i, isdebuff}
end
if self.active[val] and not bypass then
if tnbr(self.frames[val][1]:GetAlpha())<=0.1 then
self.frames[val][1]:SetAlpha(tnbr(path["alpha"]))
end
self:FShow(val)
if path["timer"] then
self.frames[val][3]:Show()
end
end
end
end
end
end
end
function MPOWA:IsStacks(count, id, kind)
if self.SAVE[id][kind] ~= "" then
local con = strsub(self.SAVE[id][kind], 1, 2)
local amount = tnbr(strsub(self.SAVE[id][kind], 3))
if not con then
con = strsub(self.SAVE[id][kind], 1, 1)
amount = tnbr(strsub(self.SAVE[id][kind], 2))
end
if self.SAVE[id]["buffname"] == "unitpower" then
count = UnitMana(self.SAVE[id]["unit"] or "player")
if self.SAVE[id]["inverse"] then
if (con == ">=") then
con = "<"
elseif (con == "<=") then
con = ">"
elseif con == ">" then
con = "<="
elseif (con == "<") then
con = ">="
elseif (con == "=") then
con = "!"
elseif (con == "!") then
con = "="
end
end
end
if amount ~= nil and con ~= nil then
if con == ">=" and count >= amount then
return true
elseif con == "<=" and count <= amount then
return true
elseif con == "<" and count < amount then
return true
elseif con == ">" and count > amount then
return true
elseif con == "=" and count == amount then
return true
elseif con == "!" and count ~= amount then
return true
end
end
con = strfind(self.SAVE[id][kind], "-")
if con then
local amount1 = tnbr(strsub(self.SAVE[id][kind], 1, con-1))
local amount2 = tnbr(strsub(self.SAVE[id][kind], con+1))
if con and amount1 and amount2 and ((count >= amount1 and count <= amount2) or (count >= amount2 and count <= amount1)) then
return true
end
else
return false
end
end
return false
end