-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAuraFilter.lua
More file actions
148 lines (117 loc) · 3.4 KB
/
AuraFilter.lua
File metadata and controls
148 lines (117 loc) · 3.4 KB
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
-- **** imports ****
-- **** private ****
local MatchesFilter = function(self, filter, unit, index, auraName, auraId, auraCaster)
-- force check by id
if (filter.forceId) then
if (auraId ~= filter.forceId) then
return false;
end
-- check by name
elseif (filter.name) then
if (auraName ~= filter.name) then
return false;
end
-- check by id
elseif (filter.id) then
if (auraId ~= filter.id) then
return false;
end
end
-- check type
if (filter.type) then
-- UnitAura returns 0-40 auras, internally we mark buffs as 1-40 and debuffs as 41-80
if (filter.type == "DEBUFF" and (index <= 40 or index > 80)) then
return false;
elseif (filter.type == "BUFF" and (index <= 0 or index > 40)) then
return false;
end
end
-- check notoriety
if (filter.notoriety) then
if (filter.notoriety == "FRIEND" and not UnitIsFriend("player", unit)) then
return false;
elseif (filter.notoriety == "ENEMY" and not UnitIsEnemy("player", unit)) then
return false;
end
end
-- check caster
if (filter.caster and (not auraCaster or not UnitIsUnit(filter.caster, auraCaster))) then
return false;
end
return true;
end
local GetPriority = function( self, unit, index, auraName, auraId, auraCaster )
local filters = self.filters;
if ( #filters <= 0 ) then
return 1;
end
for _, filter in ipairs( filters ) do
for _, v in ipairs( filter ) do
--[[
local caster = v.caster;
if ( not caster or ( auraCaster and UnitIsUnit( caster, auraCaster ) ) ) then
if ( v.forceId ) then
if ( v.forceId == auraId ) then
return v.priority or 1;
end
elseif ( v.name and v.name == auraName ) then
--print(v.name .. " => " .. index);
return v.priority or 1;
end
end
]]
if (MatchesFilter(self, v, unit, index, auraName, auraId, auraCaster)) then
return v.priority or 1;
end
end
end
return nil;
end
local NextAura;
NextAura = function( self, unit, index, name, rank, texture, count, auraType, duration, expiration, caster, stealable, consolidate, auraId )
if ( not name ) then
return nil;
end
local priority = GetPriority( self, unit, index, name, auraId, caster );
if ( priority ) then
return index, name, rank, texture, count, auraType, duration, expiration, caster, stealable, consolidate, auraId, priority;
end
return NextAura( self, unit, self.auraIterator( unit, index ) );
end
-- **** public ****
local AddFilter = function( self, filter )
assert( type( filter ) == "table", "Parameter 'filter' must be a table" );
for _, v in ipairs( filter ) do
local id = v.id;
if ( id and not v.name ) then
v.name = GetSpellInfo( id );
end
end
tinsert( self.filters, filter );
end
local RemoveFilter = function( self, filter )
assert( type( filter ) == "table", "Parameter 'filter' must be a table" );
local filters = self.filters;
for index, value in ipairs( filters ) do
if ( value == filter ) then
tremove( filters, index );
end
end
end
-- **** call, ctor ****
local call = function( self, unit )
return self.iterator, unit, 0;
end
local ctor = function( self, baseCtor, iterator )
self.auraIterator = iterator();
self.filters = { };
self.iterator = function( unit, index )
return NextAura( self, unit, self.auraIterator( unit, index ) );
end
end
-- **** main ****
kCore.AuraFilter, _ = kCore.CreateClass( ctor, {
AddFilter = AddFilter,
RemoveFilter = RemoveFilter,
}, nil );
kCore.AuraFilter.metatable.__call = call;