-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFocusMagic.lua
More file actions
207 lines (180 loc) · 5.46 KB
/
FocusMagic.lua
File metadata and controls
207 lines (180 loc) · 5.46 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
local PREFIX = "|cff33ff99"..(...).."|r:"
local LOCALE = GetLocale()
local CI = LibStub("LibClassicInspector")
local GetNumGroupMembers, GetRaidRosterInfo, IsInGroup, IsInRaid, SendChatMessage, SlashCmdList, UnitClass, UnitIsUnit, UnitName = GetNumGroupMembers, GetRaidRosterInfo, IsInGroup, IsInRaid, SendChatMessage, SlashCmdList, UnitClass, UnitIsUnit, UnitName
local print, tinsert, tremove, tsort = print, table.insert, table.remove, table.sort
local ASSUME_FOCUS_MAGIC_IF_WAITING_TO_INSPECT = true
local PREFER_SMALL_CIRCLES = true
local COLOR_HIGHLIGHT = "|cff1eff0c"
local group = {}
function group:Build()
self.isInGroup = IsInGroup()
self.isInRaid = IsInRaid()
if self.isInGroup then
self.size = GetNumGroupMembers()
else
self.size = 1
end
self.roster = {}
for i = 1, self.size do
self:AddRoster(i)
end
end
function group:AddRoster(index)
local unitId = "party"..index
local party = 1
if not self.isInGroup then
unitId = "player"
elseif self.isInRaid then
unitId = "raid"..index
party = select(3, GetRaidRosterInfo(index))
end
local data = {
["name"] = UnitName(unitId),
["party"] = party,
["isPlayer"] = UnitIsUnit(unitId, "player"),
["isMage"] = false,
["needToInspect"] = false,
["hasFocusMagic"] = false,
}
if select(2, UnitClass(unitId)) == "MAGE" then
data.isMage = true
local _, _, _, _, rank = CI:GetTalentInfo(unitId, 1, 29)
if not rank then
data.needToInspect = true
data.hasFocusMagic = ASSUME_FOCUS_MAGIC_IF_WAITING_TO_INSPECT
elseif rank == 1 then
data.hasFocusMagic = true
end
end
self.roster[index] = data
end
function group:GetMagesToInspect()
local names = {}
for i = 1, self.size do
if self.roster[i].needToInspect then
tinsert(names, self.roster[i].name)
end
end
tsort(names)
return names
end
function group:GetMagesWithFocusMagic()
local names = {}
for i = 1, self.size do
if self.roster[i].hasFocusMagic then
tinsert(names, self.roster[i].name)
end
end
tsort(names)
return names
end
function group:GetMagesWithoutFocusMagic()
local names = {}
for i = 1, self.size do
if self.roster[i].isMage and not self.roster[i].hasFocusMagic then
tinsert(names, self.roster[i].name)
end
end
tsort(names)
return names
end
function group:ShouldUsePartyChat()
local party = nil
for i = 1, self.size do
if self.roster[i].hasFocusMagic or self.roster[i].isPlayer then
if party and party ~= self.roster[i].party then
return false
end
party = self.roster[i].party
end
end
return true
end
local function join(sep, list)
if #list < 1 then
return ""
end
local result = list[1]
for i = 2, #list do
result = result..sep..list[i]
end
return result
end
local function announceFocusMagicAssignments(shouldAnnounce, shouldForce)
group:Build()
local goodMages = group:GetMagesWithFocusMagic()
if #goodMages < 2 then
print(PREFIX.." There are fewer than 2 mages with focus magic.")
return
end
if not shouldForce then
local magesToInspect = group:GetMagesToInspect()
if #magesToInspect > 0 then
shouldAnnounce = false
print(PREFIX.." Need to inspect "..join("/", magesToInspect).." to verify they spec into focus magic.")
print("Type "..COLOR_HIGHLIGHT.."/fm force|r to assume yes and announce anyway.")
end
end
--Generate assignment message, e.g.:
--FM: Amage<=>Bmage
--FM: Amage<=>Bmage (Xmage does not have FM)
--FM alphabetically: Amage=>Bmage=>Cmage=>Amage
--FM alphabetically: Amage<=>Bmage, Cmage<=>Dmage
--FM alphabetically: Amage<=>Bmage, Cmage=>Dmage=>Emage=>Cmage
--FM alphabetically: Amage<=>Bmage, Cmage<=>Dmage, Emage=>Fmage=>Gmage=>Emage (Xmage/Ymage do not have FM)
local message = "FM"
if #goodMages > 2 then
message = message.." alphabetically"
end
while PREFER_SMALL_CIRCLES and #goodMages > 3 do
message = message..", "..goodMages[1].."<=>"..goodMages[2]
tremove(goodMages, 1)
tremove(goodMages, 1)
end
if #goodMages < 3 then
message = message..", "..goodMages[1].."<=>"..goodMages[2]
else
message = message..", "
for i = 1, #goodMages do
message = message..goodMages[i].."=>"
end
message = message..goodMages[1]
end
local badMages = group:GetMagesWithoutFocusMagic()
if #badMages == 1 then
message = message.." ("..badMages[1].." does not have FM)"
elseif #badMages > 1 then
message = message.." ("..join("/", badMages).." do not have FM)"
end
message = message:gsub(",", ":", 1)
if shouldAnnounce then
local channel = "RAID"
if group:ShouldUsePartyChat() then
channel = "PARTY"
end
SendChatMessage(message, channel)
else
print(message)
end
end
local function printHelp()
print(PREFIX.." Usage:")
print(" "..COLOR_HIGHLIGHT.."/fm|r - announce focus magic assignments")
print(" "..COLOR_HIGHLIGHT.."/fm force|r - same as above, but announce even if the addon hasn't verified that all mages spec into FM")
print(" "..COLOR_HIGHLIGHT.."/fm quiet|r - generate focus assignments but don't announce them")
end
local function slashCommand(args)
args = string.lower(args or "")
if args == "" then
announceFocusMagicAssignments(true, false)
elseif args == "f" or args == "force" then
announceFocusMagicAssignments(true, true)
elseif args == "q" or args == "quiet" then
announceFocusMagicAssignments(false, false)
else
printHelp()
end
end
SLASH_FM1 = "/fm"
SlashCmdList["FM"] = slashCommand