-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueueManager.lua
305 lines (293 loc) · 7.1 KB
/
QueueManager.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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
--[[
* Copyright (c) 2011-2012 by Adam Hellberg.
*
* This file is part of Command.
*
* Command is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Command is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Command. If not, see <http://www.gnu.org/licenses/>.
--]]
-- Upvalues
local type = type
local pairs = pairs
local select = select
local tostring = tostring
-- API Upvalues
local SetCVar = SetCVar
local JoinLFG = JoinLFG
local LeaveLFG = LeaveLFG
local GetLFGMode = GetLFGMode
local HideUIPanel = HideUIPanel
local SetLFGRoles = SetLFGRoles
local SetLFGDungeon = SetLFGDungeon
local AcceptProposal = AcceptProposal
local GetLFGDungeonInfo = GetLFGDungeonInfo
local GetRandomDungeonBestChoice = GetRandomDungeonBestChoice
local C = Command
--- Table containing all QueueManager methods.
-- This is referenced "QM" in QueueManager.lua.
-- @name Command.QueueManager
-- @class table
-- @field QueuedByCommand True if player has been queued by a command, false otherwise.
-- @field Current The current dungeon for which the group is queued.
-- @field Running True if announce is running, false otherwise.
-- @field Time Total time since Announce was called.
-- @field LastMode Last not-nil value returned by GetLFGMode.
--
C.QueueManager = {
QueuedByCommand = false,
Current = nil,
Running = false,
Time = 0,
LastMode = nil,
Announced = false
}
local L = C.LocaleManager
local QM = C.QueueManager
--- Contains information about various dungeon types.
-- Each entry has an Alias table and an Id field.
-- The Alias table contains names that this dungeon may be referenced by.
-- The Id field is either a number or a function that gives the index for that dungeon type.
-- @name Command.QueueManager.Types
-- @class table
-- @field ClassicRandom Random Classic Dungeon
-- @field TBCRandom Random Burning Crusade Dungeon
-- @field TBCHeroic Random Heroic Burning Crusade Dungeon
-- @field LKRandom Random Wrath of the Lich king Dungeon
-- @field LKHeroic Random Heroic Wrath of the Lich King Dungeon
-- @field CataclysmRandom Random Cataclysm Dungeon
-- @field CataclysmHeroic Random Heroic Cataclysm Dungeon
-- @field HourOfTwilight Random Hour of Twilight Dungeon
-- @field CrownChemical Crown Chemical Co. Holiday Boss (Shadowfang Keep)
-- @field Horseman The Headless Horseman Hallow's Eve Dungeon
-- @field BestChoice Let the server decide what dungeon is best
--
QM.Types = {
ClassicRandom = {
Alias = {
"classic",
"vanilla",
"classicrandom",
"random"
},
Id = 258
},
TBCRandom = {
Alias = {
"tbc",
"burningcrusade",
"tbcrandom",
"burningcrusaderandom",
"theburningcrusade",
"randomtbc"
},
Id = 259
},
TBCHeroic = {
Alias = {
"tbchc",
"tbcheroic",
"tbcrandomhc",
"tbcrandomheroic",
"randomtbchc",
"randomtbcheroic"
},
Id = 260
},
LKRandom = {
Alias = {
"lk",
"wotlk",
"lkrandom",
"wotlkrandom",
"lichking",
"wrathofthelichking"
},
Id = 261
},
LKHeroic = {
Alias = {
"lkhc",
"wotlkhc",
"hclk",
"hcwotlk",
"lkhcrandom",
"hclkrandom",
"wotlkhcrandom",
"hcwotlkrandom"
},
Id = 262
},
CataclysmRandom = {
Alias = {
"cata",
"catanormal",
"cataclysm"
},
Id = 300
},
CataclysmHeroic = {
Alias = {
"catahc",
"cataclysmhc",
"cataheroic",
"cataclysmheroic",
"catahcrandom",
"cataheroicrandom",
"cataclysmhcrandom",
"cataclysmheroicrandom"
},
Id = 301
},
HourOfTwilight = {
Alias = {
"twilight",
"hour",
"houroftwilight",
"hourtwilight",
"twilighthour",
"twilite",
"twi",
"th",
"hot",
"ht"
},
Id = 434
},
CrownChemical = {
Alias = {
"thecrownchemicalco",
"crownchemical",
"valentine",
"valentineboss",
"valentinedungeon",
"love",
"loveboss",
"lovedungeon",
"loveisintheair",
"<3"
},
Id = 288
},
Horseman = {
Alias = {
"horseman",
"headless",
"headlesshorseman",
"hallowseve",
"hallows",
"hallow",
"halloweve",
"halloween"
},
Id = 285
},
BestChoice = {
Alias = {
"best",
"bestchoice",
"auto",
"choice"
},
Id = function() return GetRandomDungeonBestChoice() end
}
}
--- Gets the numeric index of a dungoen for use with SetLFGDungeon.
-- @param alias Name/Alias of the dungeon.
-- @return Index of the dungeon if dungeon was found, false otherwise.
--
function QM:GetIndex(alias)
for _,v in pairs(self.Types) do
for _,d in pairs(v.Alias) do
if alias:lower() == d then
if type(v.Id) == "function" then
return v.Id()
end
return v.Id
end
end
end
return false
end
--- Queue for the dungeon with supplied index.
-- @param index Index of dungeon to queue for.
-- @return String stating that rolecheck has started.
--
function QM:Queue(index)
local _, t, h, d = GetLFGRoles()
if not t and not h and not d then
d = true
end
SetLFGRoles(true, t, h, d)
SetLFGDungeon(index)
JoinLFG()
self.QueuedByCommand = true
local name = (select(1, GetLFGDungeonInfo(index)))
HideUIPanel(LFDParentFrame)
SetCVar("Sound_EnableSFX", 1)
self.Current = name
self.Announced = false
return "QM_QUEUE_START", {tostring(QM.Current)}
end
--- Cancel the queueing/rolechecking.
-- @return String stating that queue has been cancelled.
--
function QM:Cancel()
self.QueuedByCommand = false
self.Announced = false
LeaveLFG()
return "QM_CANCEL"
end
--- Causes player to accept a pending LFG invite.
-- @return String stating that the invite was accepted.
--
function QM:Accept()
self.QueuedByCommand = false
self.Announced = false
AcceptProposal()
return "QM_ACCEPT"
end
--- Announce the current status of LFG to group.
-- @param _ Not used
-- @param elapsed Time elapsed since last time OnUpdate fired.
--
function QM:Announce(_, elapsed)
self.Time = self.Time + elapsed
if self.Time >= 0.25 then
local mode = (select(1, GetLFGMode()))
if mode ~= nil then self.LastMode = mode end
if mode == "queued" and not self.Announced then
C.ChatManager:SendMessage(L("QM_ANNOUNCE_QUEUEING"):format(QM.Current), "SMART")
self.Announced = true
elseif not mode then
if self.LastMode ~= "rolecheck" then
C.ChatManager:SendMessage(L("QM_ANNOUNCE_LFGCANCEL"), "SMART")
else
C.ChatManager:SendMessage(L("QM_ANNOUNCE_ROLECANCEL"), "SMART")
end
self.QueuedByCommand = false
self.Announced = false
end
self.Time = 0
self.Frame:SetScript("OnUpdate", nil)
self.Running = false
end
end
--- Trigger method to announce status.
-- This is because the status of LFG is not available straight after LFG_UPDATE event is fired.
--
function QM:AnnounceStatus()
if self.Running then return end
self.Running = true
if not self.Frame then self.Frame = CreateFrame("Frame") end
self.Frame:SetScript("OnUpdate", function(_, elapsed) QM:Announce(_, elapsed) end)
end