-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTransmogUpgradeMaster.lua
More file actions
944 lines (829 loc) · 35 KB
/
TransmogUpgradeMaster.lua
File metadata and controls
944 lines (829 loc) · 35 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
local name = ...;
--- @class TUM_NS
local ns = select(2, ...);
--- @class TransmogUpgradeMaster
local TUM = {}
TransmogUpgradeMaster = TUM
--@debug@
_G.TUM = TUM
--@end-debug@
ns.core = TUM
TUM.data = ns.data
TUM.Config = ns.TUM_Config
local constants = TUM.data.constants
--- @alias TUM_LearnedFromOtherItem "learnedFromOtherItem"
local LEARNED_FROM_OTHER_ITEM = 'learnedFromOtherItem'
local BONUS_ID_OFFSET = 13
local ITEM_UPGRADE_TOOLTIP_PATTERN = ITEM_UPGRADE_TOOLTIP_FORMAT_STRING:gsub('%%d', '(%%d+)'):gsub('%%s', '(.-)');
local CATALYST_ATLAS = 'CreationCatalyst-32x32';
local UPGRADE_ATLAS = 'CovenantSanctum-Upgrade-Icon-Available';
local CATALYST_UPGRADE_TEXTURE = [[Interface\AddOns\TransmogUpgradeMaster\media\CatalystUpgrade.png]];
local CATALYST_MARKUP = CreateAtlasMarkup(CATALYST_ATLAS, 18, 18);
local UPGRADE_MARKUP = CreateAtlasMarkup(UPGRADE_ATLAS, 18, 18);
local CATALYST_UPGRADE_MARKUP = CreateSimpleTextureMarkup(CATALYST_UPGRADE_TEXTURE, 18, 18);
local OK_MARKUP = [[|TInterface\RaidFrame\ReadyCheck-Ready:0|t]];
local NOK_MARKUP = [[|TInterface\RaidFrame\ReadyCheck-NotReady:0|t]];
local OTHER_MARKUP = CreateAtlasMarkup('QuestRepeatableTurnin', 16, 16);
local playerClassID = select(3, UnitClass("player"));
local classIDToName = {};
do
for classID = 1, GetNumClasses() do
local className, classFile = GetClassInfo(classID);
local classColor = RAID_CLASS_COLORS[classFile];
if className then
classIDToName[classID] = classColor:WrapTextInColorCode(className);
end
end
TUM.currentSeason = TUM.data.currentSeason;
TUM.sets = TUM.data.sets;
TUM.setSourceIDs = TUM.data.setSourceIDs;
TUM.catalystItems = TUM.data.catalystItems;
TUM.catalystItemByID = TUM.data.catalystItemByID;
end
EventUtil.ContinueOnAddOnLoaded(name, function()
--- @type TransmogUpgradeMaster_CollectionUI
TUM.UI = ns.UI;
TUM.db = TUM.Config:Init();
TUM.UI:Init();
local currentSeason = C_MythicPlus.GetCurrentSeason();
if currentSeason and currentSeason > 0 then
TUM.currentSeason = (currentSeason and currentSeason > 0 and TUM:IsSeasonSupported(currentSeason))
and currentSeason
or TUM.data.currentSeason;
TUM.UI:InitSeason(TUM.currentSeason);
TUM.seasonInitialized = true;
else
RunNextFrame(function()
C_MythicPlus.RequestMapInfo();
end);
EventUtil.RegisterOnceFrameEventAndCallback('CHALLENGE_MODE_MAPS_UPDATE', function()
currentSeason = C_MythicPlus.GetCurrentSeason();
TUM.currentSeason = (currentSeason and currentSeason > 0 and TUM:IsSeasonSupported(currentSeason))
and currentSeason
or TUM.data.currentSeason;
TUM.UI:InitSeason(TUM.currentSeason);
TUM.seasonInitialized = true;
end);
end
RunNextFrame(function()
TUM:InitItemSourceMap()
EventUtil.ContinueOnAddOnLoaded('Blizzard_ItemInteractionUI', function()
hooksecurefunc(ItemInteractionFrame, 'InteractWithItem', function() TUM:HandleCatalystInteraction() end)
end)
end)
--- @param tooltip GameTooltip
TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Item, function(tooltip, tooltipData)
if tooltip == GameTooltip or tooltip == GameTooltip.ItemTooltip.Tooltip or tooltip == ItemRefTooltip then
TUM:HandleTooltip(tooltip, tooltipData)
end
end)
SLASH_TRANSMOG_UPGRADE_MASTER1 = "/tum";
SLASH_TRANSMOG_UPGRADE_MASTER2 = "/transmogupgrademaster";
SlashCmdList["TRANSMOG_UPGRADE_MASTER"] = function(msg)
if msg and msg:trim() == 'config' then
TUM.Config:OpenSettings();
return;
end
TUM.UI:ToggleUI();
end
if NumyProfiler then
TUM.HandleTooltip = NumyProfiler:Wrap(name, "Core", "HandleTooltip", TUM.HandleTooltip);
NumyProfiler:WrapModules(name, "API", TransmogUpgradeMaster_API);
end
TUM:RegisterIntoBaganator();
end)
do
function TransmogUpgradeMaster_OnAddonCompartmentClick(_, mouseButton)
if mouseButton == 'LeftButton' then
TUM.UI:ToggleUI();
else
TUM.Config:OpenSettings();
end
end
function TransmogUpgradeMaster_OnAddonCompartmentEnter(_, button)
GameTooltip:SetOwner(button, 'ANCHOR_RIGHT');
GameTooltip:AddLine('Transmog Upgrade Master')
GameTooltip:AddLine(CreateAtlasMarkup('NPE_LeftClick', 18, 18) .. ' to toggle the Collection UI');
GameTooltip:AddLine(CreateAtlasMarkup('NPE_RightClick', 18, 18) .. ' to open the settings');
GameTooltip:Show();
end
function TransmogUpgradeMaster_OnAddonCompartmentLeave()
GameTooltip:Hide();
end
end
function TUM:IsSeasonSupported(seasonID)
return not not TUM.data.catalystItems[seasonID];
end
---@param classID number
---@param seasonID number?
---@return nil | { [TUM_Tier]: number } # [tier] = setID
function TUM:GetSetsForClass(classID, seasonID)
return self.sets[seasonID or self.currentSeason] and self.sets[seasonID or self.currentSeason][classID] or nil;
end
--- @param classMask number
--- @return number[] classIDList
function TUM:ConvertClassMaskToClassList(classMask)
local classIDList = {};
for classID = 1, GetNumClasses() do
local classAllowed = FlagsUtil.IsSet(classMask, bit.lshift(1, (classID - 1)));
if classAllowed then
table.insert(classIDList, classID);
end
end
return classIDList;
end
function TUM:InitItemSourceMap()
if self.itemSourceMapInitialized == false then
-- already initializing...
return
end
local itemSourceIDs = {}
self.itemSourceMapInitialized = false
self.itemSourceMapProgress = 0
self.itemSourceMapTotal = 0
self.itemSourceIDs = TransmogUpgradeMasterCacheDB or itemSourceIDs
local buildNr = select(2, GetBuildInfo())
if buildNr == self.itemSourceIDs._buildNr then
self.itemSourceMapInitialized = true
self.itemSourceMapProgress = 1
self.itemSourceMapTotal = 1
-- only refresh the cache if the build number has changed
return
end
--- @type table<number, TransmogCategoryAppearanceInfo[]>
local categoryAppearances = {}
for _, category in pairs(Enum.TransmogCollectionType) do
categoryAppearances[category] = C_TransmogCollection.GetCategoryAppearances(category)
self.itemSourceMapTotal = self.itemSourceMapTotal + #categoryAppearances[category]
end
local msPerBatch = 20
local function iterateAppearances()
local start = debugprofilestop()
for _, appearances in pairs(categoryAppearances) do
for _, info in pairs(appearances) do
local appearanceSources = C_TransmogCollection.GetAppearanceSources(info.visualID)
if appearanceSources then
for _, sourceInfo in ipairs(appearanceSources) do
local tier = constants.itemModIDTiers[sourceInfo.itemModID] or nil
if tier then
itemSourceIDs[sourceInfo.itemID] = itemSourceIDs[sourceInfo.itemID] or {}
itemSourceIDs[sourceInfo.itemID][tier] = sourceInfo.sourceID
end
end
end
self.itemSourceMapProgress = self.itemSourceMapProgress + 1
if debugprofilestop() - start > msPerBatch then
coroutine.yield()
start = debugprofilestop()
end
end
end
self.itemSourceMapInitialized = true
self.itemSourceIDs = itemSourceIDs
TransmogUpgradeMasterCacheDB = itemSourceIDs
TransmogUpgradeMasterCacheDB._buildNr = buildNr
end
local resumeFunc = coroutine.wrap(iterateAppearances)
local ticker
ticker = C_Timer.NewTicker(1, function()
if self.itemSourceMapInitialized then
ticker:Cancel()
return
end
resumeFunc()
end)
end
function TUM:IsToken(itemID)
return not not self.data.tokens[itemID]
end
--- @param tooltipData TooltipData?
--- @return nil|{season: number, classList: number[], tier: TUM_Tier|nil, slot: number}
function TUM:GetTokenInfo(itemID, itemLink, tooltipData)
local tokenInfo = self.data.tokens[itemID]
if not tokenInfo then
return nil
end
local _, data = LinkUtil.ExtractLink(itemLink)
local parts = strsplittable(':', data)
local itemCreationContext = tonumber(parts[12])
local tier = constants.itemContextTiers[itemCreationContext] or self:GetTooltipDifficultyTier(itemLink, tooltipData)
return {
season = tokenInfo.season,
tier = tier,
slot = tokenInfo.slot,
classList = tokenInfo.classList,
}
end
--- @param itemLink string
--- @param tooltipData TooltipData?
--- @return TUM_Tier|nil tier
function TUM:GetTooltipDifficultyTier(itemLink, tooltipData)
tooltipData = tooltipData or C_TooltipInfo.GetHyperlink(itemLink)
local line2Text = tooltipData and tooltipData.lines[2] and tooltipData.lines[2].leftText or nil
if not line2Text then return nil end
for tier, difficultyString in pairs(constants.difficultyTierStrings) do
if line2Text == difficultyString then
return tier
end
end
-- default to normal
return constants.tiers.normal
end
--- doesn't return season information for catalysed items from previous seasons, but that's fine, since nothing can be done with those items anyway
--- @param itemLink string
--- @return TUM_Season|nil seasonID
function TUM:GetItemSeason(itemLink)
local _, data = LinkUtil.ExtractLink(itemLink);
local parts = data and strsplittable(':', data) or {};
local itemID = tonumber(parts[1]);
local tokenInfo = self.data.tokens[itemID];
if tokenInfo then return tokenInfo.season; end
local numBonusIDs = tonumber(parts[BONUS_ID_OFFSET]) or 0;
for index = (BONUS_ID_OFFSET + 1), (BONUS_ID_OFFSET + numBonusIDs) do
local bonusID = tonumber(parts[index]);
local seasonID = self.data.catalystBonusIDMap[bonusID];
if seasonID then
return seasonID;
end
end
if self:CanBeUpgraded(itemLink) then
-- this can be inaccurate
return self.currentSeason;
end
return nil;
end
--- @todo in midnight this is somewhat incorrect. technically the items are still upgradable, but you can't actually get any valorstones to do so
--- @param itemLink string
--- @return boolean
function TUM:CanBeUpgraded(itemLink)
local data = C_TooltipInfo.GetHyperlink(itemLink);
for _, line in ipairs(data and data.lines or {}) do
if line and line.leftText and line.leftText:match(ITEM_UPGRADE_TOOLTIP_PATTERN) then
if
line.leftText:match('|cFF808080.-')
or line.leftColor:GenerateHexColor() == 'ff808080'
then
return false
else
return true
end
end
end
return false
end
--- @param itemLink string
--- @return boolean isConquestPvpItem
function TUM:IsConquestPvpItem(itemLink)
local _, sourceID = C_TransmogCollection.GetItemInfo(itemLink)
if not sourceID then
return false
end
local sourceInfo = C_TransmogCollection.GetSourceInfo(sourceID)
return sourceInfo and sourceInfo.itemModID == constants.conquestItemModID or false
end
--- @param itemLink string
--- @param tooltipData TooltipData
function TUM:CanSendItemToAlt(itemLink, tooltipData)
local binding = self:GetItemBinding(itemLink, tooltipData)
return binding and constants.mailableBindings[binding] or false
end
--- @param itemLink string
--- @param tooltipData TooltipData
--- @return Enum.TooltipDataItemBinding|nil itemBinding
function TUM:GetItemBinding(itemLink, tooltipData)
local data = tooltipData or C_TooltipInfo.GetHyperlink(itemLink);
for _, line in ipairs(data and data.lines or {}) do
if line and line.type == Enum.TooltipDataLineType.ItemBinding then
return line.bonding
end
end
return nil
end
--- @param itemLink string
--- @param seasonID TUM_Season
--- @param classID number
--- @param itemSlot Enum.InventoryType
--- @return TUM_Tier|nil tier
function TUM:GuessTierFromForgedTooltip(itemLink, seasonID, classID, itemSlot)
local catalysedItemID = self.catalystItems[seasonID] and self.catalystItems[seasonID][classID] and self.catalystItems[seasonID][classID][itemSlot]
if not catalysedItemID then
return nil
end
local forgedLink = itemLink:gsub('item:(%d+)', 'item:' .. catalysedItemID)
local _, sourceID = C_TransmogCollection.GetItemInfo(forgedLink)
local sourceInfo = sourceID and C_TransmogCollection.GetSourceInfo(sourceID)
return sourceInfo and constants.itemModIDTiers[sourceInfo.itemModID] or nil
end
local modifierFunctions = {
[TUM.Config.modifierKeyOptions.always] = function() return true end,
[TUM.Config.modifierKeyOptions.shift] = IsShiftKeyDown,
[TUM.Config.modifierKeyOptions.ctrl] = IsControlKeyDown,
[TUM.Config.modifierKeyOptions.alt] = IsAltKeyDown,
[TUM.Config.modifierKeyOptions.never] = function() return false end,
}
--- @param tooltip GameTooltip
--- @param text string
--- @param isCollected boolean
function TUM:AddTooltipLine(tooltip, text, isCollected, fromOtherItem)
local modifierSetting =
(isCollected and self.db.showCollectedModifierKey)
or (fromOtherItem and self.db.showCollectedFromOtherItemModifierKey)
or (self.db.showUncollectedModifierKey)
local modifierFunction = modifierFunctions[modifierSetting]
if not modifierFunction or not modifierFunction() then
return
end
local ok = OK_MARKUP .. GREEN_FONT_COLOR:WrapTextInColorCode(' Collected ') .. OK_MARKUP
local nok = NOK_MARKUP .. RED_FONT_COLOR:WrapTextInColorCode(' Not Collected ') .. NOK_MARKUP
local other = OTHER_MARKUP .. BLUE_FONT_COLOR:WrapTextInColorCode(' From Another Item ') .. OTHER_MARKUP
tooltip:AddDoubleLine(text, (isCollected and ok) or (fromOtherItem and other) or nok)
end
--- @param tooltip GameTooltip
--- @param text string
function TUM:AddDebugLine(tooltip, text)
if not self.db.debug then return end
tooltip:AddDoubleLine('<TUM Debug>', text, 1, 0.5, 0, 1, 1, 1)
end
--- @param tbl table?
---@param value any
local function tryInsert(tbl, value)
if tbl then
table.insert(tbl, value)
end
end
--- @param itemLink string
--- @param classID number? # defaults to the player's class
--- @param debugLines string[]? # if provided, debug lines will be added to this table
--- @param tooltipData TooltipData?
--- @return TUM_AppearanceMissingResult
function TUM:IsAppearanceMissing(itemLink, classID, debugLines, tooltipData)
--- @type TUM_AppearanceMissingResult
local result = {
canCatalyse = nil,
canUpgrade = nil,
catalystAppearanceMissing = nil,
catalystUpgradeAppearanceMissing = nil,
upgradeAppearanceMissing = nil,
catalystAppearanceLearnedFromOtherItem = false,
catalystUpgradeAppearanceLearnedFromOtherItem = false,
upgradeAppearanceLearnedFromOtherItem = false,
}
if not C_Item.IsItemDataCachedByID(itemLink) then
tryInsert(debugLines, 'item data not cached')
return result
end
classID = classID or playerClassID
result.canCatalyse, result.canUpgrade = false, false
result.contextData = {}
local context = result.contextData
local itemID = tonumber(itemLink:match("item:(%d+)"))
local isToken = itemID and self:IsToken(itemID)
if not itemID or (not isToken and not C_Item.IsDressableItemByID(itemID)) then
return result
end
context.itemID = itemID
tryInsert(debugLines, 'itemID: ' .. tostring(itemID))
local upgradeInfo = C_Item.GetItemUpgradeInfo(itemLink)
local canUpgrade = upgradeInfo and self:CanBeUpgraded(itemLink)
local seasonID = self:GetItemSeason(itemLink)
context.seasonID = seasonID
local seasonName = constants.seasonNames[seasonID] or nil
tryInsert(debugLines, ('seasonID: %s%s'):format(tostring(seasonID), seasonName and (' (%s)'):format(seasonName) or ''))
tryInsert(debugLines, ('canUpgrade: %s'):format(tostring(canUpgrade)))
if not (upgradeInfo and upgradeInfo.currentLevel > 0) and not seasonID then
tryInsert(debugLines, 'not upgradable and no seasonID')
return result
end
local currentTier = 0;
local tierSource = '';
if upgradeInfo and upgradeInfo.currentLevel > 0 then
local breakpoint = constants.upgradeTransmogBreakpoints[seasonID or self.currentSeason];
currentTier = constants.trackStringIDToTiers[upgradeInfo.trackStringID] or 0
if currentTier == 0 then
tryInsert(debugLines, ('unsupported upgrade track: %s (%s) '):format(tostring(upgradeInfo.trackString), tostring(upgradeInfo.trackStringID)))
return result;
end
tierSource = 'upgrade info'
if upgradeInfo.currentLevel >= breakpoint and currentTier < constants.tiers.mythic then
currentTier = currentTier + 1
tierSource = 'upgrade info > breakpoint'
end
if canUpgrade and upgradeInfo.currentLevel < breakpoint and currentTier < constants.tiers.mythic then
result.canUpgrade = true
end
else
currentTier = seasonID and self:GetTierFromUpgradeTrackBonusID(itemLink, seasonID) or 0
tierSource = 'upgrade info (bonusID)'
end
local _, sourceID = C_TransmogCollection.GetItemInfo(itemLink)
tryInsert(debugLines, 'sourceID: ' .. tostring(sourceID))
if sourceID and debugLines then
local sourceInfo = C_TransmogCollection.GetSourceInfo(sourceID)
tryInsert(debugLines, 'itemModID: ' .. tostring(sourceInfo and sourceInfo.itemModID))
end
local tokenInfo = isToken and self:GetTokenInfo(itemID, itemLink, tooltipData)
if tokenInfo then
if not tokenInfo.classList[classID] then
tryInsert(debugLines, 'item is a token for another class')
return result
end
currentTier = tokenInfo.tier or currentTier
tierSource = 'token info'
end
local itemSlot = tokenInfo and tokenInfo.slot or C_Item.GetItemInventoryTypeByID(itemLink)
if itemSlot == Enum.InventoryType.IndexRobeType then
-- robes catalyse into chest pieces
itemSlot = Enum.InventoryType.IndexChestType
end
context.slot = itemSlot
if currentTier == 0 then
local sourceIDs = self:GetSourceIDsForItemID(itemID)
local index = tIndexOf(sourceIDs or {}, sourceID)
currentTier = index or 0
tierSource = 'sourceID index'
if currentTier == 0 then
local sourceInfo = sourceID and C_TransmogCollection.GetSourceInfo(sourceID)
currentTier = sourceInfo and constants.itemModIDTiers[sourceInfo.itemModID] or 0
tierSource = 'source itemModID'
end
if currentTier == 0 then
currentTier = seasonID and self:GuessTierFromForgedTooltip(itemLink, seasonID, classID, itemSlot) or 0
tierSource = 'tooltip shenanigans'
end
if currentTier == 0 then
tryInsert(debugLines, 'no tier info found')
return result
end
end
context.tier = currentTier
tryInsert(debugLines, 'currentTier: ' .. tostring(currentTier))
tryInsert(debugLines, 'tierSource: ' .. tostring(tierSource))
local setIDs = sourceID and C_TransmogSets.GetSetsContainingSourceID(sourceID)
local relatedSets
if setIDs and #setIDs > 0 then
tryInsert(debugLines, 'setIDs: ' .. table.concat(setIDs, ', '))
for _, setID in ipairs(setIDs) do
local setInfo = C_TransmogSets.GetSetInfo(setID)
local classIDList = self:ConvertClassMaskToClassList(setInfo.classMask)
local classSets = self:GetSetsForClass(classIDList[1], seasonID)
if classSets and tIndexOf(classSets, setID) then
relatedSets = classSets
end
end
end
-- conquest PvP items can be catalysed for set bonus and upgraded, but they keep their appearance
local isConquestPvpItem = self:IsConquestPvpItem(itemLink)
tryInsert(debugLines, 'isConquestPvpItem: ' .. tostring(isConquestPvpItem))
context.isPvpItem = isConquestPvpItem
if isConquestPvpItem then
result.canUpgrade = false
end
local isCatalysed = self:IsItemCatalysed(itemID)
tryInsert(debugLines, 'isCatalysed: ' .. tostring(isCatalysed))
result.canCatalyse = not not (tokenInfo or (seasonID and not isCatalysed and not isConquestPvpItem and self:IsCatalystSlot(itemSlot) and self:IsValidArmorTypeForClass(itemLink, classID)))
if result.canCatalyse then
--@debug@
if not tokenInfo and self:GuessTierFromForgedTooltip(itemLink, seasonID, classID, itemSlot) ~= currentTier then
print('wrong tier guessed for item ', itemLink)
end
--@end-debug@
local catalystCollected, catalystUpgradeCollected
local playerSets = self:GetSetsForClass(classID, seasonID)
if playerSets then
catalystCollected = self:IsSetItemCollected(playerSets[currentTier], itemSlot)
if result.canUpgrade then
catalystUpgradeCollected = self:IsSetItemCollected(playerSets[currentTier + 1], itemSlot)
end
else
catalystCollected = self:IsCatalystItemCollected(seasonID, classID, itemSlot, currentTier)
if result.canUpgrade then
catalystUpgradeCollected = self:IsCatalystItemCollected(seasonID, classID, itemSlot, currentTier + 1)
end
end
if catalystCollected ~= nil then
result.catalystAppearanceMissing = catalystCollected ~= true
if catalystCollected == LEARNED_FROM_OTHER_ITEM then
result.catalystAppearanceLearnedFromOtherItem = true
end
end
if catalystUpgradeCollected ~= nil then
result.catalystUpgradeAppearanceMissing = catalystUpgradeCollected ~= true
if catalystUpgradeCollected == LEARNED_FROM_OTHER_ITEM then
result.catalystUpgradeAppearanceLearnedFromOtherItem = true
end
end
else
tryInsert(debugLines, 'can\'t catalyse or catalyst keeps old appearance')
end
local upgradeCollected
if isCatalysed and relatedSets and result.canUpgrade then
local nextSetID = relatedSets[currentTier + 1]
if nextSetID then
upgradeCollected = self:IsSetItemCollected(nextSetID, itemSlot)
end
elseif result.canUpgrade then
local sourceIDs = self:GetSourceIDsForItemID(itemID)
if sourceIDs and sourceIDs[currentTier + 1] then
upgradeCollected = self:IsSourceIDCollected(sourceIDs[currentTier + 1])
end
end
if upgradeCollected ~= nil then
result.upgradeAppearanceMissing = upgradeCollected ~= true
if upgradeCollected == LEARNED_FROM_OTHER_ITEM then
result.upgradeAppearanceLearnedFromOtherItem = true
end
end
if self:IsCacheWarmedUp() then
if result.canCatalyse then
result.catalystAppearanceMissing = result.catalystAppearanceMissing or false
if result.canUpgrade then
result.catalystUpgradeAppearanceMissing = result.catalystUpgradeAppearanceMissing or false
end
end
if result.canUpgrade then
result.upgradeAppearanceMissing = result.upgradeAppearanceMissing or false
end
end
return result
end
--- @param tooltip GameTooltip
--- @param tooltipData TooltipData
function TUM:HandleTooltip(tooltip, tooltipData)
local itemLink = select(2, TooltipUtil.GetDisplayedItem(tooltip))
if not itemLink or issecretvalue(itemLink) then return end
local debugLines = {}
local result = self:IsAppearanceMissing(itemLink, nil, debugLines, tooltipData)
if tooltipData.guid then
local itemLocation = C_Item.GetItemLocation(tooltipData.guid)
local isConvertable = itemLocation
and itemLocation:HasAnyLocation()
and itemLocation:IsValid()
and C_Item.IsItemConvertibleAndValidForPlayer(itemLocation)
if isConvertable and not result.canCatalyse and not result.contextData.isPvpItem then
tooltip:AddLine("TUM Error: Item can be catalysed, but catalyst info wasn't found", 1, 0, 0, true)
end
end
for _, line in ipairs(debugLines) do
self:AddDebugLine(tooltip, line)
end
local loadingTooltipShown = false
if result.canCatalyse then
if result.catalystAppearanceMissing == nil then
if not loadingTooltipShown then loadingTooltipShown = self:ShowLoadingTooltipIfLoading(tooltip) end
else
self:AddTooltipLine(
tooltip,
CATALYST_MARKUP .. ' Catalyst appearance',
not result.catalystAppearanceMissing,
result.catalystAppearanceLearnedFromOtherItem
)
end
if result.canUpgrade then
if result.catalystUpgradeAppearanceMissing == nil then
if not loadingTooltipShown then loadingTooltipShown = self:ShowLoadingTooltipIfLoading(tooltip) end
else
self:AddTooltipLine(
tooltip,
CATALYST_UPGRADE_MARKUP .. ' Catalyst & Upgrade appearance',
not result.catalystUpgradeAppearanceMissing,
result.catalystUpgradeAppearanceLearnedFromOtherItem
)
end
end
end
if result.canUpgrade then
if result.upgradeAppearanceMissing == nil then
if not loadingTooltipShown then loadingTooltipShown = self:ShowLoadingTooltipIfLoading(tooltip) end
else
self:AddTooltipLine(
tooltip,
UPGRADE_MARKUP .. ' Upgrade appearance',
not result.upgradeAppearanceMissing,
result.upgradeAppearanceLearnedFromOtherItem
)
end
end
if modifierFunctions[self.db.showWarbandCatalystInfoModifierKey]() and self:CanSendItemToAlt(itemLink, tooltipData) then
local catalystClassList = {}
local catalystUpgradeClassList = {}
for classID = 1, GetNumClasses() do
if classID ~= playerClassID and self.db.warbandCatalystClassList[classID] then
local classResult = self:IsAppearanceMissing(itemLink, classID, nil, tooltipData)
if classResult.catalystAppearanceMissing then
table.insert(catalystClassList, classID)
end
if classResult.catalystUpgradeAppearanceMissing then
table.insert(catalystUpgradeClassList, classID)
end
end
end
if #catalystClassList > 0 then
local classNames = {}
for _, classID in ipairs(catalystClassList) do
table.insert(classNames, classIDToName[classID])
end
tooltip:AddDoubleLine(CATALYST_MARKUP .. ' Catalyst missing for', table.concat(classNames, ', '))
end
if #catalystUpgradeClassList > 0 then
local classNames = {}
for _, classID in ipairs(catalystUpgradeClassList) do
table.insert(classNames, classIDToName[classID])
end
tooltip:AddDoubleLine(
CATALYST_UPGRADE_MARKUP .. ' Catalyst & Upgrade missing for',
table.concat(classNames, ', ')
)
end
end
end
--- @return boolean isCacheWarmedUp
--- @return number progress # a number between 0 and 1, where 1 means caching has finished
function TUM:IsCacheWarmedUp()
if not TransmogUpgradeMasterCacheDB and not self.itemSourceMapInitialized then
return false, self.itemSourceMapProgress / self.itemSourceMapTotal
end
return true, 1
end
--- @return boolean loading
function TUM:ShowLoadingTooltipIfLoading(tooltip)
local warmedUp, progress = self:IsCacheWarmedUp()
if warmedUp then return false end
local text = string.format("TransmogUpgradeMaster is loading (%.0f%%)", progress * 100)
tooltip:AddLine(text, nil, nil, nil, true)
return true
end
--- @param itemID number
--- @return nil|table<TUM_Tier, number>
function TUM:GetSourceIDsForItemID(itemID)
return self.data.itemSourceIDs[itemID] or self.itemSourceIDs[itemID]
end
--- @param itemLink string
--- @param seasonID TUM_Season
--- @return TUM_Tier? tier # nil if the tier cannot be determined from itemlink
function TUM:GetTierFromUpgradeTrackBonusID(itemLink, seasonID)
local _, data = LinkUtil.ExtractLink(itemLink);
local parts = strsplittable(':', data);
local upgradeTrackBonusIDs = constants.upgradeTrackBonusIDs;
local numBonusIDs = tonumber(parts[BONUS_ID_OFFSET]) or 0;
for index = (BONUS_ID_OFFSET + 1), (BONUS_ID_OFFSET + numBonusIDs) do
local bonusID = tonumber(parts[index]);
local bonusIDInfo = upgradeTrackBonusIDs[bonusID];
if bonusIDInfo then
local breakpoint = constants.upgradeTransmogBreakpoints[seasonID];
return bonusIDInfo.level < breakpoint and bonusIDInfo.track or math.min(constants.tiers.mythic, bonusIDInfo.track + 1);
end
end
end
--- @param itemLink string
--- @param classID number # defaults to the player's class
--- @return boolean
function TUM:IsValidArmorTypeForClass(itemLink, classID)
local invType, _, itemClassID, itemSubClassID = select(4, C_Item.GetItemInfoInstant(itemLink))
return invType == "INVTYPE_CLOAK" or (itemClassID == Enum.ItemClass.Armor and itemSubClassID == constants.classArmorTypeMap[classID])
end
function TUM:IsCatalystSlot(slot)
return constants.catalystSlots[slot] or false
end
function TUM:IsItemCatalysed(itemID)
return not not self.catalystItemByID[itemID]
end
--- @param sourceID number
--- @return boolean|TUM_LearnedFromOtherItem
function TUM:IsSourceIDCollected(sourceID)
local sourceInfo = C_TransmogCollection.GetSourceInfo(sourceID)
if not sourceInfo then
return false
end
if sourceInfo.isCollected then
return true
end
local sourceIDs = C_TransmogCollection.GetAllAppearanceSources(sourceInfo.visualID);
if sourceIDs and #sourceIDs > 0 then
for _, id in ipairs(sourceIDs) do
local info = C_TransmogCollection.GetSourceInfo(id)
if info and info.isCollected then
return LEARNED_FROM_OTHER_ITEM
end
end
end
return false
end
--- @param seasonID number
--- @param slot Enum.InventoryType
--- @param tier TUM_Tier
--- @return boolean|nil|TUM_LearnedFromOtherItem
function TUM:IsCatalystItemCollected(seasonID, classID, slot, tier)
if not self.catalystItems[seasonID] or not self.catalystItems[seasonID][classID] then
return nil
end
local itemID = self.catalystItems[seasonID][classID][slot]
if not itemID then return nil end
local sourceIDs = self:GetSourceIDsForItemID(itemID)
if not sourceIDs or not sourceIDs[tier] then
return nil
end
return self:IsSourceIDCollected(sourceIDs[tier])
end
--- @param transmogSetID number
--- @param slot number # Enum.InventoryType
--- @return boolean|nil|TUM_LearnedFromOtherItem
function TUM:IsSetItemCollected(transmogSetID, slot)
if self.setSourceIDs[transmogSetID] then
local sourceID = self.setSourceIDs[transmogSetID][slot]
return sourceID and self:IsSourceIDCollected(sourceID) or false
end
local sources = C_TransmogSets.GetSourcesForSlot(transmogSetID, slot)
local fromOtherItem = false
for _, slotSourceInfo in ipairs(sources) do
if slotSourceInfo.isCollected then
return true
elseif self:IsSourceIDCollected(slotSourceInfo.sourceID) == LEARNED_FROM_OTHER_ITEM then
fromOtherItem = true
end
end
return fromOtherItem and LEARNED_FROM_OTHER_ITEM or false
end
function TUM:HandleCatalystInteraction()
local isConversion = ItemInteractionFrame:GetInteractionType() == Enum.UIItemInteractionType.ItemConversion
local isFree = not ItemInteractionFrame:UsesCharges() and not ItemInteractionFrame:CostsCurrency()
if not isConversion then return end
local setting = self.db.autoConfirmCatalyst
if
setting == self.Config.autoConfirmCatalystOptions.always
or (setting == self.Config.autoConfirmCatalystOptions.previousSeason and isFree)
then
ItemInteractionFrame:CompleteItemInteraction()
end
end
function TUM:RegisterIntoBaganator()
if not C_AddOns.IsAddOnLoaded("Baganator") or not Baganator or not Baganator.API then return; end
local function setUpgrade(icon)
icon:SetAtlas(UPGRADE_ATLAS);
return true;
end
local function setCatalyst(icon)
icon:SetAtlas(CATALYST_ATLAS);
return true;
end
local function setCatalystUpgrade(icon)
icon:SetTexture(CATALYST_UPGRADE_TEXTURE);
return true;
end
local function returnFalse() return false; end
local cache = {};
--- @param icon Texture
--- @param itemDetails BaganatorItemDetails
--- @return boolean? shouldDisplay # return nil if not enough info is known
local function onUpdate(icon, itemDetails)
local size = self.db.baganatorIconSize;
icon:SetSize(size, size);
if cache[itemDetails.itemLink] ~= nil then
return cache[itemDetails.itemLink](icon);
end
if not C_Item.IsItemDataCachedByID(itemDetails.itemID) then
C_Item.RequestLoadItemDataByID(itemDetails.itemID);
return;
end
if not self:IsCacheWarmedUp() then return; end
local results = securecallfunction(self.IsAppearanceMissing, self, itemDetails.itemLink);
local catalyse, upgrade = false, false;
if results and results.canCatalyse and results.catalystAppearanceMissing then
catalyse = true;
end
if results and results.canUpgrade and results.upgradeAppearanceMissing then
upgrade = true;
end
if results and results.canUpgrade and results.catalystUpgradeAppearanceMissing then
catalyse = true;
upgrade = true;
end
if catalyse and upgrade then
cache[itemDetails.itemLink] = setCatalystUpgrade;
elseif catalyse then
cache[itemDetails.itemLink] = setCatalyst;
elseif upgrade then
cache[itemDetails.itemLink] = setUpgrade;
else
cache[itemDetails.itemLink] = returnFalse;
end
return cache[itemDetails.itemLink](icon);
end
if NumyProfiler then
onUpdate = NumyProfiler:Wrap(name, 'Core', 'BaganatorCornerWidget_OnUpdate', onUpdate);
end
Baganator.API.RegisterCornerWidget(
"Transmog Upgrade Master",
"TransmogUpgradeMaster",
onUpdate,
function(itemButton)
local tex = itemButton:CreateTexture(nil, "OVERLAY");
local size = self.db.baganatorIconSize;
tex:SetSize(size, size);
return tex;
end,
{ corner = "bottom_right", priority = 1 }
)
EventRegistry:RegisterFrameEventAndCallback("TRANSMOG_COLLECTION_UPDATED", function()
cache = {};
end);
end