vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | gGroupCalendar_Invites = |
2 | { |
||
3 | Event = nil, |
||
4 | Status = nil, |
||
5 | Group = nil, |
||
6 | Inviting = false, |
||
7 | ChangedFunc = nil, |
||
8 | ChangedFuncParam = nil, |
||
9 | GroupChanged = false, |
||
10 | NextInviteDelay = 0, |
||
11 | MaxInvitesPerTimeSlice = 1, |
||
12 | InvitationSliceInterval = 0.2, |
||
13 | }; |
||
14 | |||
15 | GroupCalendar_cInviteStatusMessages = |
||
16 | { |
||
17 | NeedSelection = GroupCalendar_cInviteNeedSelectionStatus, |
||
18 | Ready = GroupCalendar_cInviteReadyStatus, |
||
19 | InitialInvites = GroupCalendar_cInviteInitialInvitesStatus, |
||
20 | AwaitingAcceptance = GroupCalendar_cInviteAwaitingAcceptanceStatus, |
||
21 | ConvertingToRaid = GroupCalendar_cInviteConvertingToRaidStatus, |
||
22 | Inviting = GroupCalendar_cInviteInvitingStatus, |
||
23 | Complete = GroupCalendar_cInviteCompleteStatus, |
||
24 | ReadyToRefill = GroupCalendar_cInviteReadyToRefillStatus, |
||
25 | -- The "no more available" message is kind of useless, so for now |
||
26 | -- I'm just showing it as completed instead until I figure out a |
||
27 | -- better use for that state |
||
28 | NoMoreAvailable = GroupCalendar_cInviteNoMoreAvailableStatus, |
||
29 | -- NoMoreAvailable = GroupCalendar_cInviteCompleteStatus, |
||
30 | RaidFull = GroupCalendar_cRaidFull, |
||
31 | }; |
||
32 | |||
33 | function CalendarGroupInvites_BeginEvent(pDatabase, pEvent) |
||
34 | -- Just return if it's still the same event |
||
35 | |||
36 | if pEvent == gGroupCalendar_Invites.Event then |
||
37 | return; |
||
38 | end |
||
39 | |||
40 | gGroupCalendar_Invites.Database = pDatabase; |
||
41 | gGroupCalendar_Invites.Event = pEvent; |
||
42 | gGroupCalendar_Invites.Limits = pEvent.mLimits; |
||
43 | |||
44 | if not gGroupCalendar_Invites.Limits then |
||
45 | gGroupCalendar_Invites.Limits = EventDatabase_GetStandardLimitsByID(pEvent.mType); |
||
46 | end |
||
47 | |||
48 | if gGroupCalendar_Invites.Limits |
||
49 | and not gGroupCalendar_Invites.Limits.mPriorityOrder then |
||
50 | gGroupCalendar_Invites.Limits.mPriorityOrder = gGroupCalendar_PlayerSettings.AutoSelectPriorityOrder; |
||
51 | end |
||
52 | |||
53 | gGroupCalendar_Invites.Group = CalendarAttendanceList_New(); |
||
54 | gGroupCalendar_Invites.Group.NumJoinedMembers = 0; |
||
55 | gGroupCalendar_Invites.Group.NumJoinedOrInvited = 0; |
||
56 | |||
57 | gGroupCalendar_Invites.GroupChanged = true; |
||
58 | gGroupCalendar_Invites.SortBy = "Date"; |
||
59 | |||
60 | CalendarGroupInvites_UpdateGroup(gGroupCalendar_Invites.Group); |
||
61 | |||
62 | -- Determine the status |
||
63 | |||
64 | local vEventMaximumAttendance = CalendarGroupInvites_GetEventMaxAttendance(pEvent); |
||
65 | |||
66 | if gGroupCalendar_Invites.Group.NumJoinedOrInvited >= vEventMaximumAttendance then |
||
67 | CalendarGroupInvites_SetStatus("Complete"); |
||
68 | else |
||
69 | CalendarGroupInvites_SetReadyStatus(); |
||
70 | end |
||
71 | |||
72 | CalendarGroupInvites_NotifyGroupChanged(); |
||
73 | end |
||
74 | |||
75 | function CalendarGroupInvites_EndEvent(pEvent) |
||
76 | if pEvent ~= gGroupCalendar_Invites.Event then |
||
77 | return; |
||
78 | end |
||
79 | |||
80 | CalendarGroupInvites_SetChangedFunc(nil, nil); |
||
81 | |||
82 | gGroupCalendar_Invites.Event = nil; |
||
83 | gGroupCalendar_Invites.Status = nil; |
||
84 | gGroupCalendar_Invites.Group = nil; |
||
85 | end |
||
86 | |||
87 | function CalendarGroupInvites_SetChangedFunc(pChangedFunc, pChangedFuncParam) |
||
88 | gGroupCalendar_Invites.ChangedFunc = pChangedFunc; |
||
89 | gGroupCalendar_Invites.ChangedFuncParam = pChangedFuncParam; |
||
90 | end |
||
91 | |||
92 | function CalendarGroupInvites_EventChanged(pEvent) |
||
93 | if pEvent ~= gGroupCalendar_Invites.Event then |
||
94 | return; |
||
95 | end |
||
96 | |||
97 | CalendarGroupInvites_UpdateGroup(gGroupCalendar_Invites.Group); |
||
98 | CalendarGroupInvites_NotifyGroupChanged(); |
||
99 | end |
||
100 | |||
101 | function CalendarGroupInvites_SetReadyStatus() |
||
102 | if CalendarGroupInvites_HasSelection() then |
||
103 | CalendarGroupInvites_SetStatus("Ready"); |
||
104 | else |
||
105 | CalendarGroupInvites_SetStatus("NeedSelection"); |
||
106 | end |
||
107 | end |
||
108 | |||
109 | function CalendarGroupInvites_SetStatus(pStatus) |
||
110 | gGroupCalendar_Invites.Status = pStatus; |
||
111 | gGroupCalendar_Invites.GroupChanged = true; |
||
112 | end |
||
113 | |||
114 | function CalendarGroupInvites_NotifyGroupChanged() |
||
115 | if gGroupCalendar_Invites.GroupChanged then |
||
116 | if gGroupCalendar_Invites.ChangedFunc then |
||
117 | gGroupCalendar_Invites.ChangedFunc(gGroupCalendar_Invites.ChangedFuncParam); |
||
118 | end |
||
119 | |||
120 | gGroupCalendar_Invites.GroupChanged = false; |
||
121 | end |
||
122 | end |
||
123 | |||
124 | function CalendarGroupInvites_GetUpdateDelay() |
||
125 | end |
||
126 | |||
127 | function CalendarGroupInvites_NeedsUpdateTimer() |
||
128 | return gGroupCalendar_Invites.Inviting; |
||
129 | end |
||
130 | |||
131 | function CalendarGroupInvites_Update(pElapsed) |
||
132 | if not gGroupCalendar_Invites.Inviting then |
||
133 | return; |
||
134 | end |
||
135 | |||
136 | gGroupCalendar_Invites.NextInviteDelay = gGroupCalendar_Invites.NextInviteDelay - pElapsed; |
||
137 | |||
138 | if gGroupCalendar_Invites.NextInviteDelay <= 0 then |
||
139 | CalendarGroupInvites_InviteNow(); |
||
140 | gGroupCalendar_Invites.NextInviteDelay = gGroupCalendar_Invites.InvitationSliceInterval; |
||
141 | end |
||
142 | end |
||
143 | |||
144 | function CalendarGroupInvites_PartyMembersChanged() |
||
145 | if not gGroupCalendar_Invites.Event then |
||
146 | return; |
||
147 | end |
||
148 | |||
149 | CalendarGroupInvites_UpdateGroup(gGroupCalendar_Invites.Group); |
||
150 | |||
151 | CalendarGroupInvites_NotifyGroupChanged(); |
||
152 | end |
||
153 | |||
154 | function CalendarGroupInvites_PartyLootMethodChanged() |
||
155 | gGroupCalendar_Invites.PartyFormed = true; |
||
156 | end |
||
157 | |||
158 | function CalendarGroupInvites_SystemMessage(pMessage) |
||
159 | -- See if someone declined an invitation |
||
160 | |||
161 | local vStartIndex, vEndIndex, vName = string.find(pMessage, GroupCalendar_cInviteDeclinedSysMsg); |
||
162 | |||
163 | if vStartIndex then |
||
164 | CalendarGroupInvites_PlayerDeclinedInvitation(vName); |
||
165 | return; |
||
166 | end |
||
167 | |||
168 | -- See if they are already in a group |
||
169 | |||
170 | vStartIndex, vEndIndex, vName = string.find(pMessage, GroupCalendar_cAlreadyGroupedSysMsg); |
||
171 | |||
172 | if vStartIndex then |
||
173 | CalendarGroupInvites_PlayerAlreadyGrouped(vName); |
||
174 | return; |
||
175 | end |
||
176 | |||
177 | -- See if they're not online |
||
178 | |||
179 | vStartIndex, vEndIndex, vName = string.find(pMessage, GroupCalendar_cNoSuchPlayerSysMsg); |
||
180 | |||
181 | if vStartIndex then |
||
182 | CalendarGroupInvites_NoSuchPlayer(vName); |
||
183 | return; |
||
184 | end |
||
185 | end |
||
186 | |||
187 | function CalendarGroupInvites_GuildRosterChanged() |
||
188 | if gGroupCalendar_Invites.Group then |
||
189 | CalendarGroupInvites_UpdateGroup(gGroupCalendar_Invites.Group); |
||
190 | end |
||
191 | end |
||
192 | |||
193 | function CalendarGroupInvites_UpdateGroup(pGroup) |
||
194 | -- Add the attendance info |
||
195 | |||
196 | CalendarGroupInvites_MergeEventAttendance(pGroup, gGroupCalendar_Invites.Event, true); |
||
197 | |||
198 | -- First mark all the joined members as "Left" and |
||
199 | -- count the invited members. Also check their offline |
||
200 | -- status using the guild roster |
||
201 | |||
202 | local vGuildRoster = CalendarNetwork_GetGuildRosterCache(); |
||
203 | |||
204 | for vIndex, vPlayer in pGroup.Items do |
||
205 | if vPlayer.mGroupStatus == "Joined" then |
||
206 | vPlayer.mGroupStatus = "Left"; |
||
207 | end |
||
208 | |||
209 | if vGuildRoster then |
||
210 | local vUpperName = strupper(vPlayer.mName); |
||
211 | local vMemberInfo = vGuildRoster[vUpperName]; |
||
212 | |||
213 | if vMemberInfo then |
||
214 | vPlayer.mOffline = not vMemberInfo.Online; |
||
215 | end |
||
216 | end |
||
217 | end |
||
218 | |||
219 | -- Now scan the group and update everyone who's in |
||
220 | |||
221 | local vNumRaidMembers = GetNumRaidMembers(); |
||
222 | |||
223 | if vNumRaidMembers > 0 then |
||
224 | for vIndex = 1, vNumRaidMembers do |
||
225 | local vName, vRank, vSubgroup, vLevel, vClass, vFileName, vZone, vOnline, vIsDead = GetRaidRosterInfo(vIndex); |
||
226 | |||
227 | if vName then |
||
228 | local vClassCode = EventDatabase_GetClassCodeByClass(vClass); |
||
229 | local vPlayer = pGroup.Items[vName]; |
||
230 | |||
231 | if vPlayer then |
||
232 | vPlayer.mRaidRank = vRank; |
||
233 | vPlayer.mZone = vZone; |
||
234 | vPlayer.mOffline = not vOnline; |
||
235 | vPlayer.mDead = vIsDead; |
||
236 | vPlayer.mGroupStatus = "Joined"; |
||
237 | vPlayer.mSelected = nil; -- Deselect players as they join the group |
||
238 | else |
||
239 | vPlayer = |
||
240 | { |
||
241 | mType = "Player", |
||
242 | mName = vName, |
||
243 | mRaidRank = vRank, |
||
244 | mGroupNumber = vSubGroup, |
||
245 | mLevel = vLevel, |
||
246 | mClassCode = vClassCode, |
||
247 | mZone = vZone, |
||
248 | mOffline = not vOnline, |
||
249 | mDead = vIsDead, |
||
250 | mGroupStatus = "Joined", |
||
251 | }; |
||
252 | |||
253 | pGroup.Items[vName] = vPlayer; |
||
254 | end |
||
255 | end |
||
256 | end |
||
257 | else |
||
258 | for vIndex = 0, MAX_PARTY_MEMBERS do |
||
259 | local vUnitID = nil; |
||
260 | |||
261 | if vIndex == 0 then |
||
262 | vUnitID = "player"; |
||
263 | elseif GetPartyMember(vIndex) then |
||
264 | vUnitID = "party"..vIndex; |
||
265 | else |
||
266 | vUnitID = nil; |
||
267 | end |
||
268 | |||
269 | if vUnitID then |
||
270 | local vName = UnitName(vUnitID); |
||
271 | |||
272 | -- Map the party info to a raid rank |
||
273 | |||
274 | local vRank = 0; |
||
275 | |||
276 | if GetNumPartyMembers() == 0 |
||
277 | or UnitIsPartyLeader(vUnitID) then |
||
278 | vRank = 2; |
||
279 | end |
||
280 | |||
281 | -- |
||
282 | |||
283 | local vClassCode = EventDatabase_GetClassCodeByClass(UnitClass(vUnitID)); |
||
284 | local vPlayer = pGroup.Items[vName]; |
||
285 | |||
286 | if vPlayer then |
||
287 | vPlayer.mRaidRank = vRank; |
||
288 | vPlayer.mOffline = not UnitIsConnected(vUnitID); |
||
289 | vPlayer.mDead = UnitIsDeadOrGhost(vUnitID); |
||
290 | vPlayer.mGroupStatus = "Joined"; |
||
291 | vPlayer.mSelected = nil; -- Deselect players as they join the group |
||
292 | else |
||
293 | vPlayer = |
||
294 | { |
||
295 | mType = "Player", |
||
296 | mName = vName, |
||
297 | mRaidRank = vRank, |
||
298 | mGroupNumber = 1, |
||
299 | mLevel = UnitLevel(vUnitID), |
||
300 | mClassCode = vClassCode, |
||
301 | --mZone = vZone, |
||
302 | mOffline = not UnitIsConnected(vUnitID), |
||
303 | mDead = UnitIsDeadOrGhost(vUnitID), |
||
304 | mGroupStatus = "Joined", |
||
305 | }; |
||
306 | |||
307 | pGroup.Items[vName] = vPlayer; |
||
308 | end |
||
309 | end |
||
310 | end |
||
311 | end |
||
312 | |||
313 | -- |
||
314 | |||
315 | CalendarGroupInvites_SelectionChanged(); |
||
316 | gGroupCalendar_Invites.GroupChanged = true; |
||
317 | end |
||
318 | |||
319 | function CalendarGroupInvites_SetSortMode(pSortBy) |
||
320 | gGroupCalendar_Invites.SortBy = pSortBy; |
||
321 | |||
322 | if gGroupCalendar_Invites.Group then |
||
323 | CalendarGroupInvites_SortGroup(gGroupCalendar_Invites.Group); |
||
324 | CalendarGroupInvites_NotifyGroupChanged(); |
||
325 | end |
||
326 | end |
||
327 | |||
328 | function CalendarGroupInvites_EventChanged(pDatabase, pEvent) |
||
329 | if gGroupCalendar_Invites.Event ~= pEvent |
||
330 | or not gGroupCalendar_Invites.Group then |
||
331 | return; |
||
332 | end |
||
333 | |||
334 | CalendarGroupInvites_UpdateGroup(gGroupCalendar_Invites.Group); |
||
335 | end |
||
336 | |||
337 | function CalendarGroupInvites_GetGroupItemCategory(pItem) |
||
338 | if pItem.mStatus == "Y" |
||
339 | or pItem.mGroupStatus == "Joined" |
||
340 | or pItem.mGroupStatus == "Left" |
||
341 | or pItem.mSelected then |
||
342 | if pItem.mClassCode then |
||
343 | return pItem.mClassCode; |
||
344 | else |
||
345 | return "?"; |
||
346 | end |
||
347 | end |
||
348 | |||
349 | return CalendarAttendanceList_GetRSVPClassCategory(pItem); |
||
350 | end |
||
351 | |||
352 | function CalendarGroupInvites_SortGroup(pGroup) |
||
353 | -- Sort into categories |
||
354 | |||
355 | local vNumAttendees = pGroup.NumAttendees; |
||
356 | CalendarAttendanceList_SortIntoCategories(pGroup, CalendarGroupInvites_GetGroupItemCategory); |
||
357 | pGroup.NumAttendees = vNumAttendees; |
||
358 | |||
359 | -- Sort the categories |
||
360 | |||
361 | table.sort(pGroup.SortedCategories, EventDatabase_CompareClassCodes); |
||
362 | |||
363 | -- Sort the attendance within each category |
||
364 | |||
365 | for vCategory, vClassInfo in pGroup.Categories do |
||
366 | table.sort(vClassInfo.mAttendees, CalendarGroupInvites_GetGroupItemCompare(gGroupCalendar_Invites.SortBy)); |
||
367 | end |
||
368 | |||
369 | gGroupCalendar_Invites.GroupChanged = true; |
||
370 | end |
||
371 | |||
372 | GroupCalendar_cGroupStatusOrder = |
||
373 | { |
||
374 | Joined = 1, |
||
375 | Invited = 2, |
||
376 | Ready = 3, |
||
377 | Grouped = 4, |
||
378 | Standby = 5, |
||
379 | Declined = 6, |
||
380 | Offline = 7, |
||
381 | Left = 8, |
||
382 | }; |
||
383 | |||
384 | GroupCalendar_cGroupStatusMessages = |
||
385 | { |
||
386 | Joined = GroupCalendar_cJoinedGroupStatus, |
||
387 | Invited = GropuCalendar_cInvitedGroupStatus, |
||
388 | Ready = GropuCalendar_cReadyGroupStatus, |
||
389 | Grouped = GroupCalendar_cGroupedGroupStatus, |
||
390 | Standby = GroupCalendar_cStandbyGroupStatus, |
||
391 | Declined = GroupCalendar_cDeclinedGroupStatus, |
||
392 | Offline = GroupCalendar_cOfflineGroupStatus, |
||
393 | Left = GroupCalendar_cLeftGroupStatus, |
||
394 | }; |
||
395 | |||
396 | GroupCalendar_cRSVPStatusToGroupStatus = |
||
397 | { |
||
398 | Y = "Ready", |
||
399 | S = "Standby", |
||
400 | }; |
||
401 | |||
402 | function CalendarGroupInvites_CompareGroupItems(pItem1, pItem2, pSecondaryCompareFunc) |
||
403 | if not pItem1 then |
||
404 | if not pItem2 then |
||
405 | Calendar_ErrorMessage("CalendarGroupInvites_CompareGroupItems: pItem1 is nil"); |
||
406 | else |
||
407 | Calendar_ErrorMessage("CalendarGroupInvites_CompareGroupItems: pItem2 is nil"); |
||
408 | end |
||
409 | |||
410 | return false; |
||
411 | end |
||
412 | |||
413 | if not pItem2 then |
||
414 | Calendar_ErrorMessage("CalendarGroupInvites_CompareGroupItems: pItem2 is nil"); |
||
415 | return true; |
||
416 | end |
||
417 | |||
418 | -- Compare by status first |
||
419 | |||
420 | local vOrder1 = GroupCalendar_cGroupStatusOrder[pItem1.mGroupStatus]; |
||
421 | local vOrder2 = GroupCalendar_cGroupStatusOrder[pItem2.mGroupStatus]; |
||
422 | |||
423 | if not vOrder1 then |
||
424 | Calendar_ErrorMessage("CalendarGroupInvites_CompareGroupItems: pItem1: Unknown status "..pItem1.mGroupStatus); |
||
425 | |||
426 | if not vOrder2 then |
||
427 | Calendar_ErrorMessage("CalendarGroupInvites_CompareGroupItems: pItem2: Unknown status "..pItem2.mGroupStatus); |
||
428 | end |
||
429 | |||
430 | return false; |
||
431 | end |
||
432 | |||
433 | if not vOrder2 then |
||
434 | Calendar_ErrorMessage("CalendarGroupInvites_CompareGroupItems: pItem2: Unknown status "..pItem2.mGroupStatus); |
||
435 | return true; |
||
436 | end |
||
437 | |||
438 | if vOrder1 ~= vOrder2 then |
||
439 | return vOrder1 < vOrder2; |
||
440 | end |
||
441 | |||
442 | -- Use the secondary comparison |
||
443 | |||
444 | return pSecondaryCompareFunc(pItem1, pItem2); |
||
445 | end |
||
446 | |||
447 | function CalendarGroupInvites_CompareGroupItemsByRank(pItem1, pItem2) |
||
448 | return CalendarGroupInvites_CompareGroupItems(pItem1, pItem2, EventDatabase_CompareRSVPsByRankAndDate); |
||
449 | end |
||
450 | |||
451 | function CalendarGroupInvites_CompareGroupItemsByDate(pItem1, pItem2) |
||
452 | return CalendarGroupInvites_CompareGroupItems(pItem1, pItem2, EventDatabase_CompareRSVPsByDate); |
||
453 | end |
||
454 | |||
455 | function CalendarGroupInvites_CompareGroupItemsByName(pItem1, pItem2) |
||
456 | return CalendarGroupInvites_CompareGroupItems(pItem1, pItem2, EventDatabase_CompareRSVPsByName); |
||
457 | end |
||
458 | |||
459 | function CalendarGroupInvites_GetGroupItemCompare(pSortBy) |
||
460 | if pSortBy == "Rank" then |
||
461 | return CalendarGroupInvites_CompareGroupItemsByRank; |
||
462 | elseif pSortBy == "Date" then |
||
463 | return CalendarGroupInvites_CompareGroupItemsByDate; |
||
464 | elseif pSortBy == "Name" then |
||
465 | return CalendarGroupInvites_CompareGroupItemsByName; |
||
466 | else |
||
467 | Calendar_ErrorMessage("GroupCalendar: Unknown sorting method in CalendarGroupInvites_GetGroupItemCompare"); |
||
468 | end |
||
469 | end |
||
470 | |||
471 | function CalendarGroupInvites_ComparePlayerItemsByDate(pPlayer1, pPlayer2) |
||
472 | if not pPlayer1.mDate then |
||
473 | return false; |
||
474 | elseif not pPlayer2.mDate then |
||
475 | return true; |
||
476 | end |
||
477 | |||
478 | if pPlayer1.mDate < pPlayer2.mDate then |
||
479 | return true; |
||
480 | elseif pPlayer1.mDate > pPlayer2.mDate then |
||
481 | return false; |
||
482 | elseif pPlayer1.mTime ~= pPlayer2.mTime then |
||
483 | return pPlayer1.mTime < pPlayer2.mTime; |
||
484 | else |
||
485 | return pPlayer1.mName < pPlayer2.mName; |
||
486 | end |
||
487 | end |
||
488 | |||
489 | function CalendarGroupInvites_GetEventMaxAttendance(pEvent) |
||
490 | if not pEvent.mLimits |
||
491 | or not pEvent.mLimits.mMaxAttendance then |
||
492 | return MAX_RAID_MEMBERS; |
||
493 | end |
||
494 | |||
495 | return pEvent.mLimits.mMaxAttendance; |
||
496 | end |
||
497 | |||
498 | function CalendarGroupInvites_GetNextInvitee(pGroup) |
||
499 | for vCategory, vCategoryInfo in pGroup.Categories do |
||
500 | for vIndex, vPlayer in vCategoryInfo.mAttendees do |
||
501 | if vPlayer.mNeedsInvite then |
||
502 | return vPlayer; |
||
503 | end |
||
504 | end |
||
505 | end |
||
506 | |||
507 | return nil; |
||
508 | end |
||
509 | |||
510 | function CalendarGroupInvites_InviteNow() |
||
511 | if not gGroupCalendar_Invites.Event then |
||
512 | if gGroupCalendar_Settings.DebugInvites then |
||
513 | Calendar_DebugMessage("Skipping invites: no event associated"); |
||
514 | end |
||
515 | |||
516 | gGroupCalendar_Invites.Inviting = false; |
||
517 | return; |
||
518 | end |
||
519 | |||
520 | -- Get the maximum size for the group |
||
521 | |||
522 | local vMaxPartyMembers; |
||
523 | |||
524 | CalendarGroupInvites_SetStatus("Inviting"); |
||
525 | |||
526 | if GetNumRaidMembers() == 0 then |
||
527 | vMaxPartyMembers = MAX_PARTY_MEMBERS + 1; -- +1 because Blizzard doesn't include the player in the MAX_PARTY_MEMBERS count |
||
528 | else |
||
529 | vMaxPartyMembers = MAX_RAID_MEMBERS; |
||
530 | end |
||
531 | |||
532 | -- |
||
533 | |||
534 | if gGroupCalendar_Settings.DebugInvites then |
||
535 | Calendar_DebugMessage("Starting invites: MaxPartyMembers: "..vMaxPartyMembers); |
||
536 | end |
||
537 | |||
538 | -- Count the number of outstanding invitations |
||
539 | |||
540 | local vNumInvitesSent = 0; |
||
541 | |||
542 | for vExcessLooping = 1, 40 do |
||
543 | -- Don't allow too many invitations in one burst in order to prevent |
||
544 | -- Blizzard's spammer filters from kicking us offline |
||
545 | |||
546 | if vNumInvitesSent >= gGroupCalendar_Invites.MaxInvitesPerTimeSlice then |
||
547 | if gGroupCalendar_Settings.DebugInvites then |
||
548 | Calendar_DebugMessage("Maximum invites per time slice reached"); |
||
549 | end |
||
550 | |||
551 | return; |
||
552 | end |
||
553 | |||
554 | if gGroupCalendar_Settings.DebugInvites then |
||
555 | Calendar_DebugMessage("NumJoinedOrInvited: "..gGroupCalendar_Invites.Group.NumJoinedOrInvited); |
||
556 | end |
||
557 | |||
558 | -- Get the next player to invite |
||
559 | |||
560 | local vPlayer = CalendarGroupInvites_GetNextInvitee(gGroupCalendar_Invites.Group); |
||
561 | |||
562 | -- Done if there are no more players to add |
||
563 | |||
564 | if not vPlayer then |
||
565 | CalendarGroupInvites_SetStatus("Complete"); |
||
566 | gGroupCalendar_Invites.Inviting = false; |
||
567 | |||
568 | if gGroupCalendar_Settings.DebugInvites then |
||
569 | Calendar_DebugMessage("No more players to invite"); |
||
570 | end |
||
571 | |||
572 | return; |
||
573 | end |
||
574 | |||
575 | -- See if there's room for more |
||
576 | |||
577 | if gGroupCalendar_Invites.Group.NumJoinedOrInvited >= vMaxPartyMembers then |
||
578 | if GetNumRaidMembers() == 0 then |
||
579 | -- Convert to a raid |
||
580 | |||
581 | if gGroupCalendar_Invites.Group.NumJoinedMembers > 1 |
||
582 | and gGroupCalendar_Invites.PartyFormed then |
||
583 | CalendarGroupInvites_SetStatus("ConvertingToRaid"); |
||
584 | |||
585 | if gGroupCalendar_Settings.DebugInvites then |
||
586 | Calendar_DebugMessage("Converting to raid"); |
||
587 | end |
||
588 | |||
589 | ConvertToRaid(); |
||
590 | |||
591 | -- Wait for at least one player to accept |
||
592 | |||
593 | else |
||
594 | CalendarGroupInvites_SetStatus("AwaitingAcceptance"); |
||
595 | if gGroupCalendar_Settings.DebugInvites then |
||
596 | Calendar_DebugMessage("Waiting for players to accept"); |
||
597 | end |
||
598 | end |
||
599 | |||
600 | -- This state is only reached if the raid is full and the player |
||
601 | -- tries to invite more |
||
602 | |||
603 | else |
||
604 | CalendarGroupInvites_SetStatus("RaidFull"); |
||
605 | gGroupCalendar_Invites.Inviting = false; |
||
606 | end |
||
607 | |||
608 | return; |
||
609 | end |
||
610 | |||
611 | -- Invite the player |
||
612 | |||
613 | if gGroupCalendar_Settings.DebugInvites then |
||
614 | Calendar_DebugMessage("Inviting "..vPlayer.mName); |
||
615 | end |
||
616 | |||
617 | SendChatMessage( |
||
618 | format(GroupCalendar_cInviteWhisperFormat, EventDatabase_GetEventDisplayName(gGroupCalendar_Invites.Event)), |
||
619 | "WHISPER", |
||
620 | nil, |
||
621 | vPlayer.mName); |
||
622 | |||
623 | InviteByName(vPlayer.mName); |
||
624 | |||
625 | vPlayer.mGroupStatus = "Invited"; |
||
626 | vPlayer.mNeedsInvite = nil; |
||
627 | |||
628 | vNumInvitesSent = vNumInvitesSent + 1; |
||
629 | |||
630 | gGroupCalendar_Invites.Group.NumJoinedOrInvited = gGroupCalendar_Invites.Group.NumJoinedOrInvited + 1; |
||
631 | |||
632 | gGroupCalendar_Invites.GroupChanged = true; |
||
633 | end -- for |
||
634 | |||
635 | Calendar_ErrorMessage("GroupCalendar: Internal Error: InviteNow() not terminating properly"); |
||
636 | end |
||
637 | |||
638 | function CalendarAttendanceList_GetRSVPClassCategory(pItem) |
||
639 | local vCategoryID = CalendarAttendanceList_GetRSVPStatusCategory(pItem); |
||
640 | |||
641 | if not vCategoryID then |
||
642 | return nil; |
||
643 | end |
||
644 | |||
645 | if vCategoryID ~= "YES" then |
||
646 | return vCategoryID; |
||
647 | end |
||
648 | |||
649 | if pItem.mClassCode then |
||
650 | return pItem.mClassCode; |
||
651 | end |
||
652 | |||
653 | return "?"; |
||
654 | end |
||
655 | |||
656 | function CalendarGroupInvites_MergeEventAttendance(pGroup, pEvent, pSortByClass) |
||
657 | if not pEvent |
||
658 | or not pEvent.mAttendance then |
||
659 | return; |
||
660 | end |
||
661 | |||
662 | for vAttendeeName, vRSVPString in pEvent.mAttendance do |
||
663 | local vRSVP = EventDatabase_UnpackEventRSVP(nil, vAttendeeName, pEvent.mID, vRSVPString); |
||
664 | local vCategoryID = CalendarAttendanceList_GetRSVPClassCategory(vRSVP); |
||
665 | |||
666 | if vCategoryID |
||
667 | and vCategoryID ~= "NO" then |
||
668 | local vItem = pGroup.Items[vRSVP.mName]; |
||
669 | |||
670 | if not vItem then |
||
671 | vRSVP.mType = "RSVP"; |
||
672 | vRSVP.mGroupStatus = GroupCalendar_cRSVPStatusToGroupStatus[vRSVP.mStatus]; |
||
673 | |||
674 | if vRSVP.mGroupStatus then |
||
675 | pGroup.Items[vRSVP.mName] = vRSVP; |
||
676 | end |
||
677 | else |
||
678 | -- Just update the status and |
||
679 | -- player info fields |
||
680 | |||
681 | vItem.mStatus = vRSVP.mStatus; |
||
682 | vItem.mComment = vRSVP.mComment; |
||
683 | vItem.mGuild = vRSVP.mGuild; |
||
684 | vItem.mGuildRank = vRSVP.mGuildRank; |
||
685 | |||
686 | if vItem.mGroupStatus == "Standby" |
||
687 | or vItem.mGroupStatus == "Ready" then |
||
688 | vItem.mGroupStatus = GroupCalendar_cRSVPStatusToGroupStatus[vRSVP.mStatus]; |
||
689 | end |
||
690 | end |
||
691 | end |
||
692 | end |
||
693 | end |
||
694 | |||
695 | function CalendarGroupInvites_InviteSelectedPlayers() |
||
696 | -- Reset the SentInvite flag |
||
697 | |||
698 | for vCategory, vCategoryInfo in gGroupCalendar_Invites.Group.Categories do |
||
699 | for vIndex, vPlayer in vCategoryInfo.mAttendees do |
||
700 | if vPlayer.mSelected then |
||
701 | vPlayer.mNeedsInvite = true; |
||
702 | end |
||
703 | end |
||
704 | end |
||
705 | |||
706 | -- Arm the trigger for when the party is actually |
||
707 | -- formed (needed to make ConvertToRaid() work properly) |
||
708 | |||
709 | if GetNumRaidMembers() ~= 0 |
||
710 | or GetNumPartyMembers() ~= 0 then |
||
711 | gGroupCalendar_Invites.PartyFormed = true; |
||
712 | else |
||
713 | gGroupCalendar_Invites.PartyFormed = false; |
||
714 | end |
||
715 | |||
716 | -- Start inviting |
||
717 | |||
718 | gGroupCalendar_Invites.Inviting = true; |
||
719 | gGroupCalendar_Invites.NextInviteDelay = 0; |
||
720 | GroupCalendar_StartUpdateTimer(); |
||
721 | |||
722 | CalendarGroupInvites_InviteNow(); |
||
723 | CalendarGroupInvites_NotifyGroupChanged(); |
||
724 | end |
||
725 | |||
726 | function CalendarGroupInvites_HasSelection() |
||
727 | for vIndex, vPlayer in gGroupCalendar_Invites.Group.Items do |
||
728 | if vPlayer.mSelected then |
||
729 | return true; |
||
730 | end |
||
731 | end |
||
732 | |||
733 | return false; |
||
734 | end |
||
735 | |||
736 | function CalendarGroupInvites_ClearSelection() |
||
737 | for vIndex, vPlayer in gGroupCalendar_Invites.Group.Items do |
||
738 | vPlayer.mSelected = nil; |
||
739 | end |
||
740 | |||
741 | CalendarGroupInvites_SelectionChanged(); |
||
742 | end |
||
743 | |||
744 | function CalendarGroupInvites_SetItemSelected(pItem, pSelected) |
||
745 | if not pSelected then |
||
746 | pSelected = nil; |
||
747 | end |
||
748 | |||
749 | if pItem.mSelected == pSelected then |
||
750 | return; |
||
751 | end |
||
752 | |||
753 | pItem.mSelected = pSelected; |
||
754 | |||
755 | CalendarGroupInvites_SelectionChanged(); |
||
756 | CalendarGroupInvites_NotifyGroupChanged(); |
||
757 | end |
||
758 | |||
759 | function CalendarGroupInvites_SelectionChanged() |
||
760 | local vNumSelected = 0; |
||
761 | local vNumJoined = 0; |
||
762 | local vNumAttendees = 0; |
||
763 | local vNumJoinedOrInvited = 0; |
||
764 | |||
765 | for vIndex, vPlayer in gGroupCalendar_Invites.Group.Items do |
||
766 | if vPlayer.mGroupStatus == "Joined" then |
||
767 | vNumJoined = vNumJoined + 1; |
||
768 | vNumJoinedOrInvited = vNumJoinedOrInvited + 1; |
||
769 | vNumAttendees = vNumAttendees + 1; |
||
770 | else |
||
771 | if vPlayer.mSelected then |
||
772 | vNumSelected = vNumSelected + 1; |
||
773 | vNumAttendees = vNumAttendees + 1; |
||
774 | end |
||
775 | |||
776 | if vPlayer.mGroupStatus == "Invited" then |
||
777 | vNumJoinedOrInvited = vNumJoinedOrInvited + 1; |
||
778 | end |
||
779 | end |
||
780 | end |
||
781 | |||
782 | gGroupCalendar_Invites.Group.NumAttendees = vNumAttendees; |
||
783 | gGroupCalendar_Invites.Group.NumJoinedMembers = vNumJoined; |
||
784 | gGroupCalendar_Invites.Group.NumJoinedOrInvited = vNumJoinedOrInvited; |
||
785 | |||
786 | gGroupCalendar_Invites.NumSelected = vNumSelected; |
||
787 | |||
788 | CalendarGroupInvites_SortGroup(gGroupCalendar_Invites.Group); |
||
789 | CalendarGroupInvites_SetReadyStatus(); |
||
790 | end |
||
791 | |||
792 | function CalendarGroupInvites_AutoSelectPlayers() |
||
793 | CalendarClassLimits_Open(gGroupCalendar_Invites.Limits, GroupCalendar_cAutoSelectWindowTitle, true, CalendarGroupInvites_AutoSelectFromLimits); |
||
794 | end |
||
795 | |||
796 | function CalendarGroupInvites_AutoSelectFromLimits(pLimits) |
||
797 | gGroupCalendar_Invites.Limits = pLimits; |
||
798 | gGroupCalendar_PlayerSettings.AutoSelectPriorityOrder = pLimits.mPriorityOrder; |
||
799 | |||
800 | CalendarGroupInvites_ClearSelection(); |
||
801 | |||
802 | -- |
||
803 | |||
804 | local vAvailableSlots = EventAvailableSlots_InitializeFromLimits(pLimits); |
||
805 | |||
806 | -- Count existing players and accumulate the rest as prospective members |
||
807 | |||
808 | local vProspects = {}; |
||
809 | |||
810 | for vCategory, vCategoryInfo in gGroupCalendar_Invites.Group.Categories do |
||
811 | for vIndex, vPlayer in vCategoryInfo.mAttendees do |
||
812 | if vPlayer.mGroupStatus == "Joined" |
||
813 | or vPlayer.mGroupStatus == "Invited" then |
||
814 | CalendarEvent_PlayerClassAdded(vAvailableSlots, vPlayer.mClassCode) |
||
815 | else |
||
816 | table.insert(vProspects, vPlayer); |
||
817 | end |
||
818 | end |
||
819 | end |
||
820 | |||
821 | -- Sort the prospects by the selected priority |
||
822 | |||
823 | table.sort(vProspects, CalendarGroupInvites_GetGroupItemCompare(pLimits.mPriorityOrder)); |
||
824 | |||
825 | -- Add them |
||
826 | |||
827 | for vIndex, vPlayer in vProspects do |
||
828 | if EventAvailableSlots_AcceptPlayer(vAvailableSlots, vPlayer.mClassCode) then |
||
829 | vPlayer.mSelected = true; |
||
830 | end |
||
831 | end |
||
832 | |||
833 | CalendarGroupInvites_SelectionChanged(); |
||
834 | CalendarGroupInvites_NotifyGroupChanged(); |
||
835 | end |
||
836 | |||
837 | function CalendarGroupInvites_PlayerDeclinedInvitation(pName) |
||
838 | local vPlayer = CalendarAttendanceList_FindItem(gGroupCalendar_Invites.Group, "mName", pName); |
||
839 | |||
840 | if not vPlayer |
||
841 | or not vPlayer.mGroupStatus == "Invited" then |
||
842 | return; |
||
843 | end |
||
844 | |||
845 | vPlayer.mGroupStatus = "Declined"; |
||
846 | |||
847 | gGroupCalendar_Invites.GroupChanged = true; |
||
848 | CalendarGroupInvites_NotifyGroupChanged(); |
||
849 | end |
||
850 | |||
851 | function CalendarGroupInvites_PlayerAlreadyGrouped(pName) |
||
852 | local vPlayer = CalendarAttendanceList_FindItem(gGroupCalendar_Invites.Group, "mName", pName); |
||
853 | |||
854 | if not vPlayer then |
||
855 | return; |
||
856 | end |
||
857 | |||
858 | if vPlayer.mGroupStatus == "Invited" then |
||
859 | SendChatMessage(GroupCalendar_cAlreadyGroupedWhisper, "WHISPER", nil, vPlayer.mName); |
||
860 | end |
||
861 | |||
862 | vPlayer.mGroupStatus = "Grouped"; |
||
863 | |||
864 | gGroupCalendar_Invites.GroupChanged = true; |
||
865 | CalendarGroupInvites_NotifyGroupChanged(); |
||
866 | end |
||
867 | |||
868 | function CalendarGroupInvites_NoSuchPlayer(pName) |
||
869 | local vPlayer = CalendarAttendanceList_FindItem(gGroupCalendar_Invites.Group, "mName", pName); |
||
870 | |||
871 | if not vPlayer then |
||
872 | return; |
||
873 | end |
||
874 | |||
875 | vPlayer.mGroupStatus = "Offline"; |
||
876 | |||
877 | gGroupCalendar_Invites.GroupChanged = true; |
||
878 | CalendarGroupInvites_NotifyGroupChanged(); |
||
879 | end |
||
880 |