-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemies.lua
81 lines (67 loc) · 1.7 KB
/
enemies.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
local addon, dark_addon = ...
local enemies = {}
local enemies_cache = {}
local function enemies_count(func)
local count = 0
for _, unit in pairs(enemies_cache) do
if func(unit) then
count = count + 1
end
end
return count
end
function enemies:count(func)
return enemies_count
end
local function enemies_match(func)
for _, unit in pairs(enemies_cache) do
if func(unit) then
return unit
end
end
return false
end
function enemies:match(func)
return enemies_match
end
local function enemies_around(distance)
return enemies_count(function (unit)
return unit.alive
and (
(distance and unit.distance <= distance)
or not distance
)
end)
end
function enemies:around(distance)
return enemies_around
end
function dark_addon.environment.conditions.enemies()
return setmetatable({ }, {
__index = function(t, k)
return enemies[k](t)
end
})
end
local function add_enemy(unitID)
if not enemies_cache[unitID] and not UnitIsFriend("player", unitID) then
enemies_cache[unitID] = dark_addon.environment.conditions.unit(unitID)
end
end
local function remove_enemy(unitID)
if enemies_cache[unitID] then
enemies_cache[unitID] = nil
end
end
dark_addon.event.register("NAME_PLATE_UNIT_ADDED", function(...)
return add_enemy(...)
end)
dark_addon.event.register("FORBIDDEN_NAME_PLATE_UNIT_ADDED", function(...)
return add_enemy(...)
end)
dark_addon.event.register("NAME_PLATE_UNIT_REMOVED", function(...)
return remove_enemy(...)
end)
dark_addon.event.register("FORBIDDEN_NAME_PLATE_UNIT_REMOVED", function(...)
return remove_enemy(...)
end)