forked from Dragnogd/Instance-Achievement-Tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAchievementTrackerCore.lua
More file actions
4096 lines (3670 loc) · 175 KB
/
AchievementTrackerCore.lua
File metadata and controls
4096 lines (3670 loc) · 175 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
--------------------------------------
-- Namespaces
--------------------------------------
local _, core = ... --Global Addon Namespace
local L = core.L --Translation Table
local events = CreateFrame("Frame") --All events are registered to this frame
local UIConfig --UIConfig is used to make a display asking the user if they would like
local UICreated = false --To enable achievement tracking when they enter an instances
local debugMode = false
local debugModeChat = false
local sendDebugMessages = false
local ptrVersion = "9.0.1"
--------------------------------
-- Saved Variables tables
--------------------------------
AchievementTrackerOptions = {} --Saved Variables Tables
AchievementTrackerDebug = {}
events:RegisterEvent("ADDON_LOADED") --This is the first event that is called as soon as the addon loaded. Does Initial Setup
events:RegisterEvent("GET_ITEM_INFO_RECEIVED") --Get Item Information after the game has loaded to finish loading tactics
events:RegisterEvent("PLAYER_LOGIN") --Fired just before login has finished
function generateItemCache() --The Item Cache can only be generated once the game has loaded
for i,v in pairs(core.ItemCache) do --We need to first get information about the item to load into the cache
--If item does not return nil then add to tactics now as GET_ITEM_INFO_RECEIVED only fires if items are not in the cache
local itemName, itemLink = GetItemInfo(core.ItemCache[v])
if itemLink ~= nil then
for expansion, _ in pairs(core.Instances) do
for instanceType, _ in pairs(core.Instances[expansion]) do
for instance, _ in pairs(core.Instances[expansion][instanceType]) do
for boss, _ in pairs(core.Instances[expansion][instanceType][instance]) do
if boss ~= "name" then
if type(core.Instances[expansion][instanceType][instance][boss].tactics) == "table" then
if UnitFactionGroup("player") == "Alliance" then
if string.find(core.Instances[expansion][instanceType][instance][boss].tactics[1], ("IAT_" .. core.ItemCache[v])) then
core.Instances[expansion][instanceType][instance][boss].tactics[1] = string.gsub(core.Instances[expansion][instanceType][instance][boss].tactics[1], ("IAT_" .. core.ItemCache[v]), itemLink)
end
else
if string.find(core.Instances[expansion][instanceType][instance][boss].tactics[2], ("IAT_" .. core.ItemCache[v])) then
core.Instances[expansion][instanceType][instance][boss].tactics[2] = string.gsub(core.Instances[expansion][instanceType][instance][boss].tactics[2], ("IAT_" .. core.ItemCache[v]), itemLink)
end
end
else
if string.find(core.Instances[expansion][instanceType][instance][boss].tactics, ("IAT_" .. core.ItemCache[v])) then
core.Instances[expansion][instanceType][instance][boss].tactics = string.gsub(core.Instances[expansion][instanceType][instance][boss].tactics, ("IAT_" .. core.ItemCache[v]), itemLink)
end
end
end
end
end
end
end
end
end
end
function events:GET_ITEM_INFO_RECEIVED(self, arg1)
if core:has_value2(core.ItemCache, arg1) then
--Update table with updated info
for expansion, _ in pairs(core.Instances) do
for instanceType, _ in pairs(core.Instances[expansion]) do
for instance, _ in pairs(core.Instances[expansion][instanceType]) do
for boss, _ in pairs(core.Instances[expansion][instanceType][instance]) do
if boss ~= "name" then
if type(core.Instances[expansion][instanceType][instance][boss].tactics) == "table" then
if UnitFactionGroup("player") == "Alliance" then
if string.find(core.Instances[expansion][instanceType][instance][boss].tactics[1], ("IAT_" .. arg1)) then
local itemName, itemLink = GetItemInfo(arg1)
if itemLink ~= nil then
core.Instances[expansion][instanceType][instance][boss].tactics[1] = string.gsub(core.Instances[expansion][instanceType][instance][boss].tactics[1], ("IAT_" .. arg1), itemLink)
end
end
else
if string.find(core.Instances[expansion][instanceType][instance][boss].tactics[2], ("IAT_" .. arg1)) then
local itemName, itemLink = GetItemInfo(arg1)
if itemLink ~= nil then
core.Instances[expansion][instanceType][instance][boss].tactics[2] = string.gsub(core.Instances[expansion][instanceType][instance][boss].tactics[2], ("IAT_" .. arg1), itemLink)
end
end
end
else
if string.find(core.Instances[expansion][instanceType][instance][boss].tactics, ("IAT_" .. arg1)) then
local itemName, itemLink = GetItemInfo(arg1)
if itemLink ~= nil then
core.Instances[expansion][instanceType][instance][boss].tactics = string.gsub(core.Instances[expansion][instanceType][instance][boss].tactics, ("IAT_" .. arg1), itemLink)
end
end
end
end
end
end
end
end
end
end
function generateNPCCache()
core:sendDebugMessage("Attempting to load from local NPC Cache")
GetNameFromLocalNpcIDCache()
core:sendDebugMessage("Generating NPC Cache...")
local count = 1
local tempNPC = {}
for i,v in pairs(core.NPCCache) do
--GetNameFromNpcIDCache(core.NPCCache[v])
table.insert(tempNPC, core.NPCCache[v])
end
generateNPCs = C_Timer.NewTicker(0.01, function()
--core:sendDebugMessage("Fetching: " .. tempNPC[count] .. "(" .. count .. "/" .. #tempNPC .. ")")
GetNameFromNpcIDCache(tempNPC[count])
count = count + 1
if generateNPCs._remainingIterations == 1 then
core:sendDebugMessage("NPC cache generated")
end
end, #tempNPC)
end
function getNPCName(npcID)
if not tonumber(core.NPCCache[npcID]) then
return core.NPCCache[npcID]
else
GetNameFromNpcIDCache(npcID)
return ""
end
end
events:SetScript("OnEvent", function(self, event, ...)
return self[event] and self[event](self, event, ...) --Allow event arguments to be called from seperate functions
end)
--Used to detect whether there are still players in the group still in combat with the boss
function events:onUpdate(sinceLastUpdate)
self.sinceLastUpdate = (self.sinceLastUpdate or 0) + sinceLastUpdate;
if ( self.sinceLastUpdate >= 1 ) then -- in seconds
-- do stuff here
self.sinceLastUpdate = 0;
local combatStatus = getCombatStatus()
if combatStatus == false and core.encounterDetected == false then
--Once out of combat and encounter end has fired. Reset the variables
core:clearInstanceVariables()
core:clearVariables()
core:sendDebugMessage("Left Combat")
events:SetScript("OnUpdate",nil)
end
end
end
--------------------------------------
-- Achievement Scanning Variables
--------------------------------------
local playersToScan = {} --List of players that still need to be scanned to see which achievements they are missing for the current instance
local playersScanned = {} --List of players that have been successfully scanned for the current instance
local rescanNeeded = false --Set to true if a rescan is needed during a current scan. This is fired if the group size changes during a scan
local playerCurrentlyScanning = nil --This is set to the current player that is being scanned
local scanInProgress = false --Set to true when a scan of the group has started
core.scanFinished = false --Set to true when everyone in the group has been scanned successfully and no rescan is needed. Part of core so it can be accessed by the GUI
local scanAnnounced = false --Whether the achievement scanning has been announced to the chat
local scanCounter = 0 --Incremented everytime a scan completes so only scan timer waiting for a reponse are not used
--------------------------------------
-- Main Variables
--------------------------------------
core.currentZoneID = nil --The ID of the current instance the player is in
core.playerCount = 0 --The amount of players the instance lock can hold
core.inCombat = false --Whether anyone in the current group is in combat with boss/mobs
core.achievementsFailed = {} --Set to true when the requirements for a tracked achievement has failed
core.achievementsCompleted = {} --Set to true when the requrements for a tracked achievement have been met
core.chatType = nil --The chat type for the current group (say/party/raid)
core.achievementTrackedMessageShown = false --Set to true when the message "Tracking {achievement}" is output to the chat so that it only outputs once per fight
core.groupSize = 1 --Amount of players currently in the group. Set to 1 by default
core.groupSizeInInstance = 0 --Amount of players currently in the group and also in the current instance
core.achievementIDs = {} --Stores a list of the achievements to track for the current boss
core.achievementTrackingEnabled = false --Whether the user wants to track achievements for the particular instance or not
core.playersFailedPersonal = {} --List of players that have failed a personal achievement. Resets when you exit combat
core.playersSuccessPersonal = {} --List of players that have successfully completed a personal acheievement. Resets when you exit combat
core.enableAchievementScanning = true --Whether the addon is allowed to scan for achievements
core.addonEnabled = false
local combatTimerStarted = false --Used to determine if players in the group are still in combat with a boss
local lastMessageSent = "" --Stores the last message sent to the chat. This is used to prevent the same message being sent more than once in case of an error and to prevent unwanted spam
local requestToRun = false --Store whether the current addon sent the request to enable itself or not for achievement tracking
local electionFinished = false
local enableDisplayAchievement = true
local currentBossNums = {}
local detectBossWait = false
local announceToRaidWarning = false --Whether or not to announce messages to Raid Warning or not. Can only be done while in raid & user is raid leader or assist.
local enableSound = false --Whether to play a sound when achievement is completed
local enableSoundFailed = false --Whether to play a sound when achievement is failed
local failedSound = nil
local completedSound = nil
core.achievementDisplayStatus = "show" --How achievements should be display within the GUI (Show/Hide/Grey)
local mobMouseoverCache = {}
local encounterCache = {}
local announceMissingAchievements = false
local versionCheckInitiated = false
local trackAchievementsInUI = false --Track achievements in achievements UI upon entering raid
local trackAchievementInUiTable = {}
local trackCharacterAchievements = false
local changeInfoFrameScale = false
local trackAchievementsNoPrompt = false
local changeMinimapIcon = false
local sendMessageOnTimer_ProcessMessage = false --Set when we have message in message queue that needs to be output
local sendMessageOnTimer_Message = nil --Message in queue to be outputted
local sendMessageOnTimer_StartTimer = false --Is set when the loop that outputs a message every n seconds is started
local sendMessageOnTimer_OnCooldown = false --Waiting n seconds before outputting more messages
local trackAchievementsUIAutomatic = false --Whether the Track Achievement UI was generated automatically after entering instance
--------------------------------------
-- Current Instance Variables
--------------------------------------
core.inInstance = false
core.expansion = nil --Current expansion of the particular instance
core.instanceType = nil --Whether the instance is a dungeon or a raid
core.instance = nil --Name of the instance the player is currently in
core.instanceNameSpaces = nil --Instance name with spaces
core.foundBoss = false --Whether or not a boss has been found to track or not
core.currentBosses = {} --Stores a list of the bosses the player is currently attacking. (Can be mutliple if one boss has multiple achievements)
core.mobCache = {} --Stores a list of mobs that have been checked to see whether or not they need to be tracked or not
core.instanceVariablesReset = true --Whether the instance variables have reset after leaving an instance
--------------------------------------
-- Boss functions
--------------------------------------
core.mobCounter = 0 --Used in the trackMob function to see how many of a certain type of mob have currently spawned
core.mobUID = {} --Used in the trackMob function to store the unique UID of each mob of a certain type that has spawned
core.thresholdAnnounced = false --Used to check whether the trackMob funciton has announced the requirements have been met
core.encounterStarted = false
core.displayAchievements = false
core.encounterDetected = false
core.outputTrackingStatus = false
core.announceTrackedAchievementsToChat = false --Whether or not the user has chosen for IAT to announce which achievements are currently being tracked to chat
core.lockDetection = false --Once an encounter has finished. Stop the encounter being detected again straight away
core.onlyTrackMissingAchievements = false --Whether or not the user has chosen to only track missing achievements or not
core.trackingSupressed = false --Whether or not tracking is being supressed for the current fight
core.infoFrameShown = false
core.infoFrameLock = false
local automaticBlizzardTracking = true --By Default blizzard trackers are almost always white (true)
local automaticBlizzardTrackingInitialCheck = false --Initial check for value at start of each encounter
local enableCombatLogging = false
core.syncMessageQueue = {} --Messages sent from sync to other addons. Used when range is too small for one addon to cover.
local enableInfoFrame = true --Whether or not user has Info Frame enabled or not
core.groupSizeRequiresUpdate = false
--------------------------------------
-- Addon Syncing
--------------------------------------
local masterAddon = false --The master addon for the group. This stop multiple people with the addon outputting identical messages. Reset at the end of every fight
local playerRank = -1 --The rank of the player is the group. Players with higher rank get priorty over outputting messages unless they have an outdated addon
local addonID = 0
local messageQueue = {}
local blockRequirementsCheck = false --This blocks comparing who is the master addon for remainder of fight since it has been determined an addon already has better requirements than this addon
local relayAddonPlayer = nil
local relayAddonVersion = 0
local masterAddonPlayer = nil --The player who is currently the master addon
local versionRequestSent = false --When adds send version request, only do this once per fight.
local checkBrodcast = false
local broadcastMessage = nil
local broadcastMajorVersion = nil
local brodcastMinorVersion = nil
local firstBroadcast = 10
local newRequestRecieved = false
--------------------------------------
-- InfoFrame Variables
--------------------------------------
core.manualCountMaxSize = 0
core.manualCountCurrentSize = 0
core.manualCountSetup = false
--Get the current size of the group
function core:getGroupSize()
if core.encounterStarted == false then
local size = GetNumGroupMembers()
if size == 0 then
--If the size is 0 then player is not in a group. However we need to still set it to 1 since 0 players doesn't make sense
core.groupSize = 1
else
core.groupSize = size
end
core:sendDebugMessage("Group Size set to: " .. core.groupSize)
else
core:sendDebugMessage("Cannot update group size while fighting boss. Waiting till end of combat")
core.groupSizeRequiresUpdate = true
end
end
------------------------------------------------------
---- Players Achievements Functions
------------------------------------------------------
--Get a list of all the players currently in the group. This is used so we can scan all the players in the group to see which achievements they need
--This is run everytime the composition of the group changes so we always have an up to date list of players who need a certain achievement
function getPlayersInGroup()
if core.inInstance == true then
--Only Announce the scanning once.
if scanAnnounced == false then
printMessage(L["Core_StartingAchievementScan"] .. " " .. core.instanceNameSpaces .. " (" .. L["Core_GameFreezeWarning"] .. "!)")
scanAnnounced = true
end
core:getGroupSize() --Get current size of the group
scanInProgress = true
core.scanFinished = false
local currentGroup = {} --Create a local copy of the group so we can then compare it to the current group to see what changes there are.
if core.groupSize > 1 then
--We are in a group
local currentUnit
core:detectGroupType() --Detect the type of group the player is in so we can do the appropriate scanning
for i = 1, core.groupSize do
if core.chatType == "PARTY" or core.chatType == "INSTANCE_CHAT" then
if i < core.groupSize then
currentUnit = "party" .. i
else
currentUnit = "player"
end
elseif core.chatType == "RAID" then
currentUnit = "raid" .. i
end
local name, realm = UnitName(currentUnit)
if core:has_value(playersScanned, name) == false and core:has_value(playersToScan, name) == false and name ~= "Unknown" then
table.insert(playersToScan, name)
end
--Add to the current group so we can remove players that have left the group
if name ~= "Unknown" then
table.insert(currentGroup, name)
end
end
else
currentUnit = "player"
local name, realm = UnitName(currentUnit)
if core:has_value(playersScanned, name) == false and core:has_value(playersToScan, name) == false and name ~= "Unknown" then
table.insert(playersToScan, name)
end
table.insert(currentGroup, name)
end
--Check if anyone in the group has left that has already been scanned
--In playersToScan
if #playersToScan > 0 then
for i = #playersToScan, 1, -1 do
if core:has_value(currentGroup, playersToScan[i]) == false then
table.remove(playersToScan, i)
end
end
end
--In playersScanned
if #playersScanned > 0 then
for i = #playersScanned, 1, -1 do
if core:has_value(currentGroup, playersScanned[i]) == false then
--Remove player from the table that generates the UI for that achievementw
for boss,_ in pairs(core.Instances[core.expansion][core.instanceType][core.instance]) do
if boss ~= "name" then
local name = playersScanned[i]
--print("Removing: " .. name)
--Check if player was added the table
for j = 1, #core.Instances[core.expansion][core.instanceType][core.instance][boss].players do
if core.Instances[core.expansion][core.instanceType][core.instance][boss].players[j] == name then
table.remove(core.Instances[core.expansion][core.instanceType][core.instance][boss].players, j)
--print("Removed: " .. name)
end
end
end
end
--Update the GUI
core.Config:Instance_OnClickAutomatic()
table.remove(playersScanned, i)
end
end
end
rescanNeeded = false
--Start the player scanning
if #playersToScan > 0 then
--Fetch information for the next person in the group
getInstanceAchievements()
else
core:sendDebugMessage(L["Core_AchievementScanFinished"] .. " (" .. #playersScanned .. "/" .. core.groupSize .. ")")
scanInProgress = false
core.scanFinished = true
--Once the achievement scanning has finished enable the achievement tab to start scanning again
if _G["AchievementFrameComparison"] ~= nil then
--Re-register this event so achievement ui and inspect achievement ui work as intended
_G["AchievementFrameComparison"]:RegisterEvent("INSPECT_ACHIEVEMENT_READY")
end
--Announce which achievements this addon player needs to still get in this instance
if announceMissingAchievements == false then
announceMissingAchievements = true
local achievements = ""
local foundAchievement = false
for boss,_ in pairs(core.Instances[core.expansion][core.instanceType][core.instance]) do
if boss ~= "name" then
local name, _ = UnitName("player")
if core:has_value(core.Instances[core.expansion][core.instanceType][core.instance][boss].players, name) == true then
foundAchievement = true
achievements = achievements .. GetAchievementLink(core.Instances[core.expansion][core.instanceType][core.instance][boss].achievement)
end
end
end
if foundAchievement == false then
core:printMessage(L["Core_CompletedAllAchievements"] .. " " .. achievements)
else
core:printMessage(L["Core_IncompletedAchievements"])
end
end
end
else
core:sendDebugMessage("Player is not in an instance. Cancelling scan")
end
end
--Used to fetch achievement information for each player in the group. This is used so players can see and output which players in the group are missing which achievements
--TODO: have a limit on the amount of times a certain player is scanned. This is needed so we are not constantly scanning players that are offline or players who never enter the instance
function getInstanceAchievements()
ClearAchievementComparisonUnit()
--Make sure the player we are about to scan is still in the group
if UnitName(playersToScan[1]) ~= nil then
playerCurrentlyScanning = playersToScan[1]
--core:sendDebugMessage("Setting Comparison Unit to: " .. UnitName(playersToScan[1]))
core.currentComparisonUnit = UnitName(playersToScan[1])
--Check if the achievement ui is open before setting the comparison unit
if _G["AchievementFrame"] then
--The AchievementFrameComparison_OnEvent in Blizzard_AchievementUI does not check if the INSPECT_ACHIEVEMENT_READY event was fired from it's own addon or not
--Temporarily disable the event while we do our scanning.
--To protect against errors by disabling event, pause the scanning if the achievement ui or inspect achievement ui is shown
_G["AchievementFrameComparison"]:UnregisterEvent("INSPECT_ACHIEVEMENT_READY");
SetAchievementComparisonUnit(playersToScan[1])
else
--Achievement Frame has not been loaded so go ahead and set the comparison unit
SetAchievementComparisonUnit(playersToScan[1])
end
--Set the id to the current scanCounter so we can determine if the timer is still valid or not. If the scanCounter is higher than the local timer then ignore the output from the timer since it's no longer valid
local scanCounterloc = scanCounter
--Wait 2 seconds then check if the achievement information was returned successfully. If playerCurrentlyScanning is nil then we can assume the information was returned successfully
--If playerCurrentlyScanning still has a value then INSPECT_ACHIEVEMNT_READY event has not run and the information for that player was not fetched
C_Timer.After(2, function()
--Check if the scan is still valid or not
if scanCounterloc == scanCounter then
--Last player scan was successfully. Check if we need to continue scanning
-- if #playersToScan > 0 then
-- getInstanceAchievements()
-- elseif #playersToScan == 0 and rescanNeeded == false then
-- printMessage("Achievment Scanning Finished (" .. #playersScanned .. "/" .. core.groupSize .. ")")
-- scanInProgress = false
-- core.scanFinished = true
-- elseif #playersToScan == 0 and rescanNeeded == true then
-- --print("Achievement Scanning Finished but some players still need scanning. Waiting 20 seconds then trying again (" .. #playersScanned .. "/" .. core.groupSize .. ")")
-- C_Timer.After(10, function()
-- scanInProgress = true
-- getPlayersInGroup()
-- end)
-- end
--Last player to scan was not successfull
--core:sendDebugMessage("Last scan was unsuccessfull: " .. scanCounterloc)
rescanNeeded = true
if playersToScan[1] ~= nil then
--print("Cannot Scan " .. playersToScan[1])
table.remove(playersToScan, 1)
end
if #playersToScan > 0 then
getInstanceAchievements()
elseif #playersToScan == 0 and rescanNeeded == true then
--print("Achievement Scanning Finished but some players still need scanning. Waiting 20 seconds then trying again (" .. #playersScanned .. "/" .. core.groupSize .. ")")
C_Timer.After(10, function()
scanInProgress = true
getPlayersInGroup()
end)
end
else
--core:sendDebugMessage("Cancelling: " .. scanCounterloc)
end
end)
else
rescanNeeded = true
scanInProgress = true
getPlayersInGroup()
end
end
------------------------------------------------------
---- Achievement Tracking Setup
------------------------------------------------------
--Run when the player initially enters an instance to setup variables such as instanceName, expansion etc so we can track the correct bosses
function getInstanceInfomation()
--Delay the execution of this function to make sure difficultyID information is ready to be fetched from the server
C_Timer.After(2, function()
--If the instance is different to the one we last checked then we need to reset varaibles and re-scan
if IsInInstance() and core.inInstance == true then
local instanceNameSpaces, _, difficultyID, _, maxPlayers, _, _, currentZoneID, _ = GetInstanceInfo()
if instanceNameSpaces ~= core.instanceNameSpaces then
--Instances don't match. Lets rescan
core.inInstance = false
if UIConfig ~= nil and core.inInstance == false then
core:sendDebugMessage("Hiding Tracking UI")
UIConfig:Hide()
end
--Disable achievement tracking if currently tracking
checkAndClearInstanceVariables()
end
end
if IsInInstance() and core.inInstance == false then
core:sendDebugMessage("Player has entered instance")
local instanceCompatible = false --Check whether player is on correct difficulty to earn achievements
core.instanceNameSpaces, _, core.difficultyID, _, core.maxPlayers, _, _, core.currentZoneID, _ = GetInstanceInfo()
if core.difficultyID ~= 0 then
core:sendDebugMessage(core.currentZoneID)
core.instance = core.currentZoneID --Instance name without any puntuation
core.instanceClear = "_" .. core.currentZoneID --Instance name with _ to fetch functions for tracking of the particular instance
core:sendDebugMessage("Offical Instance Name: " .. core.instance .. " " .. core.instanceClear)
--If the raid is in the lich king expansion then detect whether player is on the 10man or 25man difficulty
--This is only needed for raids that have seperate achievements for 10man and 25man. Happens for the majority of WOTLK raids
if core.instance == 615 or core.instance == 616 or core.instance == 249 or core.instance == 649 or core.instance == 624 or core.instance == 533 or core.instance == 631 then
if core.difficultyID == 3 or core.difficultyID == 5 then
--10 Man
core:sendDebugMessage("Detected Legacy 10 man Raid")
core.instance = core.instance .. -10
core:sendDebugMessage("New Instance Name: " .. core.instance)
elseif core.difficultyID == 4 or core.difficultyID == 6 then
--25 Man
core:sendDebugMessage("Detected Legacy 25 man raid")
core.instance = core.instance .. -25
core:sendDebugMessage("New Instance Name: " .. core.instance)
end
end
--Find the instance in the core.instances table so we can cache the value to be used later
for expansion,_ in pairs(core.Instances) do
for instanceType,_ in pairs(core.Instances[expansion]) do
for instance,_ in pairs(core.Instances[expansion][instanceType]) do
if instance == core.instance then
core.expansion = expansion
core.instanceType = instanceType
core.instance = instance
core.inInstance = true
core.instanceVariablesReset = false
core:sendDebugMessage("Expansion: " .. core.expansion)
core:sendDebugMessage("Instance Type: " .. core.instanceType)
core:sendDebugMessage("Instance: " .. core.instance)
end
end
end
end
--Check whether achievements can be earned for the instance the player has entered
core:sendDebugMessage("DifficultyID: " .. core.difficultyID)
if core.difficultyID == 2 then
--WOTLK/Cata/Mop/Wod heroic dungeons
if core.expansion == 8 or core.expansion == 7 or core.expansion == 6 or core.expansion == 5 then
instanceCompatible = true
end
elseif core.difficultyID == 23 then
--Legion/BFA/Shadowlands Mythics
if core.expansion == 5 or core.expansion == 4 or core.expansion == 3 or core.expansion == 2 then
instanceCompatible = true
end
--Mythic WoD don't work for most achievements
if core.difficultyID == 23 and core.expansion == 5 then
core.warnCompatible = true
end
elseif core.difficultyID == 3 or core.difficultyID == 5 then
--legacy10
instanceCompatible = true
elseif core.difficultyID == 4 or core.difficultyID == 6 then
--legacy25
instanceCompatible = true
elseif core.difficultyID == 11 or core.difficultyID == 12 then
--scenerios"
if core.expansion == 6 then
instanceCompatible = true
end
elseif core.difficultyID == 13 or core.difficultyID == 14 or core.difficultyID == 15 or core.difficultyID == 16 then
--current
instanceCompatible = true
elseif core.difficultyID == 7 or core.difficultyID == 17 and debugMode == true then
instanceCompatible = true
elseif core.difficultyID == 24 or core.difficultyID == 33 then
--Timewalking
instanceCompatible = true
end
if debugMode == true then
instanceCompatible = true
--Set instance we want to debug
-- core.instanceNameSpaces = "Castle Nathria"
-- core.instanceName = "CastleNathria"
-- core.instance = 2296
-- core.instanceClear = "_2296"
-- core.expansion = 2
-- core.instanceType = "Raids"
end
if instanceCompatible == true and core.expansion ~= nil then
--Check if the instance has any achievements to actually track
local foundTracking = false
core:sendDebugMessage("Expansion: " .. core.expansion)
core:sendDebugMessage("Instance Type: " .. core.instanceType)
core:sendDebugMessage("Instance: " .. core.instance)
for boss,_ in pairs(core.Instances[core.expansion][core.instanceType][core.instance]) do
if boss ~= "name" then
if core.Instances[core.expansion][core.instanceType][core.instance][boss].track ~= nil then
foundTracking = true
end
end
end
--Ask the user whether they want to enable Achievement Tracking in the instance. Always ask user even if we can't track anything, so that they can see what they are missing too.
if trackAchievementsUIAutomatic == false then
trackAchievementsUIAutomatic = true
core:sendDebugMessage("Asking user whether they want to track this instance")
if UICreated == false then
core:sendDebugMessage("Creating Tracking UI")
createEnableAchievementTrackingUI()
else
core:sendDebugMessage("Displaying Tracking UI since it was already created")
if trackAchievementsNoPrompt == true then
enableAchievementTracking()
else
UIConfig.content:SetText(L["Core_EnableAchievementTracking"] .. ": " .. core.instanceNameSpaces);
UIConfig:Show()
end
end
else
core:sendDebugMessage("No Achievements to track for this instance")
end
--Switch to correct tab in GUI
if core.expansion == 2 then
Tab_OnClick(_G["AchievementTrackerTab2"])
elseif core.expansion == 3 then
Tab_OnClick(_G["AchievementTrackerTab3"])
elseif core.expansion == 4 then
Tab_OnClick(_G["AchievementTrackerTab4"])
elseif core.expansion == 5 then
Tab_OnClick(_G["AchievementTrackerTab5"])
elseif core.expansion == 6 then
Tab_OnClick(_G["AchievementTrackerTab6"])
elseif core.expansion == 7 then
Tab_OnClick(_G["AchievementTrackerTab7"])
elseif core.expansion == 8 then
Tab_OnClick(_G["AchievementTrackerTab8"])
end
--Make sure right instance is selected
core.Config:Instance_OnClickAutomatic()
else
core:sendDebugMessage("Achievements cannot be earned for the following difficulty " .. core.difficultyID)
end
else
--Information about the instance difficulty has not finished loading. Re-call function and try again
core:sendDebugMessage("Unable to fetch DifficultyID for current instance. Waiting 2 seconds then trying again")
getInstanceInfomation()
end
elseif IsInInstance() == false and core.inInstance == true then
core:sendDebugMessage("6")
core.inInstance = false
if UIConfig ~= nil then
core:sendDebugMessage("Hiding Tracking UI")
UIConfig:Hide()
end
end
end)
end
--Run if we need to setup additional events/variables for a certain instance. For example if we need to track additional events such as messages from bosses
function initialInstanceSetup()
--Used to start certain events for some instances so we don't have to run them when they are not needed
core:sendDebugMessage("Starting Initial Setup If Needed...")
local retOK, ret1 = pcall(function() core[core.instanceClear]:InitialSetup() end);
if (retOK) then
core:sendDebugMessage("Starting Initial Setup For Instance")
core[core.instanceClear]:InitialSetup()
else
core:sendDebugMessage("Function failed, error text: " .. ret1 .. ".")
end
end
--Create the achievement tracking UI if it is not already been created
--This will ask the user if they want to enable acheivement tracking for the current instance the player has entered
--It will only show in instances where there are achievements to be tracked and they are on the correct difficulty to earn acheivements
function createEnableAchievementTrackingUI()
UICreated = true
--Create the frame to ask the user whether they want to enable the addon for the particular instance they are in
UIConfig = CreateFrame("Frame", "AchievementTrackerCheck", UIParent, "UIPanelDialogTemplate", "AchievementTemplate")
UIConfig:SetSize(200, 200)
--Title
UIConfig.title = UIConfig:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
UIConfig.title:SetPoint("CENTER", AchievementTrackerCheckTitleBG, "CENTER", -5, 0);
UIConfig.title:SetText("IAT V" .. core.Config.majorVersion .. "." .. core.Config.minorVersion .. "." .. core.Config.revisionVersion);
--Content
UIConfig.content = UIConfig:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
UIConfig.content:SetPoint("TOPLEFT", AchievementTrackerCheckDialogBG, "TOPLEFT", 0, -5);
UIConfig.content:SetText(L["Core_EnableAchievementTracking"] .. ": " .. core.instanceNameSpaces);
UIConfig.content:SetWidth(185)
UIConfig.btnYes = CreateFrame("Button", nil, UIConfig, "GameMenuButtonTemplate");
UIConfig.btnYes:SetPoint("RIGHT", UIConfig.content, "BOTTOM", 0, -20);
UIConfig.btnYes:SetSize(80, 30);
UIConfig.btnYes:SetText(L["Core_Yes"]);
UIConfig.btnYes:SetNormalFontObject("GameFontNormal");
UIConfig.btnYes:SetHighlightFontObject("GameFontHighlight");
UIConfig.btnNo = CreateFrame("Button", nil, UIConfig, "GameMenuButtonTemplate");
UIConfig.btnNo:SetPoint("LEFT", UIConfig.btnYes, "RIGHT", 5, 0);
UIConfig.btnNo:SetSize(80, 30);
UIConfig.btnNo:SetText(L["Core_No"]);
UIConfig.btnNo:SetNormalFontObject("GameFontNormal");
UIConfig.btnNo:SetHighlightFontObject("GameFontHighlight");
UIConfig:SetHeight(UIConfig.content:GetHeight() + UIConfig.btnYes:GetHeight() + UIConfig.title:GetHeight() + 35)
UIConfig.btnYes:SetScript("OnClick", enableAchievementTracking);
UIConfig.btnNo:SetScript("OnClick", disableAchievementTracking);
UIConfig:SetMovable(true)
UIConfig:EnableMouse(true)
UIConfig:SetClampedToScreen(true)
UIConfig:RegisterForDrag("LeftButton")
UIConfig:SetScript("OnDragStart", UIConfig.StartMoving)
UIConfig:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
AchievementTrackerOptions["trackingFrameXPos"] = self:GetLeft()
AchievementTrackerOptions["trackingFrameYPos"] = self:GetBottom()
end)
--Info Frame X/Y Posiions
if AchievementTrackerOptions["trackingFrameXPos"] ~= nil and AchievementTrackerOptions["trackingFrameYPos"] ~= nil then
UIConfig:ClearAllPoints()
UIConfig:SetPoint("BOTTOMLEFT",AchievementTrackerOptions["trackingFrameXPos"],AchievementTrackerOptions["trackingFrameYPos"])
else
UIConfig:SetPoint("CENTER")
end
--Setup the InfoFrame
core.IATInfoFrame:SetupInfoFrame()
if trackAchievementsNoPrompt == true then
enableAchievementTracking()
end
end
--Players wants to track achievements for this instance
function enableAchievementTracking(self)
core.achievementTrackingEnabled = true
UIConfig:Hide()
--Register Events
events:RegisterEvent("INSPECT_ACHIEVEMENT_READY") --Used for scanning players in the group to see which achievements they are missing
events:RegisterEvent("GROUP_ROSTER_UPDATE") --Used to find out when the group size has changed and to therefore initiate an achievement scan of the group
events:RegisterEvent("CHAT_MSG_SYSTEM") --Used to find out when players join group to intiate an achievement scan of the group
events:RegisterEvent("PLAYER_REGEN_DISABLED") --Used to detect when the player has entered combat and to reset tracked variables for bosses
events:RegisterEvent("PLAYER_REGEN_ENABLED") --Used to track when the player has left combat
events:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED") --Used to track the completion/failiure of achievements
events:RegisterEvent("ENCOUNTER_START") --Used to detect the start of a boss fight
events:RegisterEvent("ENCOUNTER_END") --Used to detect the end of a boss fight
events:RegisterEvent("UPDATE_MOUSEOVER_UNIT") --Used to output achievement for boss and players missing achievements on hoverkk
--Start the achievement scan
if core.enableAchievementScanning == true then
getPlayersInGroup()
else
core:sendDebugMessage("Achievement Scanning Disabled")
end
--Start the combatlog if applicable
if enableCombatLogging == true then
core:sendDebugMessage("Enable CombatLog")
local isLogging = LoggingCombat()
if LoggingCombat() ~= true then
LoggingCombat(1)
core:printMessage(L["Core_CombatLogEnabled"])
--RaidNotice_AddMessage(RaidWarningFrame, "[IAT] Combat Log Started", ChatTypeInfo["SYSTEM"])
else
core:sendDebugMessage("Combatlog already enabled")
end
else
core:sendDebugMessage("Combatlog does not need to be enabled")
end
--Addon Syncing Priority:
--1.) Highest Version Number of addon
--2.) Raid Leader / Party Leader
--3.) Raid Assistant
--4.) Member
--Setup the instance events if required
initialInstanceSetup()
--Get a random ID between 1 and 100,000
addonID = random(1,100000)
--Check if there is already someone else running the addon in the group / whether the priority is higher for the current player than other players running the addon
if core.groupSize == 1 then
--Player is not a group so set the player to the master addon
core:sendDebugMessage("Setting Master Addon 1")
masterAddon = true
printMessage(L["Core_AchievementTrackingEnabledFor"] .. " " .. core.instanceNameSpaces)
else
--Get the rank for the current player
for i = 1, core.groupSize do
local name, rank, subgroup, level, class, fileName, zone, online, isDead, role, isML = GetRaidRosterInfo(i)
if name == UnitName("Player") then
--Send out message so other adds can add new player to their arrays
playerRank = rank
end
end
end
if core.warnCompatible == true then
StaticPopupDialogs["IAT_WarnCompatible"] = {
text = L["GUI_DifficultyWarning"],
button1 = "Ok",
timeout = 0,
whileDead = true,
hideOnEscape = true,
}
StaticPopup_Show ("IAT_WarnCompatible")
core.warnCompatible = false
end
if changeMinimapIcon == true then
_G["LibDBIcon10_InstanceAchievementTracker"].icon:SetVertexColor(0,1,0)
end
end
--Hide the achievment tracking UI once the player has left the instance
function disableAchievementTracking(self)
UIConfig:Hide()
core.inInstance = false
if changeMinimapIcon == true then
_G["LibDBIcon10_InstanceAchievementTracker"].icon:SetVertexColor(1,0,0)
end
end
--Used to detect when everyone in the group has left combat so we can reset global and instance variables
function getCombatStatus()
local playerInCombat = false
if core.groupSize > 1 then
--We are in a group
local currentUnit
core:detectGroupType()
for i = 1, core.groupSize do
if core.chatType == "PARTY" then
if i < core.groupSize then
currentUnit = "party" .. i
else
currentUnit = "player"
end
elseif core.chatType == "RAID" then
currentUnit = "raid" .. i
end
if currentUnit ~= nil then
if UnitAffectingCombat(currentUnit) == true then
playerInCombat = true
end
end
end
if playerInCombat == false then
--Everyone in the group has left combat so we can clear the tracking variables
return false
else
--Someone in the group is still in combat
return true
end
else
--Player is not in a group. Check if they are in combat though
if UnitAffectingCombat("Player") == true then
playerInCombat = true
return true
else
playerInCombat = false
return false
end
end
end
--------------------------------------
---- Custom Slash Command
--------------------------------------
core.commands = {
[L["Core_help"]] = function()
printMessage(L["Core_Commands"] .. ":")
printMessage("/iat help|r - " .. L["Core_ListCommands"])
printMessage("/iat toggle|r - " .. L["Core_CommandToggleTracking"])
end,
[L["Core_Enable"]] = function()
print("Enable/Disable addon")
end,
["version"] = function()
if versionCheckInitiated == false then
versionCheckInitiated = true
C_ChatInfo.SendAddonMessage("Whizzey", "sendVersionIAT", "RAID")
C_Timer.After(20, function()
versionCheckInitiated = false
end)
else
print("Wait 20 seconds before using this command again")
end
end,
["debug"] = function()
if sendDebugMessages == true then
debugMode = false
debugModeChat = false
sendDebugMessages = false
printMessage("Debug Mode Disabled")
else
debugMode = true
debugModeChat = true
sendDebugMessages = true
printMessage("Debug Mode Enabled")
if core.achievementTrackingEnabled == false and core.addonEnabled == true then
getInstanceInfomation()
elseif core.achievementTrackingEnabled == true and core.addonEnabled == true then
core.inInstance = false
if UIConfig ~= nil and core.inInstance == false then
core:sendDebugMessage("Hiding Tracking UI")
UIConfig:Hide()
end
core.achievementTrackingEnabled = false
--Disable achievement tracking if currently tracking
checkAndClearInstanceVariables()
ClearGUITabs()
getInstanceInfomation()
elseif core.addonEnabled == false then
core:printMessage(L["Core_EnableAddonFirst"])
end
end
end,
[L["Core_Toggle"]] = function()
trackAchievementsUIAutomatic = false
if core.achievementTrackingEnabled == false and core.addonEnabled == true then
getInstanceInfomation()
elseif core.achievementTrackingEnabled == true and core.addonEnabled == true then
core.inInstance = false
if UIConfig ~= nil and core.inInstance == false then
core:sendDebugMessage("Hiding Tracking UI")
UIConfig:Hide()
end
core.achievementTrackingEnabled = false
--Disable achievement tracking if currently tracking
checkAndClearInstanceVariables()
ClearGUITabs()
getInstanceInfomation()
elseif core.addonEnabled == false then
core:printMessage(L["Core_EnableAddonFirst"])
end
end,
};