-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGC5ScheduleLib.lua
More file actions
executable file
·3762 lines (2984 loc) · 108 KB
/
GC5ScheduleLib.lua
File metadata and controls
executable file
·3762 lines (2984 loc) · 108 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
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
----------------------------------------
-- Group Calendar 5 Copyright (c) 2018 John Stephen
-- This software is licensed under the MIT license.
-- See the included LICENSE.txt file for more information.
----------------------------------------
local _
-- Invite Statuses
GroupCalendar.CALENDAR_EVENTCOLOR_MODERATOR = {r = 0.54, g = 0.75, b = 1.0}
GroupCalendar.CALENDAR_INVITESTATUS_COLORS =
{
[CALENDAR_INVITESTATUS_CONFIRMED] = GREEN_FONT_COLOR,
[CALENDAR_INVITESTATUS_ACCEPTED] = {r = 0.6, g = 1, b = 1},
[CALENDAR_INVITESTATUS_TENTATIVE] = ORANGE_FONT_COLOR,
[CALENDAR_INVITESTATUS_DECLINED] = GRAY_FONT_COLOR,
[CALENDAR_INVITESTATUS_OUT] = RED_FONT_COLOR,
[CALENDAR_INVITESTATUS_STANDBY] = YELLOW_FONT_COLOR,
[CALENDAR_INVITESTATUS_INVITED] = NORMAL_FONT_COLOR,
[CALENDAR_INVITESTATUS_SIGNEDUP] = {r = 0.6, g = 1, b = 1},
[CALENDAR_INVITESTATUS_NOT_SIGNEDUP] = NORMAL_FONT_COLOR,
}
GroupCalendar.CALENDAR_INVITESTATUS_COLOR_CODES = {}
for vKey, vColor in pairs(GroupCalendar.CALENDAR_INVITESTATUS_COLORS) do
GroupCalendar.CALENDAR_INVITESTATUS_COLOR_CODES[vKey] = string.format("|cff%02x%02x%02x", vColor.r * 255 + 0.5, vColor.g * 255 + 0.5, vColor.b * 255 + 0.5)
end
GroupCalendar.CALENDAR_INVITESTATUS_NAMES =
{
[CALENDAR_INVITESTATUS_CONFIRMED] = CALENDAR_STATUS_CONFIRMED,
[CALENDAR_INVITESTATUS_ACCEPTED] = CALENDAR_STATUS_ACCEPTED,
[CALENDAR_INVITESTATUS_TENTATIVE] = CALENDAR_STATUS_TENTATIVE,
[CALENDAR_INVITESTATUS_DECLINED] = CALENDAR_STATUS_DECLINED,
[CALENDAR_INVITESTATUS_OUT] = CALENDAR_STATUS_OUT,
[CALENDAR_INVITESTATUS_STANDBY] = CALENDAR_STATUS_STANDBY,
[CALENDAR_INVITESTATUS_INVITED] = CALENDAR_STATUS_INVITED,
[CALENDAR_INVITESTATUS_SIGNEDUP] = CALENDAR_STATUS_SIGNEDUP,
[CALENDAR_INVITESTATUS_NOT_SIGNEDUP] = nil,
}
GroupCalendar.CALENDAR_CALENDARTYPE_COLORS =
{
-- ["PLAYER"] = ,
-- ["GUILD_ANNOUNCEMENT"] = ,
-- ["GUILD_EVENT"] = ,
["SYSTEM"] = {r=1.0, g=1.0, b=0.6},
["HOLIDAY"] = HIGHLIGHT_FONT_COLOR,
["RAID_LOCKOUT"] = NORMAL_FONT_COLOR,
["RAID_RESET"] = HIGHLIGHT_FONT_COLOR,
}
GroupCalendar.EVENT_MAX_TITLE_LENGTH = 31
GroupCalendar.EVENT_MAX_DESCRIPTION_LENGTH = 255
----------------------------------------
GroupCalendar._Calendar = {}
----------------------------------------
GroupCalendar._Calendar.cMaxHistory = 14
function GroupCalendar._Calendar:Construct(pOwnersName, pCalendarID, pCalendarData, pReadOnly)
self.OwnersName = pOwnersName
self.CalendarID = pCalendarID
self.CalendarData = pCalendarData
self.ReadOnly = pReadOnly
self.Schedules = {}
-- Add the method table to all of the events in the calendar
local vMetaTable = (pReadOnly and GroupCalendar._CachedEventMetaTable) or GroupCalendar._APIEventMetaTable
if self.CalendarData then
for vDate, vEvents in pairs(self.CalendarData) do
for _, vEvent in ipairs(vEvents) do
setmetatable(vEvent, vMetaTable)
end
end
end
--
if not self.ReadOnly then
GroupCalendar.EventLib:RegisterEvent("CALENDAR_UPDATE_EVENT_LIST", self.CalendarUpdateEventList, self)
GroupCalendar.EventLib:RegisterEvent("CVAR_UPDATE", self.CVarUpdate, self)
GroupCalendar.EventLib:RegisterEvent("CALENDAR_UPDATE_PENDING_INVITES", self.Synchronize, self)
end
-- Install event monitoring to aid in debugging
--[[
if pCalendarID == "PLAYER" then
GroupCalendar.EventLib:RegisterEvent("CALENDAR_UPDATE_EVENT_LIST", self.DebugEvents, self)
GroupCalendar.EventLib:RegisterEvent("CALENDAR_OPEN_EVENT", self.DebugEvents, self)
GroupCalendar.EventLib:RegisterEvent("CALENDAR_CLOSE_EVENT", self.DebugEvents, self)
GroupCalendar.EventLib:RegisterEvent("CALENDAR_UPDATE_EVENT", self.DebugEvents, self)
GroupCalendar.EventLib:RegisterEvent("CALENDAR_UPDATE_INVITE_LIST", self.DebugEvents, self)
GroupCalendar.EventLib:RegisterCustomEvent("GC5_EVENT_CHANGED", self.DebugEvents, self)
GroupCalendar.EventLib:RegisterCustomEvent("GC5_CALENDAR_CHANGED", self.DebugEvents, self)
GroupCalendar.EventLib:RegisterEvent("CALENDAR_ACTION_PENDING", self.DebugEvents, self)
GroupCalendar.EventLib:RegisterEvent("CALENDAR_NEW_EVENT", self.DebugEvents, self)
end
]]
end
function GroupCalendar._Calendar:DebugEvents(pEventID, ...)
if GroupCalendar.Debug.events then
local vParam = select(1, ...) or ""
GroupCalendar:DebugMessage("Calendar:DebugEvents: %s%s: %s", GREEN_FONT_COLOR_CODE, pEventID, tostring(vParam))
end
end
function GroupCalendar._Calendar:CalendarUpdateEventList()
GroupCalendar.BlizzardCalendarReady = true
self:FlushCaches()
end
function GroupCalendar._Calendar:GetSelectedEvent()
if GroupCalendar.WoWCalendar.OpenedEvent then
return GroupCalendar.WoWCalendar.OpenedEvent
end
if not self.CalendarData then
return
end
local vDate = GroupCalendar.DateLib:ConvertMDYToDate(
GroupCalendar.WoWCalendar.SelectedEventMonth,
GroupCalendar.WoWCalendar.SelectedEventDay,
GroupCalendar.WoWCalendar.SelectedEventYear)
local vEvents = self.CalendarData[vDate]
if not vEvents then
return
end
for _, vEvent in ipairs(vEvents) do
if vEvent.Index == GroupCalendar.WoWCalendar.SelectedEventIndex then
return vEvent
end
end
end
function GroupCalendar._Calendar:FlushCaches()
if self.ReadOnly then
return
end
if self.CalendarID ~= "PLAYER" then
for vDate, vSchedule in pairs(self.Schedules) do
self.Schedules[vDate] = nil
end
else
self:Synchronize()
end
GroupCalendar.EventLib:DispatchEvent("GC5_CALENDAR_CHANGED")
end
function GroupCalendar._Calendar:CVarUpdate(pName, pValue)
if pName == "calendarShowDarkmoon"
or pName == "calendarShowWeeklyHolidays"
or pName == "calendarShowBattlegrounds" then
self:FlushCaches()
end
end
function GroupCalendar._Calendar:GetSchedule(pMonth, pDay, pYear)
if not pMonth or not pDay or not pYear then
error("GetSchedule: month, day and year expected")
end
local vDate = GroupCalendar.DateLib:ConvertMDYToDate(pMonth, pDay, pYear)
local vSchedule = self.Schedules[vDate]
if not vSchedule then
vSchedule = GroupCalendar:New(GroupCalendar._CalendarDay, self.OwnersName, self.CalendarID, self.CalendarData, self.ReadOnly)
vSchedule:SetDate(pMonth, pDay, pYear)
self.Schedules[vDate] = vSchedule
end
return vSchedule
end
function GroupCalendar._Calendar:GetLocalSchedule(pMonth, pDay, pYear)
end
function GroupCalendar._Calendar:Synchronize()
local currentDate = GroupCalendar.WoWCalendar:GetDate()
self.CurrentMonth = currentDate.month
self.CurrentDay = currentDate.monthDay
self.CurrentYear = currentDate.year
self.CurrentDate = GroupCalendar.DateLib:ConvertMDYToDate(self.CurrentMonth, self.CurrentDay, self.CurrentYear)
local vCutoffDate = self.CurrentDate - self.cMaxHistory
-- Mark the schedules so we can tell which ones don't get used
for vDate, vSchedule in pairs(self.Schedules) do
vSchedule.Unused = true
end
for vDate = vCutoffDate, self.CurrentDate + 365 do
local vMonth, vDay, vYear = GroupCalendar.DateLib:ConvertDateToMDY(vDate)
if self:HasDayEvents(vMonth, vDay, vYear) then
local vSchedule = self.Schedules[vDate]
if not vSchedule then
vSchedule = GroupCalendar:New(GroupCalendar._CalendarDay, self.OwnersName, self.CalendarID, self.CalendarData, self.ReadOnly)
self.Schedules[vDate] = vSchedule
else
vSchedule.Unused = nil
end
vSchedule:SetDate(vMonth, vDay, vYear)
end
end
-- Remove unused schedules
for vDate, vSchedule in pairs(self.Schedules) do
if vSchedule.Unused then
self.Schedules[vDate] = nil
end
end
end
function GroupCalendar._Calendar:HasDayEvents(pMonth, pDay, pYear)
local vMonthOffset = GroupCalendar.WoWCalendar:GetMonthOffset(pMonth, pYear)
local vNumEvents = GroupCalendar.WoWCalendar:GetNumDayEvents(vMonthOffset, pDay)
SetCVar("calendarShowLockouts", 1)
for vEventIndex = 1, vNumEvents do
local event = GroupCalendar.WoWCalendar:GetDayEvent(vMonthOffset, pDay, vEventIndex)
if (self.CalendarID == GroupCalendar._CalendarDay.cBlizzardCalendarIDs[event.calendarType])
or (self.CalendarID ~= "BLIZZARD" and not GroupCalendar._CalendarDay.cBlizzardCalendarIDs[event.calendarType]) then
return true
end
end
return false
end
function GroupCalendar._Calendar:NewEvent(pMonth, pDay, pYear, pCalendarType)
if self.ReadOnly then
error("Can't create new events in a read-only calendar")
end
if self:IsAfterMaxCreateDate(pMonth, pDay, pYear) then
error("Can't create events that far in the future")
end
local vEvent = {}
setmetatable(vEvent, GroupCalendar._APIEventMetaTable)
vEvent:NewEvent(self.OwnersName, pMonth, pDay, pYear, pCalendarType)
return vEvent
end
function GroupCalendar._Calendar:IsAfterMaxCreateDate(month, day, year)
if not month or not day or not year then
error("Expected month, day, year")
end
local maxCreateDate = GroupCalendar.WoWCalendar:GetMaxCreateDate()
if year > maxCreateDate.year then
return true
elseif year < maxCreateDate.year then
return false
elseif month > maxCreateDate.month then
return true
elseif month < maxCreateDate.month then
return false
else
return day > maxCreateDate.monthDay
end
end
----------------------------------------
GroupCalendar._CalendarDay = {}
----------------------------------------
function GroupCalendar._CalendarDay:Construct(pOwnersName, pCalendarID, pCalendarData, pReadOnly)
self.OwnersName = pOwnersName
self.CalendarID = pCalendarID
self.CalendarData = pCalendarData
self.ReadOnly = pReadOnly
self.Events = nil
end
GroupCalendar._CalendarDay.cBlizzardCalendarIDs =
{
SYSTEM = "BLIZZARD",
HOLIDAY = "BLIZZARD",
RAID_RESET = "BLIZZARD"
}
function GroupCalendar._CalendarDay:SetDate(pMonth, pDay, pYear)
local vDate = GroupCalendar.DateLib:ConvertMDYToDate(pMonth, pDay, pYear)
if not self.Events then
if self.CalendarData then
self.Events = self.CalendarData[vDate]
end
if not self.Events then
self.Events = {}
end
end
-- Synchronize to the Blizzard database if we're not read-only
if not self.ReadOnly then
self:SynchronizeEvents(pMonth, pDay, pYear)
if self.CalendarData then
if #self.Events > 0 then
self.CalendarData[vDate] = self.Events
else
self.CalendarData[vDate] = nil
end
end
end
end
function GroupCalendar._CalendarDay:SynchronizeEvents(pMonth, pDay, pYear)
if self.CalendarID == "PLAYER"
and not GroupCalendar.BlizzardCalendarReady then
return -- Can't do anything until the WoW calendar's have loaded
end
-- Mark existing event records so we can determine if
-- they're still active once we're done
if self.Events then
for _, vEvent in ipairs(self.Events) do
vEvent.Orphaned = true
end
else
self.Events = {}
end
-- Collect the events from the WoW calendar
local vMonthOffset = GroupCalendar.WoWCalendar:GetMonthOffset(pMonth, pYear)
local vNumEvents = GroupCalendar.WoWCalendar:GetNumDayEvents(vMonthOffset, pDay)
SetCVar("calendarShowLockouts", 1)
local vAPIEvent = {}
setmetatable(vAPIEvent, GroupCalendar._APIEventMetaTable)
local vCurrentDateTimeStamp = GroupCalendar.DateLib:GetServerDateTimeStamp()
local vCalendarChanged
for vEventIndex = 1, vNumEvents do
vAPIEvent:SetEvent(self.OwnersName, pMonth, pDay, pYear, vEventIndex)
if (self.CalendarID == self.cBlizzardCalendarIDs[vAPIEvent.CalendarType])
or (self.CalendarID ~= "BLIZZARD" and not self.cBlizzardCalendarIDs[vAPIEvent.CalendarType]) then
local vEvent = self:FindExistingEvent(vAPIEvent)
if vEvent then
local vChanged
for vKey, vValue in pairs(vAPIEvent) do
if vEvent[vKey] ~= vValue then
vEvent[vKey] = vValue
vChanged = true
end
end
vEvent.CacheUpdateDate, vEvent.CacheUpdateTime = GroupCalendar.DateLib:GetServerDateTime()
vEvent.Orphaned = nil
if vChanged then
vCalendarChanged = true
GroupCalendar.BroadcastLib:Broadcast(vEvent, "CHANGED")
end
else
vEvent = GroupCalendar:DuplicateTable(vAPIEvent, true)
setmetatable(vEvent, GroupCalendar._APIEventMetaTable)
vEvent.CreationDate, vEvent.CreationTime = GroupCalendar.DateLib:GetServerDateTime()
vEvent.CacheUpdateDate, vEvent.CacheUpdateTime = GroupCalendar.DateLib:GetServerDateTime()
if self.CalendarID == "PLAYER"
and not vEvent:IsCooldownEvent()
and not vEvent:HasPassed(vCurrentDateTimeStamp)
and vEvent.InvitedBy ~= GroupCalendar.PlayerName then
vEvent.Unseen = true
end
if not self.Events then
self.Events = {}
end
table.insert(self.Events, vEvent)
vCalendarChanged = true
GroupCalendar.EventLib:DispatchEvent("GC5_EVENT_ADDED", vEvent)
end
end
end
for vIndex = #self.Events, 1, -1 do
local vEvent = self.Events[vIndex]
if vEvent.Orphaned then
vCalendarChanged = true
table.remove(self.Events, vIndex)
GroupCalendar.BroadcastLib:Broadcast(vEvent, "DELETED")
end
end
if vCalendarChanged then
GroupCalendar.EventLib:DispatchEvent("GC5_CALENDAR_CHANGED", vEvent)
end
end
function GroupCalendar._CalendarDay:FindExistingEvent(pEvent)
local vBestScore, vBestEvent
for _, vEvent in ipairs(self.Events) do
if vEvent.Orphaned then
if pEvent.CalendarType == vEvent.CalendarType
and pEvent.SequenceType == vEvent.SequenceType then
local vScore = 0
if pEvent.Title == vEvent.Title then vScore = vScore + 1 end
if pEvent.TitleTag == vEvent.TitleTag then vScore = vScore + 1 end
if pEvent.Hour == vEvent.Hour
and pEvent.Minute == vEvent.Minute then vScore = vScore + 1 end
if pEvent.Month == vEvent.Month
and pEvent.Day == vEvent.Day
and pEvent.Year == vEvent.Year then vScore = vScore + 1 end
if pEvent.EventType == vEvent.EventType
and pEvent.TextureID == vEvent.TextureID
and pEvent.Difficulty == vEvent.Difficulty then vScore = vScore + 1 end
if pEvent.ModStatus == vEvent.ModStatus then vScore = vScore + 0.25 end
if pEvent.InviteStatus == vEvent.InviteStatus then vScore = vScore + 0.25 end
if pEvent.InviteType == vEvent.InviteType then vScore = vScore + 0.25 end
if pEvent.InvitedBy == vEvent.InvitedBy then vScore = vScore + 0.5 end
if vScore and vScore >= 3 and (not vBestScore or vScore > vBestScore) then
vBestScore = vScore
vBestEvent = vEvent
end
end -- if pCalendarTYpe
end -- if Orphaned
end -- for
return vBestEvent
end
function GroupCalendar:AddTooltipEvents(pTooltip, pEvents, pUseLocalTime)
if not pEvents then
return
end
for vIndex, vEvent in ipairs(pEvents) do
local vColor = vEvent:GetEventColor()
local vOwner = tern((vEvent.RealmName ~= GroupCalendar.RealmName) and vEvent.OwnersName,
string.format(GroupCalendar.cForeignRealmFormat, vEvent.OwnersName, vEvent.RealmName),
vEvent.OwnersName)
local vEventFormat = vEvent.InvitedBy and vEvent.InvitedBy ~= "" and GroupCalendar.cTooltipScheduleItemFormat or "%s"
local vTitle = vEventFormat:format(vEvent.Title, vOwner)
if vEvent:IsAllDayEvent() then
pTooltip:AddDoubleLine(
GroupCalendar.cAllDay,
vTitle,
vColor.r, vColor.g, vColor.b, vColor.r, vColor.g, vColor.b)
else
local vTime = GroupCalendar.DateLib:ConvertHMToTime(vEvent.Hour, vEvent.Minute)
if pUseLocalTime then
vTime = GroupCalendar.DateLib:GetLocalTimeFromServerTime(vTime)
end
pTooltip:AddDoubleLine(
GroupCalendar.DateLib:GetShortTimeString(vTime),
vTitle,
vColor.r, vColor.g, vColor.b, vColor.r, vColor.g, vColor.b)
end
end
end
function GroupCalendar:GetEventTypeTextures(eventType)
local textures = GroupCalendar.WoWCalendar:EventGetTextures(eventType)
return textures
end
function GroupCalendar:InitializeEventDefaults()
GroupCalendar.DefaultEventLimits = {}
GroupCalendar.DefaultEventLevel = {}
local vEventTypeNames = {GroupCalendar.WoWCalendar:EventGetTypes()}
for vEventType, vEventTypeName in ipairs(vEventTypeNames) do
GroupCalendar.DefaultEventLimits[vEventType] = {}
GroupCalendar.DefaultEventLevel[vEventType] = {}
if vEventType == CALENDAR_EVENTTYPE_RAID or vEventType == CALENDAR_EVENTTYPE_DUNGEON or vEventType == CALENDAR_EVENTTYPE_HEROIC_DUNGEON then
local vEventTypeTextures = GroupCalendar:GetEventTypeTextures(vEventType)
for vTextureIndex, vTextureInfo in ipairs(vEventTypeTextures) do
local vLimit, vMinLevel
-- Dungeons are always 5-man
if vEventType == CALENDAR_EVENTTYPE_DUNGEON or vEventType == CALENDAR_EVENTTYPE_HEROIC_DUNGEON then
vLimit = 5
if vTextureInfo.ExpLevel == 1 then
vMinLevel = 60
elseif vTextureInfo.ExpLevel == 2 then
vMinLevel = 70
else
vMinLevel = 10
end
-- Classic raids are 20 for ZG and AQR and 40 for everything else
elseif vTextureInfo.ExpLevel == 0 then
if vTextureInfo.TextureName == "LFGIcon-ZulGurub"
or vTextureInfo.TextureName == "LFGIcon-AQRuins" then
vLimit = 20
vMinLevel = 58
else
vLimit = 40
vMinLevel = 58
end
-- TBC raids are 10-man for Karazhan and Zul'Aman, 25 for everything else
elseif vTextureInfo.ExpLevel == 0 then
if vTextureInfo.TextureName == "LFGIcon-Karazhan"
or vTextureInfo.TextureName == "LFGIcon-ZulAman" then
vLimit = 10
vMinLevel = 68
else
vLimit = 25
vMinLevel = 70
end
-- WotLK raids are 10-man for non-heroic, 25 for
-- heroic (I'm assuming this is the default for the future too)
else
if vTextureInfo.Name and vTextureInfo.Name:sub(-1) == ")" then -- Cheesy, but what else is there?
vLimit = 25
vMinLevel = 80
else
vLimit = 10
vMinLevel = 78
end
end
GroupCalendar.DefaultEventLimits[vEventType][vTextureIndex] = vLimit
GroupCalendar.DefaultEventLevel[vEventType][vTextureIndex] = vMinLevel
end -- for vTextureIndex
end -- if vEventType
end -- for vEventType
end
----------------------------------------
GroupCalendar._BaseEventMethods = {}
----------------------------------------
----------------------------------------
-- Get
function GroupCalendar._BaseEventMethods:GetTexture()
if not GroupCalendar.EventTypeTextures then
GroupCalendar.EventTypeTextures = {}
end
local vEventTypeTextures = GroupCalendar:GetEventTypeTextures(self.EventType)
return GroupCalendar:GetTextureFile(
self.TextureIndex and vEventTypeTextures[self.TextureIndex] and vEventTypeTextures[self.TextureIndex].TextureName,
self.CalendarType, self.NumSequenceDays ~= 2 and self.SequenceType or "", self.EventType, self.TitleTag)
end
function GroupCalendar._BaseEventMethods:GetLocation()
local vEventTypeTextures = GroupCalendar:GetEventTypeTextures(self.EventType)
if not vEventTypeTextures
or not vEventTypeTextures[self.TextureIndex] then
return ""
end
return vEventTypeTextures[self.TextureIndex].Name
end
function GroupCalendar._BaseEventMethods:GetEventColor()
if self:IsPlayerCreated() then
if GroupCalendar.CALENDAR_INVITESTATUS_COLORS[self.InviteStatus] then
return GroupCalendar.CALENDAR_INVITESTATUS_COLORS[self.InviteStatus]
end
elseif GroupCalendar.CALENDAR_CALENDARTYPE_COLORS[self.CalendarType] then
return GroupCalendar.CALENDAR_CALENDARTYPE_COLORS[self.CalendarType]
end
-- Default to normal color
return NORMAL_FONT_COLOR
end
function GroupCalendar._BaseEventMethods:GetLevelRange()
return self.MinLevel, self.MaxLevel
end
function GroupCalendar._BaseEventMethods:GetLimits()
return self.Limits
end
function GroupCalendar._BaseEventMethods:GetDefaultPartySize()
if not GroupCalendar.DefaultEventLimits then
GroupCalendar:InitializeEventDefaults()
end
if not GroupCalendar.DefaultEventLimits[self.EventType] then
return
else
return GroupCalendar.DefaultEventLimits[self.EventType][self.TextureIndex],
GroupCalendar.DefaultEventLevel[self.EventType][self.TextureIndex]
end
end
function GroupCalendar._BaseEventMethods:GetUID()
if self.CalendarType == "HOLIDAY"
or self.CalendarType == "SYSTEM"
or self.CalendarType == "RAID_RESET" then
return string.format("%s//%04d%02d%02d//%d", self.CalendarType, self.Year, self.Month, self.Day, self.Index)
end
if not self.UID then
self.UID = math.random(1000000)
end
return self.RealmName.."//"..self.OwnersName.."//"..self.UID
end
function GroupCalendar._BaseEventMethods:GetCreationDateTime()
if not self.CreationDate then
self.CreationDate, self.CreationTime = GroupCalendar.DateLib:GetServerDateTime()
end
return self.CreationDate, self.CreationTime
end
function GroupCalendar._BaseEventMethods:GetModifiedDateTime()
if not self.CreationDate then
self.CacheUpdateDate, self.CacheUpdateTime = GroupCalendar.DateLib:GetServerDateTime()
end
return self.CacheUpdateDate, self.CacheUpdateTime
end
function GroupCalendar._BaseEventMethods:GetSecondsToStart(pCurrentDateTimeStamp)
local vDate = GroupCalendar.DateLib:ConvertMDYToDate(self.Month, self.Day, self.Year)
local vTime60 = GroupCalendar.DateLib:ConvertHMSToTime60(self.Hour, self.Minute, 0) or 0
local vDateTimeStamp = vDate * GroupCalendar.DateLib.cSecondsPerDay + vTime60
return vDateTimeStamp - pCurrentDateTimeStamp
end
function GroupCalendar._BaseEventMethods:HasPassed(pCurrentDateTimeStamp)
local vDuration = (self.Duration or (4 * 60)) * 60
return self:GetSecondsToStart(pCurrentDateTimeStamp) + vDuration < 0
end
----------------------------------------
-- Status
function GroupCalendar._BaseEventMethods:IsAllDayEvent()
if self.SequenceType == "ONGOING" then
return true
end
if self.TitleTag
and GroupCalendar.TitleTagInfo[self.TitleTag] then
return GroupCalendar.TitleTagInfo[self.TitleTag].AllDay
end
return false
end
function GroupCalendar._BaseEventMethods:IsCooldownEvent()
if self.CalendarType == "RAID_LOCKOUT" then
return true
end
if self.TitleTag
and GroupCalendar.TitleTagInfo[self.TitleTag] then
return GroupCalendar.TitleTagInfo[self.TitleTag].IsCooldown
end
return self.TitleTag ~= nil
end
function GroupCalendar._BaseEventMethods:IsBirthdayEvent()
return self.TitleTag == "BRTH"
end
function GroupCalendar._BaseEventMethods:IsPersonalEvent()
if self.TitleTag
and GroupCalendar.TitleTagInfo[self.TitleTag] then
return GroupCalendar.TitleTagInfo[self.TitleTag].IsPersonal
end
return (self.CalendarType == "PLAYER" or self.CalendarType == "GUILD_EVENT" or self.CalendarType == "GUILD" or self.CalendarType == "GUILD_ANNOUNCEMENT" or self.CalendarType == "COMMUNITY_EVENT")
and self.TitleTag ~= nil
end
function GroupCalendar._BaseEventMethods:IsDungeonEvent()
return (self.CalendarType == "PLAYER" or self.CalendarType == "GUILD_EVENT" or self.CalendarType == "GUILD" or self.CalendarType == "GUILD_ANNOUNCEMENT" or self.CalendarType == "COMMUNITY_EVENT")
and self.TitleTag == nil
end
function GroupCalendar._BaseEventMethods:IsSignupEvent()
return self.InviteType == CALENDAR_INVITETYPE_SIGNUP
end
function GroupCalendar._BaseEventMethods:IsAnnouncementEvent()
return self.CalendarType == "GUILD_ANNOUNCEMENT" or self.CalendarType == "GUILD"
end
function GroupCalendar._BaseEventMethods:IsPlayerCreated()
return self.CalendarType == "PLAYER"
or self.CalendarType == "GUILD"
or self.CalendarType == "GUILD_ANNOUNCEMENT"
or self.CalendarType == "GUILD_EVENT"
or self.CalendarType == "ARENA"
or self.CalendarType == "COMMUNITY_EVENT"
end
function GroupCalendar._BaseEventMethods:UsesLevelLimits()
if self.TitleTag
and GroupCalendar.TitleTagInfo[self.TitleTag] then
return GroupCalendar.TitleTagInfo[self.TitleTag].UsesLevelLimits
end
return (self.CalendarType == "PLAYER"
or self.CalendarType == "GUILD"
or self.CalendarType == "GUILD_EVENT"
or self.CalendarType == "GUILD_ANNOUNCEMENT"
or self.CalendarType == "COMMUNITY_EVENT")
and self.TitleTag == nil
end
function GroupCalendar._BaseEventMethods:UsesAttendance()
if self.TitleTag
and GroupCalendar.TitleTagInfo[self.TitleTag] then
return GroupCalendar.TitleTagInfo[self.TitleTag].UsesAttendance
end
return (self.CalendarType == "PLAYER" or self.CalendarType == "GUILD_EVENT" or self.CalendarType == "COMMUNITY_EVENT")
and (self.TitleTag == nil or self.TitleTag == "")
end
function GroupCalendar._BaseEventMethods:PlayerIsQualified()
return true
end
function GroupCalendar._BaseEventMethods:IsExpired()
local vServerDate, vServerTime = GroupCalendar.DateLib:GetServerDateTime()
local vEventDate, vEventTime = GroupCalendar.DateLib:ConvertMDYToDate(self.Month, self.Day, self.Year), GroupCalendar.DateLib:ConvertHMToTime(self.Hour, self.Minute)
return vEventDate < vServerDate or (vEventDate == vServerDate and vEventTime and vEventTime < vServerTime)
end
function GroupCalendar._BaseEventMethods:EventIsVisible(pIsPlayerEvent)
if not self:IsPlayerCreated() then
return true
end
if pIsPlayerEvent then
return true
end
return self.ModStatus == "CREATOR" or self:IsAttending()
end
function GroupCalendar._BaseEventMethods:IsAttending()
return not self.TitleTag
and (self.InviteStatus == CALENDAR_INVITESTATUS_ACCEPTED
or self.InviteStatus == CALENDAR_INVITESTATUS_TENTATIVE
or self.InviteStatus == CALENDAR_INVITESTATUS_SIGNEDUP
or self.InviteStatus == CALENDAR_INVITESTATUS_CONFIRMED
or self.InviteStatus == CALENDAR_INVITESTATUS_STANDBY)
end
function GroupCalendar._BaseEventMethods:GetAttendance()
return self.Attendance
end
function GroupCalendar._BaseEventMethods:GetInviteStatus(pPlayerName)
local vAttendance = self:GetAttendance()
if not vAttendance then
if pPlayerName == self.OwnersName then
return self.InviteStatus
elseif self.CalendarType == "GUILD_EVENT" or self.CalendarType == "COMMUNITY_EVENT" then
return CALENDAR_INVITESTATUS_NOT_SIGNEDUP
else
return
end
end
if not vAttendance[pPlayerName] then
if self.CalendarType == "GUILD_EVENT" or self.CalendarType == "COMMUNITY_EVENT" then
return CALENDAR_INVITESTATUS_NOT_SIGNEDUP
else
return
end
end
return vAttendance[pPlayerName].InviteStatus
end
----------------------------------------
GroupCalendar._APIEventMethods = {}
----------------------------------------
for vKey, vValue in pairs(GroupCalendar._BaseEventMethods) do
GroupCalendar._APIEventMethods[vKey] = vValue
end
function GroupCalendar._APIEventMethods:NewEvent(pOwnersName, pMonth, pDay, pYear, pCalendarType)
self.Month = pMonth
self.Day = pDay
self.Year = pYear
self.Index = nil
self.OwnersName = pOwnersName
self.RealmName = GroupCalendar.RealmName
self.Title = ""
self.TitleTag = nil
self.Hour = 20
self.Minute = 0
self.Duration = 180
self.MinLevel = nil
self.MaxLevel = nil
if pCalendarType then
self.CalendarType = pCalendarType
elseif CanEditGuildEvent() then
self.CalendarType = "GUILD_EVENT"
else
self.CalendarType = "PLAYER"
end
self.SequenceType = nil
self.EventType = CALENDAR_EVENTTYPE_OTHER
self.TextureID = nil
self.ModStatus = "CREATOR"
self.InviteStatus = CALENDAR_INVITESTATUS_CONFIRMED
self.InvitedBy = GroupCalendar.PlayerName
self.InviteType = CALENDAR_INVITETYPE_NORMAL
self.Difficulty = nil
self.Description = ""
self.DescriptionTag = nil
end
function GroupCalendar._APIEventMethods:SetEvent(pOwnersName, pMonth, pDay, pYear, pIndex)
if not pIndex then
return self:NewEvent(pOwnersName, pMonth, pDay, pYear)
end
self.Month = pMonth
self.Day = pDay
self.Year = pYear
self.Index = pIndex
self.OwnersName = pOwnersName
self.RealmName = GroupCalendar.RealmName
local monthOffset = GroupCalendar.WoWCalendar:GetMonthOffset(self.Month, self.Year)
local event = GroupCalendar.WoWCalendar:GetDayEvent(monthOffset, self.Day, self.Index)
self.Title = event.title
if (event.sequenceType == "END") then
self.Hour = event.endTime.hour;
self.Minute = event.endTime.minute;
else
self.Hour = event.startTime.hour;
self.Minute = event.startTime.minute;
end
self.CalendarType = event.calendarType
self.SequenceType = event.sequenceType
self.EventType = event.eventType
self.TextureID = event.iconTexture
self.ModStatus = event.modStatus
self.InviteStatus = event.inviteStatus
self.InvitedBy = event.invitedBy
self.Difficulty = event.difficulty
self.InviteType = event.inviteType
self.SequenceIndex = event.sequenceType
self.NumSequenceDays = event.numSequenceDays
self.DifficultyName = event.difficultyName
self.DontDisplayBanner = event.dontDisplayBanner
self.DontDisplayEnd = event.dontDisplayEnd
self.TitleTag = GroupCalendar.WoWCalendar:EventGetTitleTag()
self.EventCanComplain = GroupCalendar.WoWCalendar:ContextMenuEventCanComplain(monthOffset, self.Day, self.Index)
-- Correct the calendar type
self:ContextSelectEvent()
local currentCalendarType = GroupCalendar.WoWCalendar:ContextMenuEventGetCalendarType()
if self.CalendarType == "GUILD" and currentCalendarType ~= "GUILD" then
self.CalendarType = "PLAYER"
end
if self.Difficulty == ""
or self.Difficulty == 0 then
self.Difficulty = nil
end
if self.Difficulty then
self.Title = string.format(DUNGEON_NAME_WITH_DIFFICULTY, self.Title or "nil", self.DifficultyName or "nil")
end
self.Title = GroupCalendar.WoWCalendar:GetDisplayTitle(self.CalendarType, self.SequenceType, self.Title)
if self.CalendarType == "HOLIDAY" then
local holidayInfo = GroupCalendar.WoWCalendar:GetHolidayInfo(monthOffset, self.Day, self.Index)
self.Description = holidayInfo.description
elseif self.CalendarType == "RAID_LOCKOUT"
or self.CalendarType == "RAID_RESET" then
self.Description = ""
end
if self.SequenceType == "ONGOING" then
self.Hour = nil
self.Minute = nil
end
if not self.InvitedBy or self.InvitedBy == "" then
self.InvitedBy = (self.CalendarType == "RAID_LOCKOUT" and GroupCalendar.PlayerData.Name)
or (self.CalendarType == "HOLIDAY" and "Holiday")
or (self.CalendarType == "SYSTEM" and GroupCalendar.cBlizzardOwner)
or (self.CalendarType == "RAID_RESET" and GroupCalendar.cBlizzardOwner)
end
end
function GroupCalendar._APIEventMethods:Open()
if GroupCalendar.WoWCalendar.OpenedEvent then
GroupCalendar.WoWCalendar.OpenedEvent:Close()
end
SetCVar("calendarShowLockouts", 1) -- Make sure this is on so indices are correct
if self.Index then
GroupCalendar.WoWCalendar:OpenEvent(GroupCalendar.WoWCalendar:GetMonthOffset(self.Month, self.Year), self.Day, self.Index)
GroupCalendar.WoWCalendar.OpenedEvent = self
else
if self.CalendarType == "GUILD_EVENT" then
GroupCalendar.WoWCalendar:CreateGuildSignUpEvent()
elseif self.CalendarType == "GUILD_ANNOUNCEMENT" then
GroupCalendar.WoWCalendar:CreateGuildAnnouncementEvent()
elseif self.CalendarType == "COMMUNITY_EVENT" then
GroupCalendar.WoWCalendar:CreateCommunitySignUpEvent()
else
GroupCalendar.WoWCalendar:CreatePlayerEvent()
end
GroupCalendar.WoWCalendar.OpenedEvent = self
self:InitializeNewEvent()