-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathCore.lua
More file actions
1888 lines (1798 loc) · 72.7 KB
/
Copy pathCore.lua
File metadata and controls
1888 lines (1798 loc) · 72.7 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
-- lua functions
local select, setmetatable, error, type, rawget, rawset, pairs, tonumber, strsplit, tContains, unpack, tostring, wipe, tinsert, tsort, tconcat, tremove
= select, setmetatable, error, type, rawget, rawset, pairs, tonumber, strsplit, tContains, unpack, tostring, wipe, table.insert, table.sort, table.concat, table.remove
-- WoW API
local GetNumSpecializations, GetSpecializationInfo, GetItemInfo, IsEquippedItem, GetContainerNumSlots, GetContainerItemID, UnitClass, GetInventorySlotInfo, GetNumGuildMembers, ConvertRGBtoColorString, GetInventoryItemLink, GetContainerItemInfo, GetAddOnMetadata, GetItemSpecInfo, GetItemUniqueness, IsInGuild, GetGuildInfo, GetSpecialization, GetSpecializationInfoByID, IsInRaid, UnitName, IsInGroup, GetGuildRosterInfo, UnitFullName, UnitRace, UnitSex
= GetNumSpecializations, GetSpecializationInfo, GetItemInfo, IsEquippedItem, GetContainerNumSlots, GetContainerItemID, UnitClass, GetInventorySlotInfo, GetNumGuildMembers, ConvertRGBtoColorString, GetInventoryItemLink, GetContainerItemInfo, GetAddOnMetadata, GetItemSpecInfo, GetItemUniqueness, IsInGuild, GetGuildInfo, GetSpecialization, GetSpecializationInfoByID, IsInRaid, UnitName, IsInGroup, GetGuildRosterInfo, UnitFullName, UnitRace, UnitSex
local E = select(2, ...)
local BestInSlot = LibStub("AceAddon-3.0"):NewAddon("BestInSlotRedux", "AceComm-3.0", "AceHook-3.0", "AceSerializer-3.0", "AceTimer-3.0")
local AceGUI = LibStub("AceGUI-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("BestInSlotRedux")
local AceEvent = LibStub("AceEvent-3.0")
E[1] = BestInSlot
E[2] = L
E[3] = AceGUI
BestInSlot.unsafeIDs = {}
BestInSlot.options = {}
BestInSlot.defaultModuleState = false
BestInSlot.options.DEBUG = false
-- Authors
BestInSlot.Author1 = ("%s%s @ %s"):format("|c"..RAID_CLASS_COLORS.DEMONHUNTER.colorStr, "Beleria".."|r",ConvertRGBtoColorString(PLAYER_FACTION_COLORS[1]).."Argent Dawn-EU|r")
BestInSlot.Author2 = ("%s%s @ %s"):format("|c"..RAID_CLASS_COLORS.PALADIN.colorStr, "Anhility".."|r",ConvertRGBtoColorString(PLAYER_FACTION_COLORS[1]).."Ravencrest-EU|r")
BestInSlot.Author3 = ("%s%s @ %s"):format("|c"..RAID_CLASS_COLORS.ROGUE.colorStr, "Sar\195\173th".."|r",ConvertRGBtoColorString(PLAYER_FACTION_COLORS[1]).."Tarren Mill-EU|r")
--[===[@non-debug@
BestInSlot.version = @project-date-integer@
--@end-non-debug@]===]
BestInSlot.AlphaVersion = not (GetAddOnMetadata("BestInSlotRedux", "Version"):find("Release") and true or false)
--@do-not-package@
BestInSlot.version = 1337
BestInSlot.options.DEBUG = true
--@end-do-not-package@
local slashCommands = {}
local defaults = {
char = {
['*'] = { --raidTier
['*'] = { --raidDifficulty
['*'] = { --listType (spec as number, customList as string)
['*'] = nil
}
},
},
latestVersion = 1,
selected = {},
windowpos = {},
customlists = {},
tutorials = {},
options = {
windowFixed = false,
showBiSTooltip = true,
sendAutomaticUpdates = true,
receiveAutomaticUpdates = true,
minimapButton = true,
guildtooltip = true,
showBossTooltip = true,
keepHistory = false,
tooltipCombat = false,
historyLength = "30d",
historyAutoDelete = true,
tooltipSource = true,
statsInManager = true,
showGuildRankInTooltip = {
['*'] = true
},
overviewfilter = {},
},
},
global = {
options = {
instantAnimation = false,
},
customitems = {
},
tutorials = true,
},
factionrealm = {
_history = {
['*'] = {}, --players database
},
['*'] = { --guildname
['*'] = { -- charactername
['*'] = { -- raidTier
['*'] = { -- difficulty
}
}
}
}
},
profile = {
minimap = {
hide = false,
}
},
}
---
--Datatypes to be used with some of BestInSlots functions
---
BestInSlot.EXPANSION = 1
BestInSlot.RAIDTIER = 2
BestInSlot.INSTANCE = 3
BestInSlot.BOSS = 4
BestInSlot.DIFFICULTY = 5
BestInSlot.SPECIALIZATION = 6
BestInSlot.MSGPREFIX = "BiS"
---
--Color codes used by the add-on
---
BestInSlot.colorHighlight = RED_FONT_COLOR_CODE
BestInSlot.colorNormal = NORMAL_FONT_COLOR_CODE
---
--data = {
-- raidTiers = {
-- [raidTierId] = {
-- description = "Raid Tier Description",
-- difficulties = {"difficultyName1", "difficultyName2"},
-- expansion = expansionId,
-- instances = {},
-- tierTokens = {},
-- tierItems = {
-- [Class1] = {
-- [difficultyName1] = {
-- tierItemId1,
-- tierItemId2,
-- tierItemId3,
-- },
-- [difficultyName2] = {
-- tierItemId1,
-- tierItemId2,
-- tierItemId3,
-- },
-- }
-- }
-- }
-- },
-- instances = {
-- [instanceId] = {
-- raidTier = raidTierID,
-- expansion = expansionId,
-- description = "Description
-- }
-- },
-- expansions = {
-- [expansionId] = {
-- raidTiers = {},
-- instances = {},
-- description = "Description",
-- }
-- }
--}
---
local data = {
raidTiers = {},
instances = {__default={
difficultyconversion = {
[1] = 1, --Dungeon Normal
[2] = 2, --Dungeon Heroic
[3] = 23, --Dungeon Mythic
},
bonusids = {
[1] = {3524},
[2] = {3524},
[3] = {3524}
},
}},
expansions = {},
bosses = {},
tiertokens = {},
}
---
--itemData = {
-- [instanceName]={
-- [bossId] = {
-- [itemid] = {
-- dungeon = "dungeon",
-- link = "link",
-- isBiS = {
-- [difficulty] = {
-- [specId] = true
-- }
-- }
-- [difficulty] = ..
-- equipSlot = "INVTYPE_[SLOT]"
-- }
-- }
-- }
--}
--
--itemData's metatable can accept itemids. When it is requested an itemid it'll look in nested tables to find the item in question
---
local itemDataCache = {}
local itemData = setmetatable({},{
__index = function(tbl, key)
local value = itemDataCache[key]
if value then return value end
for dungeon,dungeonData in pairs(tbl) do --we can do this without error checking because the __newindex metamethod will check if it's a table
for bossId, bossData in pairs(dungeonData) do
if bossData[key] then itemDataCache[key] = bossData[key] return itemDataCache[key] end
end
end
end,
__newindex = function(table, key, value)
if type(value) ~= "table" then error("Can only add tables to the itemData table") end
rawset(table, key, value)
end
})
local tierTokenData = {}
local customItems = {}
BestInSlot.slots = {"HeadSlot", "NeckSlot","ShoulderSlot","BackSlot","ChestSlot","WristSlot","HandsSlot","WaistSlot","LegsSlot","FeetSlot", "Finger0Slot","Finger1Slot","Trinket0Slot","Trinket1Slot", "MainHandSlot","SecondaryHandSlot"}
BestInSlot.invSlots = {
[1] = "INVTYPE_HEAD",
[2] = "INVTYPE_NECK",
[3] = "INVTYPE_SHOULDER",
[4] = "INVTYPE_BODY",
[5] = {"INVTYPE_CHEST", "INVTYPE_ROBE"},
[6] = "INVTYPE_WAIST",
[7] = "INVTYPE_LEGS",
[8] = "INVTYPE_FEET",
[9] = "INVTYPE_WRIST",
[10] = "INVTYPE_HAND",
[11] = "INVTYPE_FINGER",
[12] = "INVTYPE_FINGER",
[13] = "INVTYPE_TRINKET",
[14] = "INVTYPE_TRINKET",
[15] = "INVTYPE_CLOAK",
[16] = {"INVTYPE_WEAPON", "INVTYPE_2HWEAPON", "INVTYPE_WEAPONMAINHAND", "INVTYPE_RANGED", "INVTYPE_RANGEDRIGHT"},
[17] = {"INVTYPE_WEAPONOFFHAND", "INVTYPE_SHIELD", "INVTYPE_WEAPON", "INVTYPE_HOLDABLE"},
--[18] = {"INVTYPE_RANGED", "INVTYPE_THROWN", "INVTYPE_RANGEDRIGHT", "INVTYPE_RELIC"}
}
BestInSlot.dualWield = {250, 251, 252, 268, 269, 259, 260, 261, 263, 71, 72}
------------------------------------------------------------------------------------------------------------------------------------------------
-- MODULE REGISTRATION
------------------------------------------------------------------------------------------------------------------------------------------------
--- This function can be used by modules to add their data to the add-on. It checks if the proper values are set
--@param #string unlocalizedName the Localized Name of the expansion to register
--@param #string localizedDescription The localized description of the expansion to add
function BestInSlot:RegisterExpansion(unlocalizedName, localizedDescription)
if data.expansions[unlocalizedName] then
return
end
data.expansions[unlocalizedName] = {description = localizedDescription, raidTiers = {}, instances = {}}
end
--- Registers a raid tier to BestInSlot
-- @param #string expansion The expansion ID, must have been registered before by using BestInSlot:RegisterExpansion
-- @param #number raidTier The number corresponding with the Raid Tier, must be unique. The standard is to use the patch version the raid tier belongs to (e.g. 50400 for patch 5.4)
-- @param #string description The description of the raid tier. By default 'Patch 5.4'
-- @param #... The next parameters are considered the difficulties you would like to add, can be "Normal", "Heroic", and "Mythic".
function BestInSlot:RegisterRaidTier(expansion, raidTier, description, ...)
local difficulties = {...}
if data.raidTiers[raidTier] then error("This raid tier is already registered!") end
if not data.expansions[expansion] then error("The expansion has not been registered yet!") end
if not description or type(description) ~= "string" then error("The raid tier needs to provide a description!") end
if not difficulties or #difficulties == 0 then error("The raid tier "..description.." needs to provide difficulties!") end
for i = 1,#difficulties do
if type(difficulties[i]) ~= "string" then error("Difficulty parameter not set correctly") end
end
data.raidTiers[raidTier] = {description = description, difficulties = difficulties}
data.raidTiers[raidTier].expansion = expansion
data.raidTiers[raidTier].instances = {}
data.raidTiers[raidTier].module = (raidTier >= 69000) and "PvP" or (raidTier < 60000) and "WoDDungeon" or "WoD"
tinsert(data.expansions[expansion].raidTiers, raidTier)
end
local newInstanceMetatable = {
--[[__index = function(tbl, key)
local value = rawget(tbl, key)
if value then return value end
for k,v in pairs(tbl) do
if v[key] then return v[key] end
end
end,]]
__newindex = function(tbl, key, value)
if type(value) ~= "table" then error("Can only add tables with item info inside instance tables") end
if key == "tieritems" or key == "misc" or key == "customitems" then
rawset(tbl, key, value)
return
end
key = tonumber(key)
if not key then error("Key must be a number!") end
rawset(tbl, key, value)
end
}
local instanceDefaultIndexMetatable = {
__index = function(tbl, key)
return data.instances.__default[key]
end
}
---Register a raid instance to BestInSlot
--@param #number raidTier The raidTier ID as used at BestInSlot:RegisterRaidTier
--@param #string unlocalizedName An unlocalized name of the raid to add, to identify the instance, must be unique!
--@param #string description A localized description of the raid instance to add
--@param #table args Optional arguments to override default values. See data.instances.__default
function BestInSlot:RegisterRaidInstance(raidTier, unlocalizedName, description, args)
if not data.raidTiers[raidTier] then error("The raid tier "..raidTier.." has not been registered yet!") end
local localizedExpansion = data.raidTiers[raidTier].expansion
if not data.expansions[localizedExpansion] then error("The expansion "..localizedExpansion.." has not been registered yet!") end
if not data.raidTiers[raidTier] then error("The raid tier "..raidTier.." has not been registered yet") end
if data.instances[unlocalizedName] then error("This raid instance has already been registered!") end
data.instances[unlocalizedName] = setmetatable({expansion = localizedExpansion, raidTier = raidTier, description = description}, instanceDefaultIndexMetatable)
if args then
for k,v in pairs(args) do
data.instances[unlocalizedName][k] = v
end
end
tinsert(data.expansions[localizedExpansion].instances, unlocalizedName)
tinsert(data.raidTiers[raidTier].instances, unlocalizedName)
itemData[unlocalizedName] = setmetatable({}, newInstanceMetatable)
if self.db.global.customitems[unlocalizedName] then
for itemlink in pairs(self.db.global.customitems[unlocalizedName]) do
self:RegisterCustomItem(unlocalizedName, nil, itemlink) --The second parameter will be extracted out of the itemlink if not supplied
end
end
end
---Register tier items that drop in the supplied raidTier
--@param #number raidTier The raid tier that drops the tier items
--@param #table tierItems A table in the following format: {DEATHKNIGHT = { NORMAL = { normalItem1, normalItem2, ...}, HEROIC = { heroicItem1, heroicItem2},} SHAMAN = {....}} Where the difficulties must correspond with the earlier registered difficulties
function BestInSlot:RegisterTierItems(dungeon, tierItems)
if not data.instances[dungeon] then error("This dungeon is not registered yet") end
local tieritems = {}
for class in pairs(RAID_CLASS_COLORS) do
if not tierItems[class] then error("You are missing class "..class.." in the tier item list.") end
for i=1,#tierItems[class] do
local itemid = tierItems[class][i]
local _, link, _, _, _, _, _, _, equipSlot = GetItemInfo(i)
if not link then self.unsafeIDs[itemid] = true end
tieritems[itemid] = {
bossid = equipSlot and data.tiertokens[dungeon][self:GetItemSlotID(equipSlot)].bossid,
dungeon = dungeon,
difficulty = -1,
link = link,
equipSlot = equipSlot,
isBiS = {},
tieritem = class,
}
end
end
itemData[dungeon].tieritems = tieritems
end
---Register tier tokens, not supported for MoP or lower
function BestInSlot:RegisterTierTokens(raidTier, tierTokens)
if not data.raidTiers[raidTier] then error("This raid tier is not registered yet") end
local raidTierData = data.raidTiers[raidTier]
local difficulties = raidTierData.difficulties
for slotId, tierSlots in pairs(tierTokens) do
for tokenId, tokenClasses in pairs(tierSlots) do
tierTokenData[tokenId] = {classes = tokenClasses, raidtier = raidTier, slotid = slotId}
end
end
end
---Adds the named difficulty to the available difficulty
--@param #number raidtier The Raidtier to append the difficulty to
--@param #string difficulty The name of the difficulty
function BestInSlot:AddDifficultyToRaidTier(raidtier, difficulty)
if not data.raidTiers[raidtier] then error("Raidtier '"..tostring(raidtier).."' does not exist!") end
tinsert(data.raidTiers[raidtier].difficulties, difficulty)
end
--- Register Miscelaneous items
-- @param #number raidTier The Raid tier to add the misc items to
-- @param #table miscItems A table containing the miscelaneous items, should be formatted in the following format: {["Legendary Cloak Quest"] = {idCloak1, idCloak2, ...}, ["Ordos"] = {idOrdos1, idOrdos2, ...}}
-- @param #bool legionLegendary
function BestInSlot:RegisterMiscItems(instance, miscItems, legionLegendary)
if not data.instances[instance] then error("This instance is not registered yet") end
local misc = {}
for miscName,miscLootTable in pairs(miscItems) do
if type(miscName) ~= "string" or type(miscLootTable) ~= "table" then error("Misc table is not formatted properly, should be {key = {itemId1, itemId2}} Where key is a description of the source}") end
for i=1,#miscLootTable do
local itemid = miscLootTable[i]
local itemtable
if type(itemid) == "table" then
itemtable = itemid
itemid = itemtable.id
if not itemid then self.console:AddError("ItemTable didn't provide id", itemid) end
end
local link, equipSlot
if legionLegendary == true then --fix for Legion Legendaries itemlevel
_, link, _, _, _, _, _, _, equipSlot = GetItemInfo(("item:%d::::::::::::1:3630"):format(itemid))
else
_, link, _, _, _, _, _, _, equipSlot = GetItemInfo(("item:%d::::::::::::1:3524"):format(itemid))
end
if not link then self.unsafeIDs[itemid] = true end
misc[itemid] = {
dungeon = instance,
difficulty = miscLootTable.difficulty,
link = link,
equipSlot = equipSlot,
isBiS = {},
misc = miscName,
}
end
end
itemData[instance].misc = misc
end
local bossNewIndexMetatable = {
__newindex = function(tbl, key, value)
if type(value) ~= "table" then BestInSlot.console:AddError("Item info must be a table!", key, value) end
key = tonumber(key)
if not key then BestInSlot.console:AddError("Item info must be a table!", key, value) end
rawset(tbl, key, value)
end
}
--- Register boss loot of an instance. Must call this function in the order you want to put the bosses in
-- @param #string unlocalizedInstanceName The unlocalized name of the instance to add the loot to.
-- @param #table lootTable The table containing the loot for the boss, must be formatted as follows: {["Normal"] = {itemId1, itemId2}, ["Heroic"] = {itemId1, itemId2}}
-- @param #string bossName Localized name of the boss, you can use LibBabbleBoss-3.0 for this.
-- @param #number tierToken If supplied, registers this item as a boss that drops the supplied tiertoken. 1 = HeadSlot, 3 = ShoulderSlot, 5 = ChestSlot, 7 = LegsSlot, 10 = Handslot, 15 = BackSlot.
function BestInSlot:RegisterBossLoot(unlocalizedInstanceName, lootTable, bossName, tierToken, bossId)
local instance = data.instances[unlocalizedInstanceName]
if not instance then error("The instance \""..unlocalizedInstanceName.."\" has not yet been registered!") end
lootTable.info = {name = bossName}
local bossLootTable = bossId and itemData[unlocalizedInstanceName][bossId] or setmetatable({}, bossNewIndexMetatable)
local addToBoss = bossId ~= nil
local bossId = bossId or #itemData[unlocalizedInstanceName] + 1
for i=1,#lootTable do
local itemid = lootTable[i]
local itemtable
if type(itemid) == "table" then
itemtable = itemid
itemid = itemtable.id
if not itemid then self.console:AddError("ItemTable didn't provide id", itemid) end
end
local item = itemData[itemid]
if item and not item.customitem then --The item already existed
if not item.multiplesources then
item.multiplesources = {}
if item.bossid and item.dungeon then
item.multiplesources[item.dungeon] = {}
item.multiplesources[item.dungeon][item.bossid] = true
else
self:Print(item)
self:Print(self.unsafeIDs)
end
end
item.multiplesources[unlocalizedInstanceName] = item.multiplesources[unlocalizedInstanceName] or {}
item.multiplesources[unlocalizedInstanceName][bossId] = true
bossLootTable[itemid] = item
else
if item and item.customitem then
self:Print("You have added a custom item that is being registered as a module. This is being removed from your custom items.", true)
self:Print("Removing: "..item.link, true)
self:UnregisterCustomItem(itemid)
end
local _, link, _, _, _, _, _, _, equipSlot = GetItemInfo(itemid)
if not link then self.unsafeIDs[itemid] = true end
bossLootTable[itemid] = {
dungeon = unlocalizedInstanceName,
bossid = bossId,
difficulty = itemtable and itemtable.difficulty or -1,
link = link,
equipSlot = equipSlot,
exceptions = itemtable and itemtable.exceptions,
}
end
end
data.bosses[unlocalizedInstanceName] = data.bosses[unlocalizedInstanceName] or {}
if not addToBoss then
tinsert(itemData[unlocalizedInstanceName], bossLootTable) --add loot to itemData
tinsert(data.bosses[unlocalizedInstanceName], bossName) --add Boss info to data
end
if tierToken then
data.tiertokens[unlocalizedInstanceName] = data.tiertokens[unlocalizedInstanceName] or {}
data.tiertokens[unlocalizedInstanceName][tierToken] = {dungeon = unlocalizedInstanceName, bossid = #data.bosses[unlocalizedInstanceName]}
end
BestInSlot.hasModules = true
end
--Simple helper to check if an array has any key
local function hasItems(array)
for _ in pairs(array) do
return true
end
return false
end
--- Called on initializing the add-on
function BestInSlot:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("BestInSlotDB", defaults)
SLASH_BESTINSLOT1, SLASH_BESTINSLOT2 = '/bestinslot', '/bis'
self:RegisterComm(self.MSGPREFIX)
self.options.instantAnimation = self.db.global.options.instantAnimation
self.options.showBiSTooltip = self.db.char.options.showBiSTooltip
self.options.windowFixed = self.db.char.options.windowFixed
self.options.sendAutomaticUpdates = self.db.char.options.sendAutomaticUpdates
self.options.receiveAutomaticUpdates = self.db.char.options.receiveAutomaticUpdates
AceEvent:RegisterEvent("GET_ITEM_INFO_RECEIVED", function(event, itemid) BestInSlot:SendEvent("GET_ITEM_INFO_RECEIVED", itemid) end)
self:RegisterEvent("GET_ITEM_INFO_RECEIVED", "OnItemInfoGenerated")
self:Print((L["has been initialized, use %s to show the GUI"]):format((L["%s or %s"]):format(self.colorHighlight.."/bis"..self.colorNormal, self.colorHighlight.."/bestinslot"..self.colorNormal)))
end
--- Called on enabling the add-on
function BestInSlot:OnEnable()
self:HookScript(GameTooltip, "OnTooltipSetItem", "GameTooltip_OnTooltipSetItem")
if AtlasLootTooltip then
self:HookScript(AtlasLootTooltip, "OnTooltipSetItem", "GameTooltip_OnTooltipSetItem")
end
self:HookScript(ItemRefTooltip, "OnTooltipSetItem", "GameTooltip_OnTooltipSetItem")
AceEvent:RegisterEvent("PLAYER_GUILD_UPDATE", function()
BestInSlot:SendEvent("PLAYER_GUILD_UPDATE")
end)
self:MiniMapButtonVisible(self.db.char.options.minimapButton)
self:SetBestInSlotInfo()
local coreModules = {
"ZoneDetect",
"History",
"History",
"Timer"
}
for i=1, #coreModules do
self:EnableModule(coreModules[i])
end
--Enable BiS Core modules
local loadOrder = {}
local waitList = {}
local ZoneDetect = self:GetModule("ZoneDetect")
for k,v in pairs(BestInSlot.modules) do
if not v.enabledState then
if v.dependancy then
waitList[v.dependancy] = waitList[v.dependancy] or {}
tinsert(waitList[v.dependancy], v)
else
tinsert(loadOrder, v)
end
end
end
while #loadOrder ~= 0 do
local module = tremove(loadOrder)
local moduleName = module.moduleName
module:Enable()
module:InitializeZoneDetect(ZoneDetect)
if waitList[moduleName] then
local addToList = waitList[moduleName]
for i=1,#addToList do
tinsert(loadOrder, addToList[i])
end
end
end
end
function BestInSlot:OnDisable()
self:Unhook(GameTooltip, "OnTooltipSetItem")
self:Unhook(ItemRefTooltip, "OnTooltipSetItem")
end
function BestInSlot:GetDifficultyIdForDungeon(bisId, dungeon, toBiS)
local returnId, bonusIds = nil
if not toBiS then
if dungeon and data.instances[dungeon] then
returnId, bonusIds = data.instances[dungeon].difficultyconversion[bisId], data.instances[dungeon].bonusids[bisId]
else
returnId, bonusIds = data.instances.__default.difficultyconversion[bisId], data.instances.__default.bonusids[bisId]
end
else
local tbl = data.instances[dungeon] or data.instances.__default
for BiSId, WoWId in pairs(tbl.difficultyconversion) do
if bisId == WoWId then
returnId, bonusIds = BiSId, tbl.bonusids[BiSId]
end
end
end
if not returnId then return end
if type(bonusIds) == "table" then
return returnId, unpack(bonusIds)
else
return returnId, bonusIds
end
end
--- Checks wether the player has the supplied item equipped, it should consider normal and warforged items the same
-- @param #number itemid The item ID to check if it's equipped
-- @return #boolean True if item equipped, otherwise false
function BestInSlot:HasItemEquipped(itemid, difficulty)
local item = self:GetItem(itemid, difficulty)
if not item then return end
for i=1,#self.slots do
local slotID = GetInventorySlotInfo(self.slots[i])
local link = GetInventoryItemLink("player", slotID)
if link then
local id, instanceDifficulty = self:GetItemInfoFromLink(link)
instanceDifficulty = tonumber(instanceDifficulty)
if id == itemid then
if difficulty == nil then
local bisId = self:GetDifficultyIdForDungeon(instanceDifficulty, item.dungeon, true)
if bisId then
return {bisId}
end
elseif self:GetDifficultyIdForDungeon(difficulty, item.dungeon) == instanceDifficulty then
return true
end
end
end
end
if difficulty then
return {}
end
end
function BestInSlot:GetItemInfoFromLink(itemlink)
local _,itemid, enchantId, gemId1, gemId2, gemId3, gemId4, suffixId, uniqueId, linkLevel, specId, upgradeId, instanceDifficultyID, numBonusId, bonusId1, bonusId2, bonusId3, upgradeVal = (":"):split(itemlink)
return tonumber(itemid), tonumber(instanceDifficultyID), bonusId1, bonusId2
end
--- Checks if the player has an item in their bags, or an item similar to it (warforged version for example)
-- @param #number itemid The itemID to check if the player has it in their bags
-- @return #boolean true if the player has the item in their bag, otherwise false
function BestInSlot:HasItemInBag(itemid, difficulty)
local item = self:GetItem(itemid)
if not item then return false end
local bags = NUM_BAG_SLOTS
local difficulties
local name = GetItemInfo(itemid)
for i=0,bags do
local bagSize = GetContainerNumSlots(i)
for j=1,bagSize do
local texture, count, locked, quality, readable, lootable, link, isFiltered = GetContainerItemInfo(i, j)
if link then
local id, instanceDifficulty = self:GetItemInfoFromLink(link)
instanceDifficulty = tonumber(instanceDifficulty)
if id == itemid then
if difficulty == nil then
difficulties = difficulties or {}
local bisId = self:GetDifficultyIdForDungeon(instanceDifficulty, item.dungeon, true)
if bisId then
tinsert(difficulties, bisId)
end
elseif self:GetDifficultyIdForDungeon(difficulty, item.dungeon) == instanceDifficulty then
return true
end
end
end
end
end
return difficulties
end
function BestInSlot:OnItemInfoGenerated(event, itemid)
local item = itemData[itemid]
if item then
local _, link, _, _, _, _, _, _, equipSlot = GetItemInfo(item.customitem or itemid)
if not link then return end
item.link = link
item.equipSlot = equipSlot
if item.tieritem then
item.bossid = equipSlot and data.tiertokens[item.dungeon][self:GetItemSlotID(equipSlot)].bossid
end
if self.unsafeIDs[itemid] then self.unsafeIDs[itemid] = nil end
end
end
--- Checks if the player has an item either in their bags, or equipped
-- @param #number itemid The itemID to check if the player has
-- @param #number [difficulty] The DifficultyId that the item must have.
-- @param #bool [checkHigherDifficulties] When true will check higher difficulties and return the difficulty number when found, or nil when not found.
-- @return #boolean true if the player has it, otherwise false
function BestInSlot:HasItem(itemid, difficulty, checkHigherDifficulties)
if not difficulty or not checkHigherDifficulties then
return self:HasItemEquipped(itemid, difficulty) or self:HasItemInBag(itemid, difficulty)
else
local equippedResult = self:HasItemEquipped(itemid)
local result = self:HasItemInBag(itemid) or {}
if equippedResult then
if not tContains(result, equippedResult[1]) then
tinsert(result, equippedResult[1])
end
end
if #result > 0 then
tsort(result)
if result[#result] >= difficulty then
return result[#result]
end
end
end
end
------------------------------------------------------------------------------------------------------------------------------------------------
-- Slash Commands
------------------------------------------------------------------------------------------------------------------------------------------------
--- A BestInSlot function to register a custom slash command. This will automatically be displayed at /help and should be able to be called through /bis [cmd]
-- @param #string cmd The command to register
-- @param #string descr The description to be displayed when '/bis help' is being typed
-- @param #function func The function to be called when this slash command is invoked
-- @param #number prefOrder The preferred location of this message in the '/bis help' dialog. Can be nil
function BestInSlot:RegisterSlashCmd(cmd, descr, func, prefOrder)
if type(cmd) ~= "string" then error("Command should be a string") end
if type(func) ~= "function" then error("Second argument of RegisterSlashCmd should be the function that should be called when the command is given") end
if type(descr) ~= "string" then error("Slashcommand should provide a description as third parameter") end
if prefOrder and type(prefOrder) ~= "number" then error("If provided, prefOrder should be a number") end
cmd = (cmd):lower()
if slashCommands[cmd] then error("Slash command "..cmd.." is already registered!") end
slashCommands[cmd] = {func = func, descr = descr, prefOrder = prefOrder}
end
function SlashCmdList.BESTINSLOT(msg, editbox)
local args = {}
local first = true
local command
for w in (msg):gmatch("%w+") do
if first then
command = w
first = false
else
tinsert(args, w)
end
end
if not command then
slashCommands.show.func()
else
command = (command):lower()
if not slashCommands[command] then
BestInSlot:Print((L["Command not recognized, try '%s' for help"]):format("/bis help"), true)
else
slashCommands[command].func(unpack(args))
end
end
end
BestInSlot:RegisterSlashCmd("help", (L["%s - this dialog"]):format("/bis help"), function()
local orderedList = {}
for k in pairs(slashCommands) do
tinsert(orderedList, k)
end
tsort(orderedList)
for i=1,#orderedList do
if slashCommands[orderedList[i]].prefOrder then
tinsert(orderedList, slashCommands[orderedList[i]].prefOrder, orderedList[i])
tremove(orderedList, i + 1)
end
end
DEFAULT_CHAT_FRAME:AddMessage(BestInSlot.colorHighlight..("-"):rep(5)..BestInSlot.colorNormal.."BestInSlotRedux "..L["commands"]..BestInSlot.colorHighlight..("-"):rep(5).."|r")
BestInSlot:Print(("%s: %s (%s)"):format(GAME_VERSION_LABEL, GetAddOnMetadata("BestInSlotRedux", "Version"), BestInSlot.version))
for i=1,#orderedList do
BestInSlot:Print(slashCommands[orderedList[i]].descr, true)
end
DEFAULT_CHAT_FRAME:AddMessage(BestInSlot.colorHighlight..("-"):rep(36).."|r")
end)
BestInSlot:RegisterSlashCmd("debug", (L["%s - enable/disable debug messages"]):format("/bis debug"), function()
if BestInSlot.options.DEBUG then
BestInSlot:Print(L["Disabling debug messages"])
BestInSlot.options.DEBUG = false
else
BestInSlot.options.DEBUG = true
BestInSlot:Print(L["Enabling debug messages"])
end
BestInSlot:SendEvent("DebugOptionsChanged", BestInSlot.options.DEBUG)
end)
local itemslotidCache = {}
function BestInSlot:GetItemSlotID(equipSlot, spec)
if not equipSlot then return end
if spec == 72 and equipSlot == "INVTYPE_2HWEAPON" then return 16,17 end --fury warrior 2-handers
if itemslotidCache[equipSlot] then
if #itemslotidCache[equipSlot] == 1 then return itemslotidCache[equipSlot][1] else return itemslotidCache[equipSlot][1], itemslotidCache[equipSlot][2] end
end
local result = {}
for i=1,#self.invSlots do
if type(self.invSlots[i]) == "string" then
if self.invSlots[i] == equipSlot then
tinsert(result, i)
end
elseif type(self.invSlots[i]) == "table" then
for j=1,#self.invSlots[i] do
if self.invSlots[i][j] == equipSlot then
tinsert(result, i)
end
end
end
end
itemslotidCache[equipSlot] = result
return unpack(result)
end
------------------------------------------------------------------------------------------------------------------------------------------------
-- Getters for data
------------------------------------------------------------------------------------------------------------------------------------------------
---
-- This function returns an array of items by id to define in what order it should show the items provided in the itemArray
-- @param #array itemArray The array of items to sort
-- @param #string mode The mode to sort at, currently only supports "SORT_MODE_ILVL" and defaults to that
---
function BestInSlot:GetLootOrder(itemArray, mode)
local sortArray = {}
local mode = mode or "SORT_MODE_ILVL"
if mode == "SORT_MODE_ILVL" then
for k,v in pairs(itemArray) do
if #sortArray == 0 then
tinsert(sortArray, k)
else
local position
for i=1,#sortArray do
if sortArray[i] > k then
position = i
break
end
end
position = position or #sortArray + 1
tinsert(sortArray, position, k)
end
end
end
return sortArray
end
--- Retrieve the loot table that's personalized for the player.
-- @param #number raidTier The raidtier to retrieve the loot table for
-- @param #number slotID The slotID to retrieve the loot table for
-- @param #number difficulty The difficulty ID to retrieve the loot table for
-- @param #number specializationId The specializationID to retrieve the loot for
-- @param #boolean lowerRaidTiers Show loot for lower raid tiers as well
-- @param #number The specialization to use to compare uniquness for
-- @return #table The loot table for the player
function BestInSlot:GetPersonalizedLootTableBySlot(raidTier, slotId, difficulty, specializationId, lowerRaidTiers, uniquenessSpec)
local specRole, class = select(6, GetSpecializationInfoByID(specializationId))
uniquenessSpec = uniquenessSpec or specializationId
if specializationId == 261 then --Subtlety Rogues
return self:GetPersonalizedLootTableBySlot(raidTier, slotId, difficulty, 260, lowerRaidTiers, 261) --Return table for combat rogues. Non-Daggers can be used by sub aswell
end
if specializationId == 72 and slotId == 17 then --Fury warriors can wield everything in their offhand
return self:GetPersonalizedLootTableBySlot(raidTier, 16, difficulty, specializationId, lowerRaidTiers) --return main hand loot list instead
end
local items = self:GetLootTableBySlot(raidTier, slotId, difficulty, lowerRaidTiers)
if not items then
return
end
for id, item in pairs(items) do
local canUse
local statFilter = GetItemSpecInfo(item.itemid)
if item.exceptions then
local checks = {specRole, class}
for i, check in pairs({"role", "class"}) do
local checkitem = item.exceptions[check]
if checkitem and type(checkitem) == "table" and tContains(checkitem, checks[i]) or checkitem == checks[i] then
exceptions[item.itemid] = true
break
end
end
end
if statFilter then
if #statFilter == 0 then --There is no itemspecinfo available for this item, normally the table should be nil
if raidTier > 70000 and (slotId == 2 or slotId == 11 or slotId == 12) and item.misc ~= LOOT_JOURNAL_LEGENDARIES then
canUse = true
else
canUse = item.customitem ~= nil
end
else
canUse = tContains(statFilter, specializationId)
end
else
canUse = false
end
if canUse and tContains(data.raidTiers[raidTier].instances, item.dungeon) then --check item uniqueness
local family, count = GetItemUniqueness(item.itemid)
if count == 1 and self:IsItemBestInSlot(item.itemid, difficulty, uniquenessSpec) then
canUse = false
end
end
if canUse and slotId == 17 and item.equipSlot == "INVTYPE_WEAPON" then
canUse = false
for i=1,#self.dualWield do
if self.dualWield[i] == specializationId then
canUse = true
break
end
end
end
if not canUse then
items[id] = nil
end
end
local addSpec
if specializationId == 73 then --Prot warriors
addSpec = 71 --Arms
elseif specializationId == 104 then --Guardian Druid
addSpec = 103 --Feral Druid
elseif specializationId == 66 then --Prot Pally
addSpec = 70 --Ret Pally
elseif specializationId == 250 then --Blood DK
addSpec = 252 --Unholy DK
elseif specializationId == 268 then --Brewmaster Monk
addSpec = 269 --Windwalker Monk
elseif specializationId == 105 then --Resto Druid
addSpec = 102 --Balance Druid
elseif specializationId == 264 then --Resto Shaman
addSpec = 262 --Elemental Shaman
elseif specializationId == 257 or specializationId == 256 then --Both Healing Priests
addSpec = 258 --Shadow Priest
end
--ToDo Implement fix for paladin
if addSpec then
local dpsItems = self:GetPersonalizedLootTableBySlot(raidTier, slotId, difficulty, addSpec, lowerRaidTiers, specializationId)
for itemid, item in pairs(dpsItems) do
if not items[itemid] then
items[itemid] = item
end
end
end
return items
end
local function addLootToTableByFilter(tbl, itemlist, slotId, difficulty)
for id in pairs(itemlist) do
local item = BestInSlot:GetItem(id, difficulty)
if (not slotId) or (type(BestInSlot.invSlots[slotId]) == "string" and BestInSlot.invSlots[slotId] == item.equipSlot) or (type(BestInSlot.invSlots[slotId]) == "table" and tContains(BestInSlot.invSlots[slotId],item.equipSlot)) then
if (not difficulty) or (not item.difficulty or (item.difficulty == -1 or item.difficulty == difficulty or (type(item.difficulty) == "table") and tContains(item.difficulty, difficulty)) ) then
tbl[id] = item
end
end
end
end
--- Gets the loottable for the supplied dungeon
-- @param #string dungeon Unlocalized name of the dungeon
-- @param #number slotId Optional slotId to add
function BestInSlot:GetLootTableByDungeon(dungeon, slotId, difficulty)
local items = {}
local dungeonData = itemData[dungeon]
for bossId=1,#dungeonData do
addLootToTableByFilter(items, dungeonData[bossId], slotId, difficulty)
end
if dungeonData.tieritems then
addLootToTableByFilter(items, dungeonData.tieritems, slotId, difficulty)
end
if dungeonData.misc then
addLootToTableByFilter(items, dungeonData.misc, slotId, difficulty)
end
if dungeonData.customitems then
addLootToTableByFilter(items, dungeonData.customitems, slotId, difficulty)
end
return items
end
local function helperFullLootTable(tbl, itemlist, difficulty)
for id in pairs(itemlist) do
local item = BestInSlot:GetItem(id, difficulty)
if (not difficulty) or (not item.difficulty or (item.difficulty == -1 or item.difficulty == difficulty or (type(item.difficulty) == "table") and tContains(item.difficulty, difficulty)) ) then
tbl[id] = item
end
end
end
function BestInSlot:GetFullLootTableForRaidTier(raidTier, difficulty)
local items = {}
for _, dungeon in pairs(self:GetInstances(self.RAIDTIER, raidTier)) do
local dungeonData = itemData[dungeon]
for bossId=1,#dungeonData do
helperFullLootTable(items, dungeonData[bossId], difficulty)
end
if dungeonData.tieritems then
helperFullLootTable(items, dungeonData.tieritems, difficulty)
end
if dungeonData.misc then
helperFullLootTable(items, dungeonData.misc, difficulty)
end
if dungeonData.customitems then
helperFullLootTable(items, dungeonData.customitems, difficulty)
end
end
return items
end
--- Get the loottable for the supplied raidTier, slot, and difficulty
-- @param #number raidTier The raidtier to request the loot table off
-- @param #number slotId The Slot ID to request
-- @param #number difficulty The difficulty ID of the raidTier to request the data off
-- @param #boolean lowerRaidTiers Get data for lower raid tiers as well
-- @return #table The loot table
function BestInSlot:GetLootTableBySlot(raidTier, slotId, difficulty, lowerRaidTiers)
local items = {}
local dungeons = data.raidTiers[raidTier].instances
for i=1,#dungeons do
for id, item in pairs(self:GetLootTableByDungeon(dungeons[i], slotId, difficulty)) do
items[id] = item
end
end
if lowerRaidTiers then
local module = data.raidTiers[raidTier].module
local raidTiers = self:GetRaidTiers()
for i=1,#raidTiers do
if raidTiers[i] == raidTier then break end --stop the loop at the raidTier that we already have data from
if module == data.raidTiers[raidTiers[i]].module then
for id, item in pairs(self:GetLootTableBySlot(raidTiers[i], slotId, difficulty)) do
items[id] = item
end
end
end