-
Notifications
You must be signed in to change notification settings - Fork 0
/
buff.lua
94 lines (83 loc) · 2.52 KB
/
buff.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
local addon, dark_addon = ...
local UnitBuff = dark_addon.environment.unit_buff
local buff = { }
function buff:exists()
local buff, count, duration, expires, caster = UnitBuff(self.unitID, self.spell, 'any')
if buff and (caster == 'player' or caster == 'pet') then
return true
end
return false
end
function buff:down()
return not self.exists
end
function buff:up()
return self.exists
end
function buff:any()
local buff, count, duration, expires, caster = UnitBuff(self.unitID, self.spell, 'any')
if buff then
return true
end
return false
end
function buff:count()
local buff, count, duration, expires, caster = UnitBuff(self.unitID, self.spell, 'any')
if buff and (caster == 'player' or caster == 'pet') then
return count
end
return 0
end
function buff:remains()
local buff, count, duration, expires, caster = UnitBuff(self.unitID, self.spell, 'any')
if buff and (caster == 'player' or caster == 'pet') then
return expires - GetTime()
end
return 0
end
function buff:duration()
local buff, count, duration, expires, caster = UnitBuff(self.unitID, self.spell, 'any')
if buff and (caster == 'player' or caster == 'pet') then
return duration
end
return 0
end
function buff:stealable()
local buff, count, duration, expires, caster, stealable = UnitBuff(self.unitID, self.spell, 'any')
if stealable then
return true
end
return false
end
function dark_addon.environment.conditions.buff(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 = buff[k](t)
dark_addon.console.debug(4, 'buff', 'green', t.unitID .. '.buff(' .. 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 = buff['exists'](t)
dark_addon.console.debug(4, 'buff', 'green', t.unitID .. '.buff(' .. tostring(t.spell) .. ').exists = ' .. dark_addon.format(result))
return result
end
})
end