forked from beerman212/BuffTracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TrackedMobs.lua
81 lines (63 loc) · 1.44 KB
/
TrackedMobs.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
-- TrackedMobs Implementation
TrackedMobs = {}
function TrackedMobs.new()
local self = {}
setmetatable(self, {__index = TrackedMobs})
return self
end
function TrackedMobs:add_mob(mob)
mob = mob or TrackedMob.new()
self[mob.id] = mob
end
function TrackedMobs:remove_mob(id)
self[mob.id] = nil
end
function TrackedMobs:exists(id)
return self[mob.id] and true or false
end
-- TrackedMob Implementation
TrackedMob = {}
function TrackedMob.new(mob)
local self = mob or {id = -1}
setmetatable(self, {__index = TrackedMob})
return self
end
function TrackedMob.add_buff(buff)
if not self.buffs then
self.buffs = TrackedBuffs.new()
end
buff = buff or TrackedBuff.new()
self.buffs[buff.id] = buff
end
function TrackedMob.remove_buff(id)
if self.buffs then
self.buffs[id] = nil
end
end
function TrackedMob.clear_buffs()
self.buffs:clear_buffs()
end
-- TrackedBuffs Implementation
TrackedBuffs = {}
function TrackedBuffs.new()
local self = {}
setmetatable(self, {__index = TrackedBuffs})
return self
end
function TrackedBuffs:add_buff(buff)
buff = buff or TrackedBuff.new()
self[buff.id] = buff
end
function TrackedBuffs:remove_buff(buffID)
self[buffID] = nil
end
function TrackedBuffs:clear_buffs()
self:clear()
end
function TrackedBuffs:count()
local count = 0
for _, buff in pairs(self) do
count = count + 1
end
return count
end