-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoster.lua
More file actions
89 lines (82 loc) · 2.02 KB
/
Copy pathRoster.lua
File metadata and controls
89 lines (82 loc) · 2.02 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
local ADDON_NAME, ns = ...
local Roster = {}
ns.Roster = Roster
local function stripRealm(name)
if not name then
return nil
end
return (name:match("^([^%-]+)") or name)
end
-- Returns an array of { name, class, classFile, role } for everyone in the
-- current group (raid or party), including the player. Empty list when solo.
function Roster:Members()
local out = {}
local seen = {}
local function add(unit)
if not UnitExists(unit) then
return
end
local name = UnitName(unit)
if not name or seen[name] then
return
end
seen[name] = true
local _, classFile = UnitClass(unit)
local role
if UnitGroupRolesAssigned then
local r = UnitGroupRolesAssigned(unit)
if r and r ~= "NONE" then
role = r
end
end
table.insert(out, {
name = name,
classFile = classFile,
role = role,
})
end
if IsInRaid() then
for i = 1, GetNumGroupMembers() do
add("raid" .. i)
end
else
add("player")
for i = 1, 4 do
add("party" .. i)
end
end
table.sort(out, function(a, b)
return (a.name or "") < (b.name or "")
end)
return out
end
-- Is this (possibly realm-suffixed) name currently in your group/raid? When
-- solo, only the player counts. Used to keep saved calls inert unless their
-- assigned caster is actually present, so they can't be used to whisper
-- arbitrary players later.
function Roster:InGroup(name)
if not name then
return false
end
local short = stripRealm(name)
for _, m in ipairs(self:Members()) do
if m.name == name or stripRealm(m.name) == short then
return true
end
end
return false
end
-- Best-effort class lookup for a (possibly realm-suffixed) name currently in
-- the group. Returns the class file token or nil.
function Roster:ClassOf(name)
if not name then
return nil
end
local short = stripRealm(name)
for _, m in ipairs(self:Members()) do
if m.name == name or stripRealm(m.name) == short then
return m.classFile
end
end
return nil
end