/
roster.lua
135 lines (106 loc) · 2.4 KB
/
roster.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
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
-- Rosters ;<
local fiend = _G.Fiend
local UnitExists = UnitExists
local UnitInRaid = UnitInRaid
local UnitGUID = UnitGUID
local playerGUID
-- owner guid -> pet guid
local revPets = {}
-- pet guid -> Owner guid
local pets = {}
-- unit -> guid
local units = {}
-- guid -> unit
local guids = {}
local Clean = function(base, num)
local unit, guid
for i = 1, num do
unit = base .. i
guid = guids[unit]
if guid then
if revPets[guid] then
pets[revPets[guid]] = nil
revPets[guid] = nil
end
guids[guid] = nil
units[unit] = nil
end
end
end
local UpdateRoster = function(base, num)
local unit, guid
for i = 1, num do
unit = base .. i
if UnitExists(unit) then
guid = UnitGUID(unit)
if guid == playerGUID then
unit = "player"
end
units[unit] = guid
guids[guid] = unit
fiend:UNIT_PET(unit)
elseif units[unit] then
guids[units[unit]] = nil
units[unit] = nil
fiend:UNIT_PET(unit)
end
end
end
function fiend:RAID_ROSTER_UPDATE()
if not UnitInRaid("player") then
return Clean("raid", 40)
end
UpdateRoster("raid", 40)
end
function fiend:PARTY_MEMBERS_CHANGED(...)
if not UnitExists("party1") then
return Clean("party", 4)
end
UpdateRoster("party", 4)
end
function fiend:PLAYER_ENTERING_WORLD()
playerGUID = playerGUID or UnitGUID("player")
units.player = playerGUID
guids[playerGUID] = "player"
self:UNIT_PET("player")
self:RAID_ROSTER_UPDATE()
self:PARTY_MEMBERS_CHANGED()
end
function fiend:UNIT_PET(unit)
local guid = UnitGUID(unit)
local pet = unit .. "pet"
if UnitExists(pet) then
local pguid = UnitGUID(pet)
pets[pguid] = guid
revPets[guid] = pguid
units[pet] = pguid
guids[pguid] = pet
elseif revPets[guid] then
pets[revPets[guid]] = nil
revPets[guid] = nil
-- Does this still exist here?
if units[pet] then
guids[units[pet]] = nil
units[pet] = nil
end
end
end
fiend:RegisterEvent("RAID_ROSTER_UPDATE")
fiend:RegisterEvent("PARTY_MEMBERS_CHANGED")
fiend:RegisterEvent("PLAYER_ENTERING_WORLD")
fiend:RegisterEvent("UNIT_PET")
fiend:RegisterEvent("ZONE_CHANGED_NEW_AREA")
fiend.ZONE_CHANGED_NEW_AREA = fiend.PARTY_MEMBERS_CHANGED
function fiend:IsPet(guid)
return pets[guid]
end
function fiend:GetUnit(guid)
return pets[guid] and guids[pets[guid]] or guids[guid]
end
function fiend:AddPet(guid, parent)
pets[guid] = parent
revPets[parent] = guid
end
function fiend:IterateUnitRoster()
return next, units, nil
end