-
Notifications
You must be signed in to change notification settings - Fork 0
/
debuff.lua
86 lines (76 loc) · 2.4 KB
/
debuff.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
local addon, dark_addon = ...
local UnitDebuff = dark_addon.environment.unit_debuff
local debuff = { }
function debuff:exists()
local debuff, count, duration, expires, caster = UnitDebuff(self.unitID, self.spell, 'any')
if debuff and (caster == 'player' or caster == 'pet') then
return true
end
return false
end
function debuff:down()
return not self.exists
end
function debuff:up()
return self.exists
end
function debuff:any()
local debuff, count, duration, expires, caster = UnitDebuff(self.unitID, self.spell, 'any')
if debuff then
return true
end
return false
end
function debuff:count()
local debuff, count, duration, expires, caster = UnitDebuff(self.unitID, self.spell, 'any')
if debuff and (caster == 'player' or caster == 'pet') then
return count
end
return 0
end
function debuff:remains()
local debuff, count, duration, expires, caster = UnitDebuff(self.unitID, self.spell, 'any')
if debuff and (caster == 'player' or caster == 'pet') then
return expires - GetTime()
end
return 0
end
function debuff:duration()
local debuff, count, duration, expires, caster = UnitDebuff(self.unitID, self.spell, 'any')
if debuff and (caster == 'player' or caster == 'pet') then
return duration
end
return 0
end
function dark_addon.environment.conditions.debuff(unit)
return setmetatable({
unitID = unit.unitID
}, {
__index = function(t, k)
if type(t.spell) == 'table' then
t.spell = dark_addon.environment.selectrank(t.spell)
end
local result = debuff[k](t)
dark_addon.console.debug(4, 'debuff', 'teal', t.unitID .. '.debuff(' .. tostring(t.spell) .. ').' .. k .. ' = ' .. dark_addon.format(result))
return result
end,
__call = function(t, k)
t.spell = k
if type(t.spell) == 'table' then
t.spell = dark_addon.environment.selectrank(t.spell)
end
if tonumber(t.spell) then
t.spell = GetSpellInfo(t.spell)
end
return t
end,
__unm = function(t)
if type(t.spell) == 'table' then
t.spell = dark_addon.environment.selectrank(t.spell)
end
local result = debuff['exists'](t)
dark_addon.console.debug(4, 'debuff', 'teal', t.unitID .. '.debuff(' .. tostring(t.spell) .. ').exists = ' .. dark_addon.format(result))
return debuff['exists'](t)
end
})
end