-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Core.lua
1308 lines (1055 loc) · 42.6 KB
/
Core.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
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
local AddonName, AddOn = ...
-- Localize
local print, gsub, sfind = print, string.gsub, string.find
local GetItemInfo, IsEquippableItem = C_Item.GetItemInfo, C_Item.IsEquippableItem
local GetInventoryItemLink, UnitClass = GetInventoryItemLink, UnitClass
local SendChatMessage, UIParent = SendChatMessage, UIParent
local select, IsInGroup, GetItemInfoInstant = select, IsInGroup, C_Item.GetItemInfoInstant
local UnitGUID, IsInRaid, GetNumGroupMembers, GetInstanceInfo = UnitGUID, IsInRaid, GetNumGroupMembers, GetInstanceInfo
local C_Timer, InCombatLockdown, time = C_Timer, InCombatLockdown, time
local UnitIsConnected, CanInspect, UnitName = UnitIsConnected, CanInspect, UnitName
local WEAPON, ARMOR, RAID_CLASS_COLORS = _G['WEAPON'], _G['ARMOR'], RAID_CLASS_COLORS
local CreateFrame, GetDetailedItemLevelInfo = CreateFrame, C_Item.GetDetailedItemLevelInfo
-- Fix for clients with other languages
local AUCTION_CATEGORY_ARMOR = _G['AUCTION_CATEGORY_ARMOR']
local CanIMogIt = _G['CanIMogIt'] or false
local L = AddOn.L
-- local LibItemLevel = LibStub("LibItemLevel")
local LibInspect = LibStub("LibInspect")
LibInspect:SetRescan(14)
local _, playerClass, playerClassId = UnitClass("player")
local icon = LibStub("LibDBIcon-1.0")
local LDB = LibStub("LibDataBroker-1.1"):NewDataObject("DoYouNeedThat", {
type = "data source",
text = "DoYouNeedThat",
icon = "Interface\\Icons\\inv_misc_bag_17",
OnClick = function(_, buttonPressed)
if buttonPressed == "RightButton" then
if (Settings ~= nil) and AddOn.categoryID then
Settings.OpenToCategory(AddOn.categoryID)
end
else
AddOn:ToggleWindow()
end
end,
OnTooltipShow = function(tooltip)
if not tooltip or not tooltip.AddLine then return end
tooltip:AddLine("DoYouNeedThat")
tooltip:AddLine(L["MINIMAP_ICON_TOOLTIP1"])
tooltip:AddLine(L["MINIMAP_ICON_TOOLTIP2"])
end,
})
AddOn.EventFrame = CreateFrame("Frame", nil, UIParent)
AddOn.db = {}
AddOn.Entries = {}
AddOn.RaidMembers = {}
AddOn.Config = {}
AddOn.inspectCount = 1
AddOn.instanceType = 'none'
AddOn.eventsLoaded = false
local ilvlchange = nil
function AddOn.Print(msg)
print("[|cff3399FFDYNT|r] " .. msg)
end
function AddOn.Debug(msg)
if AddOn.Config.debug then AddOn.Print(msg) end
end
function AddOn:checkInGroupOrRaid()
return (IsInGroup() or IsInRaid()) and true or false
end
function AddOn:kirriGetLinkDebug(message)
local LOOT_ITEM_PATTERN = _G['LOOT_ITEM_SELF']:gsub("%%s", "(.+)")
local link = message:match(LOOT_ITEM_PATTERN)
if not link then
return
end
return link
end
function AddOn:getItemLinkFromChat(message)
self.Debug("getItemLinkFromChat")
local LOOT_ITEM_PATTERN = _G['LOOT_ITEM']:gsub("%%s", "(.+)")
local LOOT_ITEM_PUSHED_PATTERN = _G['LOOT_ITEM_PUSHED']:gsub("%%s", "(.+)")
local LOOT_ITEM_MULTIPLE_PATTERN = _G['LOOT_ITEM_MULTIPLE']:gsub("%%s", "(.+)")
local LOOT_ITEM_PUSHED_MULTIPLE_PATTERN = _G['LOOT_ITEM_PUSHED_MULTIPLE']:gsub("%%s", "(.+)")
local _, link = message:match(LOOT_ITEM_MULTIPLE_PATTERN)
if not link then
_, link = message:match(LOOT_ITEM_PUSHED_MULTIPLE_PATTERN)
if not link then
_, link = message:match(LOOT_ITEM_PATTERN)
if not link then
_, link = message:match(LOOT_ITEM_PUSHED_PATTERN)
if not link then
return
end
end
end
end
return link
end
function AddOn:getItemID(itemLink)
return tonumber(itemLink:match("item:(%d+)"))
end
function AddOn:getPetID(itemLink)
return tonumber(itemLink:match("battlepet:(%d+)"))
end
-- Events: CHAT_MSG_LOOT, BOSS_KILL
function AddOn:CHAT_MSG_LOOT(...)
self.Debug("CHAT_MSG_LOOT")
local message, _, _, _, looter = ...
local messageItemLink = self:getItemLinkFromChat(message)
if not messageItemLink then
self.Debug("getItemLinkFromChat: false")
return
end
-- Check to see if it's a pet cage
if string.find(messageItemLink, "battlepet:") then
return AddOn:checkOther(messageItemLink, looter)
end
local item = Item:CreateFromItemLink(messageItemLink)
item:ContinueOnItemLoad(function()
local itemLink = item:GetItemLink()
local itemLevel = item:GetCurrentItemLevel()
local _, _, rarity, _, _, type, _, _, equipLoc, _, _, itemClass, itemSubClass = GetItemInfo(itemLink)
-- If not Armor/Weapon
if (type ~= ARMOR and type ~= AUCTION_CATEGORY_ARMOR and type ~= WEAPON) then
self.Debug("Armor/Weapon: false")
return AddOn:checkOther(itemLink, looter)
end
ilvlchange = nil
local check, mog = self:checkAddItem(itemLink, rarity, equipLoc, itemClass, itemSubClass, itemLevel)
if not check then
self.Debug("checkAddItem: false")
return
end
AddOn:addItem(itemLink, looter, itemLevel, mog)
end)
end
--[[
Checks if the item is a mount, toy, or pet, and adds it to the loot table if the player knows it.
@param itemLink string: The item link to check.
@param looter string: The name of the looter.
@return void
]]
function AddOn:checkOther(itemLink, looter)
self.Debug("checkOther")
-- Check if the item is a mount and if the player knows it
if self.db.config.checkMounts and AddOn:isItemMount(itemLink) then
self.Debug("isItemMount: true")
if not AddOn:playerKnowsMount(itemLink) then
self.Debug("playerKnowsMount: false")
-- Add the item to the loot table with a specific level for mounts
return AddOn:addItem(itemLink, looter, 9999, '')
end
self.Debug("playerKnowsMount: true")
return
end
-- Check if the item is a toy and if the player knows it
if self.db.config.checkToys and AddOn:isItemToy(itemLink) then
self.Debug("isItemToy: true")
if not AddOn:playerKnowsToy(itemLink) then
self.Debug("playerKnowsToy: false")
-- Add the item to the loot table with a specific level for toys
return AddOn:addItem(itemLink, looter, 8888, '')
end
self.Debug("playerKnowsToy: true")
return
end
-- Check if the item is a pet and if the player knows it
if self.db.config.checkPets and AddOn:isItemPet(itemLink) then
self.Debug("isItemPet: true")
if not AddOn:playerKnowsPet(itemLink) then
self.Debug("playerKnowsPet: false")
-- Add the item to the loot table with a specific level for pets
return AddOn:addItem(itemLink, looter, 7777, '')
end
self.Debug("playerKnowsPet: true")
return
end
-- Check if the item is a cosmetics and if the player knows it
if CanIMogIt and AddOn:isCosmetic(itemLink) then
self.Debug("isCosmetic: true")
if not CanIMogIt:PlayerKnowsTransmog(itemLink) then
self.Debug("playerKnowsCosmetic: false")
-- Add the item to the loot table with a specific level for cosmetics
return AddOn:addItem(itemLink, looter, 6666, '')
end
self.Debug("playerKnowsCosmetic: true")
return
end
end
--[[
Adds an item to the loot table
@param itemLink string: The item link to add
@param looter string: The name of the looter
@param itemLevel number: The level of the item
@param mog string: The mog icon
@return void
--]]
function AddOn:addItem(itemLink, looter, itemLevel, mog)
self.Debug("addItem")
-- If the looter is a player and not a player-server pair, add the server
if not sfind(looter, '-') then
looter = self.Utils.GetUnitNameWithRealm(looter)
end
-- Create a table with the item data
local t = { itemLink, looter, itemLevel, mog }
-- Add the item to the loot table
self:AddItemToLootTable(t)
end
--[[
Checks if an item is a mount or not
@param itemLink string: The item link to check
@return boolean: True if the item is a mount, false otherwise
--]]
function AddOn:isItemMount(itemLink)
-- Retrieve the item ID from the item link
local itemID = AddOn:getItemID(itemLink)
-- Return false if the item ID could not be determined
if itemID == nil then
return false
end
-- Use the Mount Journal API to check if the item is a mount
if C_MountJournal.GetMountFromItem(itemID) then
return true
end
-- Return false if the item is not a mount
return false
end
--[[
Determines if the player knows the mount associated with the given item ID.
@param itemLink string: The item link to check
@return boolean: True if the player knows the mount, false otherwise.
]]
function AddOn:playerKnowsMount(itemLink)
-- Retrieve the item ID from the item link
local itemID = AddOn:getItemID(itemLink)
-- Return false if the item ID could not be determined
if itemID == nil then
return false
end
-- Get the mount ID from the item ID using the Mount Journal API
local mountID = C_MountJournal.GetMountFromItem(itemID)
-- If no mount ID is found, the player does not know the mount
if mountID == nil then
return false
end
-- Retrieve mount information using the mount ID and check if it's known by the player
return select(11, C_MountJournal.GetMountInfoByID(mountID))
end
--[[
Checks if an item is a toy or not
@param itemLink string: The item link to check
@return boolean: True if the item is a toy, false otherwise
--]]
function AddOn:isItemToy(itemLink)
-- Retrieve the item ID from the item link
local itemID = AddOn:getItemID(itemLink)
-- Return false if the item ID could not be determined
if itemID == nil then
return false
end
-- Check if the item is a toy using the Toy Box API
if C_ToyBox.GetToyInfo(itemID) then
return true
end
-- If no toy info is found, the item is not a toy
return false
end
--[[
Determines if the player knows the toy associated with the given item ID.
@param itemLink string: The item link to check.
@return boolean: True if the player knows the toy, false otherwise.
--]]
function AddOn:playerKnowsToy(itemLink)
-- Retrieve the item ID from the item link
local itemID = AddOn:getItemID(itemLink)
-- Return false if the item ID could not be determined
if itemID == nil then
return false
end
-- Use the PlayerHasToy API to check if the player knows the toy
return PlayerHasToy(itemID)
end
--[[
Checks if an item is a pet or not
@param itemLink string: The item link to check.
@return boolean: True if the item is a pet, false otherwise
--]]
function AddOn:isItemPet(itemLink)
-- Retrieve the item ID from the item link
local itemID = AddOn:getItemID(itemLink)
-- If itemID is not provided, check if the itemLink is a pet cage
if itemID == nil then
-- Check to see if it's a pet cage
if string.find(itemLink, "battlepet:") then
return true
end
-- If it's not a pet cage, it's not a pet
return false
end
-- If itemID is provided, check if the item is a pet using the Pet Journal API
if C_PetJournal.GetPetInfoByItemID(itemID) then
return true
end
-- If we reach this point, the item is not a pet
return false
end
--[[
Determines if the player knows the pet associated with the given item ID or item link.
@param itemLink string: The item link to check.
@return boolean: True if the player knows the pet, false otherwise.
]]
function AddOn:playerKnowsPet(itemLink)
local speciesID = nil
-- Retrieve the item ID from the item link
local itemID = AddOn:getItemID(itemLink)
if itemID ~= nil then
-- Get species ID from the item ID using the Pet Journal API
speciesID = select(13, C_PetJournal.GetPetInfoByItemID(itemID))
else
-- Extract species ID from the item link if item ID is not provided
_, _, speciesID = string.find(itemLink, "battlepet:(%d+)")
if speciesID ~= nil then
speciesID = tonumber(speciesID)
end
end
-- Return false if speciesID could not be determined
if speciesID == nil then
return false
end
-- Check if the pet is collected by the player
return C_PetJournal.GetNumCollectedInfo(speciesID) > 0
end
--[[
Determines if the given item link is cosmetic.
@param itemLink string: The item link to check.
@return boolean: True if the item is cosmetic, false otherwise.
]]
function AddOn:isCosmetic(itemLink)
-- Retrieve the item subclass using the item link
local itemSubClass = select(3, C_Item.GetItemInfoInstant(itemLink))
if itemSubClass == nil then
-- If the subclass could not be determined, return false
return false
end
-- Check if the item subclass is cosmetic
return select(1, C_Item.GetItemSubClassInfo(4, 5)) == itemSubClass
end
--[[
Checks if an item is transmogable or upgrade currently equipped.
@param itemLink string: The item link to check.
@param rarity number: The rarity of the item.
@param equipLoc string: The equip location of the item.
@param itemClass number: The class of the item.
@param itemSubClass number: The subclass of the item.
@param iLvl number: The item level of the item.
@return boolean: True if the item is transmogable and the player does not know the transmog, but another character knows it.
@return string: The icon to use for the item.
--]]
function AddOn:checkAddItem(itemLink, rarity, equipLoc, itemClass, itemSubClass, iLvl)
-- Check if the item is warbound
if self:checkIsWarboundItem(itemLink) then
self.Debug("checkIsWarboundItem: true")
return false, ''
end
-- Check if the item is transmogable
local checkmog, mog = self:checkAddItemTransmog(itemLink)
if checkmog then
self.Debug("checkAddItemTransmog: true")
return true, mog
end
-- Check if the item is equippable
if not IsEquippableItem(itemLink) then
self.Debug("IsEquippableItem: false")
return false, mog
end
-- If its a Legendary or under rare quality, do not add it
if rarity == 5 or rarity < 3 then
self.Debug("rarity == 5 or rarity < 3: false")
return false, mog
end
-- If not equippable by your class return
if not self:IsEquippableForClass(itemClass, itemSubClass, equipLoc) then
self.Debug("IsEquippableForClass: false")
return false, mog
end
-- Should get rid of class specific pieces that you cannnot equip.
if not C_Item.DoesItemContainSpec(itemLink, playerClassId) then
self.Debug("DoesItemContainSpec: false")
return false, mog
end
-- Check if the item is an upgrade
if not self:IsItemUpgrade(iLvl, equipLoc) then
self.Debug("IsItemUpgrade: false")
return false, mog
end
self.Debug("IsItemUpgrade: true")
return true, mog
end
--[[
Checks if an item is transmogable and returns its status.
If the CanIMogIt library is outdated, it will return false and a not transmogable icon.
If the item is not transmogable, it will return false and a not transmogable icon.
If the player knows the transmog, it will return false and a known icon.
If the player does not know the transmog, but another character knows it, it will return true and a known circle icon
if the user has enabled the option to check the source of the transmog.
If the player does not know the transmog and no other character knows it, it will return true and an unknown icon.
@param itemLink string: The link to the item to be checked.
@return boolean: Whether the item is transmogable.
@return string: The icon to be used to represent the state of the item.
--]]
function AddOn:checkAddItemTransmog(itemLink)
local mog = '|TInterface\\AddOns\\CanIMogIt\\Icons\\not_transmogable:0|t'
-- Check if the user has enabled the option to check if the item is transmogable
if not self.db.config.checkTransmogable then
self.Debug("checkTransmogable: false")
return false, mog
end
-- Check if the CanIMogIt library is outdated
local isTransmogable, isKnown, isOtherKnown, isOutdated = self:CanIMogItCheckItem(itemLink)
if isOutdated then
self.Debug("CanIMogIt - isOutdated: true")
return false, mog
end
-- Check if the item is transmogable
if not isTransmogable then
self.Debug("CanIMogIt - isTransmogable: false")
return false, mog
end
-- Check if the player knows the transmog
if isKnown then
mog = '|TInterface\\AddOns\\CanIMogIt\\Icons\\known:0|t'
self.Debug("CanIMogIt - isKnown: true")
return false, mog
end
-- Check if another character knows the transmog
if isOtherKnown then
mog = '|TInterface\\AddOns\\CanIMogIt\\Icons\\known_circle:0|t'
-- Check if the user has enabled the option to check the source of the transmog
if self.db.config.checkTransmogableSource then
self.Debug("CanIMogIt - isOtherKnown and checkTransmogableSource: true")
return true, mog
end
self.Debug("CanIMogIt - isOtherKnown: true")
return false, mog
end
-- If the player does not know the transmog and no other character knows it
mog = '|TInterface\\AddOns\\CanIMogIt\\Icons\\unknown:0|t'
return true, mog
end
--[[
BOSS_KILL event handler. This function is called when a boss is killed and the event is fired.
It checks if the player is in a group and if the encounter was not a Mythic Keystone (M+)
If the conditions are met, it clears the entries and shows the loot frame, if the user has enabled
the option to open the frame after an encounter.
@see https://wowpedia.fandom.com/wiki/DifficultyID
@see https://wowpedia.fandom.com/wiki/BOSS_KILL
@param encounterID number: The encounter ID of the boss that was killed.
@param encounterName string: The name of the boss that was killed.
@return void
--]]
function AddOn:BOSS_KILL(encounterID, encounterName)
self.Debug("BOSS_KILL")
self.Debug("encounterID:" .. encounterID)
self.Debug("encounterName:" .. encounterName)
-- Dont open frame when you dont in group
if not self:checkInGroupOrRaid() then
self.Debug("checkInGroupOrRaid: false")
return
end
-- Clear all entries in the loot table
self:ClearEntries()
end
--[[
CHALLENGE_MODE_COMPLETED event handler. This function is called when the player completes a Mythic+ dungeon.
It checks if the player is in a group and if the encounter was not a Mythic Keystone (M+)
If the conditions are met, it clears the entries and shows the loot frame, if the user has enabled
the option to open the frame after an encounter.
@see https://wowpedia.fandom.com/wiki/CHALLENGE_MODE_COMPLETED
@return void
--]]
function AddOn:CHALLENGE_MODE_COMPLETED()
self.Debug("CHALLENGE_MODE_COMPLETED")
-- Dont open frame when you dont in group
if not self:checkInGroupOrRaid() then
self.Debug("checkInGroupOrRaid: false")
return
end
-- Clear all entries in the loot table
self:ClearEntries()
end
--[[
Handles the PLAYER_ENTERING_WORLD event. This function is triggered when the player enters the world,
either by logging in, reloading the UI, or changing zones.
It determines the type of instance the player is in and decides whether to register or unregister events
based on the configuration settings and instance type.
@return void
--]]
function AddOn:PLAYER_ENTERING_WORLD()
-- Retrieve the current instance type
local _, instanceType = GetInstanceInfo()
-- Store the instance type in the AddOn object
AddOn.instanceType = instanceType
-- Log the instance type for debugging purposes
self.Debug("PLAYER_ENTERING_WORLD - instanceType: " .. AddOn.instanceType)
-- Register events if the loot frame should be shown everywhere or if the player is in an instance
if self.db.config.chatShowLootFrame == "everywhere" or AddOn.instanceType ~= "none" then
AddOn:registerEvents()
return
end
-- Unregister events if the conditions above are not met
AddOn:unregisterEvents()
end
--[[
Registers the necessary events for the AddOn and sets up a repeated timer to inspect group members.
This function ensures that events are only registered once and starts a timer for periodic inspection.
@return void
--]]
function AddOn:registerEvents()
self.Debug("registerEvents")
-- Check if events are already loaded to avoid duplicate registration
if AddOn.eventsLoaded then
return
end
-- Register events for loot messages, boss kills, and challenge mode completion
self.EventFrame:RegisterEvent("CHAT_MSG_LOOT")
self.EventFrame:RegisterEvent("BOSS_KILL")
self.EventFrame:RegisterEvent("CHALLENGE_MODE_COMPLETED")
-- Set a repeated timer every 7 seconds to check the inventory of raid members
self.InspectTimer = C_Timer.NewTicker(7, function() self.InspectGroup() end)
-- Mark events as loaded to prevent re-registration
AddOn.eventsLoaded = true
end
--[[
Unregisters the events for the AddOn and cancels the repeated timer for inspection.
This function is the counterpart to registerEvents() and is called when the player is no longer
in a group or raid. It ensures that events are not registered multiple times and stops the timer
for periodic inspection to prevent excessive CPU usage.
@return void
--]]
function AddOn:unregisterEvents()
self.Debug("unregisterEvents")
-- Check if events are already unloaded to avoid duplicate unregistration
if not AddOn.eventsLoaded then
return
end
-- Unregister events for loot messages, boss kills, and challenge mode completion
self.EventFrame:UnregisterEvent("CHAT_MSG_LOOT")
self.EventFrame:UnregisterEvent("BOSS_KILL")
self.EventFrame:UnregisterEvent("CHALLENGE_MODE_COMPLETED")
-- Cancel the repeated timer for inspection
if self.InspectTimer then
self.InspectTimer:Cancel()
self.InspectTimer = nil
end
-- Mark events as unloaded to prevent re-registration
AddOn.eventsLoaded = false
end
function AddOn:ADDON_LOADED(addon)
if not addon == AddonName then return end
self.EventFrame:UnregisterEvent("ADDON_LOADED")
-- Set SavedVariables defaults
if DyntDB == nil then
DyntDB = {
lootWindow = { "CENTER", 0, 0 },
lootWindowOpen = false,
config = {
whisperMessage = L["Default Whisper Message"],
openAfterEncounter = true,
debug = false,
checkTransmogable = true,
checkTransmogableSource = true,
checkMounts = true,
checkToys = true,
checkPets = true,
chatShowLootFrame = 'disabled',
minDelta = 0,
checkCustomTexts = false,
hideWarboundItems = false,
showIlvlDiffrent = false,
customTexts = {},
},
minimap = {
hide = false
}
}
end
self.db = DyntDB
self.db.lootWindowOpen = false
-- Set minDelta default if its not a fresh install
if not self.db.config.minDelta then
self.db.config.minDelta = 0
end
-- Set chatShowLootFrameEverywhere default if its not a fresh install
if not self.db.config.chatShowLootFrame then
self.db.config.chatShowLootFrame = 'disabled'
end
-- Set checkMounts default if its not a fresh install
if not self.db.config.checkMounts then
self.db.config.checkMounts = false
end
-- Set checkToys default if its not a fresh install
if not self.db.config.checkToys then
self.db.config.checkToys = false
end
-- Set checkPets default if its not a fresh install
if not self.db.config.checkPets then
self.db.config.checkPets = false
end
-- Set hideWarboundItems default if its not a fresh install
if not self.db.config.hideWarboundItems then
self.db.config.hideWarboundItems = false
end
-- Set showIlvlDiffrent default if its not a fresh install
if not self.db.config.showIlvlDiffrent then
self.db.config.showIlvlDiffrent = false
end
-- Set checkCustomTexts default if its not a fresh install
if not self.db.config.checkCustomTexts then
self.db.config.checkCustomTexts = false
end
-- Set customTexts default if its not a fresh install
if not self.db.config.customTexts or not next(self.db.config.customTexts) then
self.db.config.customTexts = {
[1] = L["CUSTOM_TEXT"]
}
end
self.createLootFrame()
-- Set window position
self.lootFrame:SetPoint(self.db.lootWindow[1], self.db.lootWindow[2], self.db.lootWindow[3])
-- Replace config with saved one
self.Config = self.db.config
icon:Register("DoYouNeedThat", LDB, self.db.minimap)
if not self.db.minimap.hide then
icon:Show("DoYouNeedThat")
end
self.createOptionsFrame()
end
function AddOn:recreateLootFrame()
self.lootFrame:Hide()
AddOn:ClearEntries()
self.lootFrame:SetParent(nil)
self.lootFrame:ClearAllPoints()
self.lootFrame:UnregisterAllEvents()
self.lootFrame:SetID(0)
self.createLootFrame()
-- Set window position
self.lootFrame:SetPoint(self.db.lootWindow[1], self.db.lootWindow[2], self.db.lootWindow[3])
-- Reopen window if left opened on uireload/exit
if self.db.lootWindowOpen then self.lootFrame:Show() end
end
local function GetEquippedIlvlBySlotID(slotID)
local item = GetInventoryItemLink('player', slotID)
return item and GetDetailedItemLevelInfo(item) or 0
end
function AddOn:IsItemUpgrade(ilvl, equipLoc)
local function overOrWithinMin(eqilvl, eq, delta)
return eqilvl >= eq + delta
end
if ilvl ~= nil and equipLoc ~= nil and equipLoc ~= '' then
local delta = self.Config.minDelta
-- Evaluate item. If ilvl > your current ilvl
if equipLoc == 'INVTYPE_FINGER' then
local eqIlvl1 = GetEquippedIlvlBySlotID(11)
local eqIlvl2 = GetEquippedIlvlBySlotID(12)
if eqIlvl1 then
ilvlchange = ilvl - eqIlvl1
end
if eqIlvl2 and (not ilvlchange or (ilvl - eqIlvl2) > ilvlchange) then
ilvlchange = ilvl - eqIlvl2
end
return overOrWithinMin(ilvl, eqIlvl1, delta) or overOrWithinMin(ilvl, eqIlvl2, delta)
elseif equipLoc == 'INVTYPE_TRINKET' then
local eqIlvl1 = GetEquippedIlvlBySlotID(13)
local eqIlvl2 = GetEquippedIlvlBySlotID(14)
if eqIlvl1 then
ilvlchange = ilvl - eqIlvl1
end
if eqIlvl2 and (not ilvlchange or (ilvl - eqIlvl2) > ilvlchange) then
ilvlchange = ilvl - eqIlvl2
end
return overOrWithinMin(ilvl, eqIlvl1, delta) or overOrWithinMin(ilvl, eqIlvl2, delta)
elseif equipLoc == 'INVTYPE_WEAPON' or equipLoc == 'INVTYPE_HOLDABLE' or equipLoc == 'INVTYPE_WEAPONOFFHAND' or equipLoc == 'INVTYPE_SHIELD' then
local eqIlvl1 = GetEquippedIlvlBySlotID(16)
local eqIlvl2 = GetEquippedIlvlBySlotID(17)
if eqIlvl1 then
ilvlchange = ilvl - eqIlvl1
end
if eqIlvl2 and (not ilvlchange or (ilvl - eqIlvl2) > ilvlchange) then
ilvlchange = ilvl - eqIlvl2
end
return overOrWithinMin(ilvl, eqIlvl1, delta) or overOrWithinMin(ilvl, eqIlvl2, delta)
else
local slotID = AddOn.Utils.GetSlotID(equipLoc)
local eqIlvl = GetEquippedIlvlBySlotID(slotID)
if eqIlvl then
ilvlchange = ilvl - eqIlvl
end
return overOrWithinMin(ilvl, eqIlvl, delta)
end
end
return false
end
function AddOn:IsEquippableForClass(itemClass, itemSubClass, equipLoc)
-- Can be equipped by all, return true without checking
if equipLoc == 'INVTYPE_CLOAK' or equipLoc == 'INVTYPE_FINGER' or equipLoc == 'INVTYPE_TRINKET' or equipLoc == 'INVTYPE_NECK' or equipLoc == 'INVTYPE_WEAPON' or itemSubClass == 0 then return true end
local classGear = self.Utils.ValidGear[playerClass]
-- Loop through equippable item classes, if a match is found return true
for i = 1, #classGear[itemClass] do
if itemSubClass == classGear[itemClass][i] then return true end
end
return false
end
function AddOn:ClearEntries()
for i = 1, #self.Entries do
if self.Entries[i].itemLink then
self.Entries[i]:Hide()
self.Entries[i].itemLink = nil
self.Entries[i].looter = nil
self.Entries[i].guid = nil
self.Entries[i].itemID = nil
self.Entries[i].ilvl:SetText("0")
self.Entries[i].ilvl2:SetText("0")
self.Entries[i].itemLink = nil
self.Entries[i].looter = nil
self.Entries[i].ilvlchange = nil
if self.Entries[i].customTextMenu then
self.Entries[i].customTextMenu:Hide()
self.Entries[i].customTextButton:Hide()
end
end
end
end
function AddOn:GetEntry(itemLink, looter)
for i = 1, #self.Entries do
-- If it already exists
if self.Entries[i].itemLink == itemLink and self.Entries[i].looter == looter then
return self.Entries[i]
end
-- Otherwise return a new one
if not self.Entries[i].itemLink then
return self.Entries[i]
end
end
end
function AddOn:AddItemToLootTable(t)
-- Itemlink, Looter, Ilvl
self.Debug("Adding item to entries")
AddOn:ShowLootFrameFromChat()
local entry = self:GetEntry(t[1], t[2])
local _, _, _, equipLoc = GetItemInfoInstant(t[1])
local character = t[2]:match("(.*)%-") or t[2]
local classColor = RAID_CLASS_COLORS[select(2, UnitClass(character))]
entry.itemLink = t[1]
entry.looter = t[2]
entry.ilvlchange = ilvlchange
entry.guid = UnitGUID(character)
-- print('ilvl', ilvl, 'equipLoc', equipLoc)
self.Debug("equipLoc: " .. equipLoc)
-- If looter has been inspected, show their equipped items in those slots
if self.RaidMembers[entry.guid] then
local raidMember = self.RaidMembers[entry.guid]
local item, item2 = nil, nil
if equipLoc == "INVTYPE_FINGER" then
item, item2 = raidMember.items[11] or nil, raidMember.items[12] or nil
elseif equipLoc == "INVTYPE_TRINKET" then
item, item2 = raidMember.items[13] or nil, raidMember.items[14] or nil
elseif equipLoc == 'INVTYPE_WEAPON' or equipLoc == 'INVTYPE_HOLDABLE' or equipLoc == 'INVTYPE_WEAPONOFFHAND' or equipLoc == 'INVTYPE_SHIELD' then
item, item2 = raidMember.items[16] or nil, raidMember.items[17] or nil
else
entry.looterEq2:Hide()
local slotId = self.Utils.GetSlotID(equipLoc)
item = raidMember.items[slotId] or nil
end
if item ~= nil then self.setItemTooltip(entry.looterEq1, item) end
if item2 ~= nil then self.setItemTooltip(entry.looterEq2, item2) end
end
entry.name:SetText(character)
entry.name:SetTextColor(classColor.r, classColor.g, classColor.b)
self.setItemTooltip(entry.item, t[1])
entry.ilvl:SetText(t[3])
entry.itemID = self:getItemID(t[1])
if self.db.config.checkTransmogable and CanIMogIt then
entry.mog:SetText(t[4])
end
self:repositionFrames()
entry.whisper:Show()
if AddOn.db.config.checkCustomTexts and next(AddOn.db.config.customTexts) then
entry.customTextButton:Show()
end
entry:Show()
end
function AddOn:ShowLootFrameFromChat()
self.Debug("ShowLootFrame")
-- check is opened
if self.db.lootWindowOpen or self.db.config.chatShowLootFrame == "disabled" then
return
end
if not self:checkInGroupOrRaid() then
self.Debug("checkInGroupOrRaid: false")
return
end
if self.db.config.chatShowLootFrame == "everywhere" then
self.lootFrame:Show()
self.db.lootWindowOpen = true
return
end
self.Debug("ShowLootFrameFromChat - instanceType: " .. AddOn.instanceType)
if AddOn.instanceType ~= "none" then
self.lootFrame:Show()
self.db.lootWindowOpen = true