-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTradeskillInfo.lua
1963 lines (1636 loc) · 57.1 KB
/
TradeskillInfo.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 L = LibStub("AceLocale-3.0"):GetLocale("TradeSkillInfo")
TradeskillInfo = LibStub("AceAddon-3.0"):NewAddon("TradeSkillInfo", "AceConsole-3.0", "AceEvent-3.0", "AceHook-3.0", "AceTimer-3.0")
TradeskillInfo.version = GetAddOnMetadata("TradeSkillInfo", "Version")
BINDING_HEADER_TRADESKILLINFO = "TradeSkillInfo"
BINDING_NAME_TOGGLE_TRADESKILLINFO = "Toggle TradeSkillInfo Browser"
BINDING_NAME_TOGGLE_TRADESKILLINFOCONFIG = "Show TradeSkillInfo Options Window"
TradeskillInfo.vars = {}
TradeskillInfo.vars.combines = {}
TradeskillInfo.vars.MouseButtons = { "LeftButton", "RightButton" }
TradeskillInfo.vars.ShiftKeys = { IsShiftKeyDown, IsControlKeyDown, IsAltKeyDown }
TradeskillInfo.vars.difficultyLevel = { ["trivial"] = 1, ["easy"] = 2, ["medium"] = 3, ["optimal"] = 4 }
TradeskillInfo.vars.diffcolors = { "|cff777777", "|cff33bb33", "|cffffff00", "|cffff7733", "|cffffffff" } -- trivial, easy, medium, optimal, header
local LDB = LibStub("LibDataBroker-1.1", true)
local DBI = LibStub("LibDBIcon-1.0", true)
local object
if LDB then
object = LDB:NewDataObject("TradeSkillInfo")
object.type = "launcher"
object.text = "TradeSkillInfo"
object.icon = "Interface\\Icons\\INV_Elemental_SpiritOfHarmony_2"
object.OnClick = function(_, button)
if button == "LeftButton" then
TradeskillInfo:UI_Toggle()
elseif button == "RightButton" then
TradeskillInfo:ConfigToggle()
end
end
object.OnTooltipShow = function(tooltip)
tooltip:AddLine("TradeSkillInfo")
tooltip:AddLine(L["Left Click"] .. ": " .. L["Open main window"] .. ".", 0, 1, 0)
tooltip:AddLine(L["Right Click"] .. ": " .. L["Open configuration window"] .. ".", 0, 1, 0)
end
end
local function getIdFromLink(link)
if not link then return end
-- local _, _, id,name = strfind(link, "|Hitem:(%d+):.+%[(.+)%]")
local _, _, id = strfind(link, "item:(%d+):")
if not id then
-- local _, _, id, name = strfind(link, "|Henchant:(%d+)|h%[(.+)%]")
local _, _, id = strfind(link, "enchant:(%d+)")
if id then
return -tonumber(id)
end
else
return tonumber(id)
end
end
local function getNameFromLink(link)
if not link then return end
local _, _, name = strfind(link, "|Hitem:.+%[(.+)%]")
return name
end
local function getItemLink(id, combineName)
if id > 0 then
local _, itemLink, itemQuality, _, _, _, _, _, _, itemTexture = GetItemInfo(id)
if itemLink then
-- local _, _, _, hexColor = GetItemQualityColor(itemQuality)
return itemLink, itemQuality, "item:"..id..":0:0:0:0:0:0:0", itemTexture
else
-- local _, _, _, hexColor = GetItemQualityColor(1)
return nil, 1, "item:"..id..":0:0:0:0:0:0:0", "Interface\\Icons\\INV_Misc_QuestionMark.blp"
end
else
local spellName, _, spellTexture = GetSpellInfo(-id)
if not spellTexture then
spellTexture = "Interface\\Icons\\Spell_Holy_GreaterHeal.blp"
end
if not spellName and combineName then
spellName = combineName
end
if spellName then
local _, _, _, hexColor = GetItemQualityColor(1)
return hexColor.."|Henchant:"..-id.."|h["..spellName.."]|h|r", 1, "enchant:"..-id, spellTexture
else
return nil, 1, "enchant:"..-id, spellTexture
end
end
end
local GetTradeSkillLine
local IsTradeSkillReady
local IsTradeSkillLinked
local IsTradeSkillGuild
local IsNPCCrafting
function TradeskillInfo:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("TradeSkillInfoDB", {
profile = {
ShowSkillLevel = true,
ShowSkillProfit = true,
ShowSkillAuctioneerProfit = true,
TooltipSource = true,
TooltipRecipeSource = true,
TooltipRecipePrice = true,
TooltipUsedIn = true,
TooltipUsableBy = true,
TooltipColorUsableBy = true,
TooltipKnownBy = { R = true, A = true, B = true, D = true, E = true, J = true, L = true, T = true, W = false, Z = true, Y = true, I = true },
TooltipLearnableBy = { R = true, A = true, B = true, D = true, E = true, J = true, L = true, T = true, W = false, Z = true, Y = true, I = true },
TooltipAvailableTo = { R = true, A = true, B = true, D = true, E = true, J = true, L = true, T = true, W = false, Z = true, Y = true, I = true },
TooltipMarketValue = true,
TooltipID = false,
TooltipStack = false,
ColorSource = { r = 0.75, g = 0.75, b = 0.25 },
ColorRecipeSource = { r = 0.75, g = 0.75, b = 0.25 },
ColorRecipePrice = { r = 1, g = 1, b = 1 },
ColorUsedIn = { r = 1, g = 1, b = 1 },
ColorUsableBy = { r = 1, g = 1, b = 1 },
ColorKnownBy = { r = 1, g = 0, b = 0 },
ColorLearnableBy = { r = 0.25, g = 0.75, b = 0.25 },
ColorAvailableTo = { r = 1, g = 0.5, b = 0.25 },
ColorID = { r = 0.75, g = 0.5, b = 0.5 },
ColorStack = { r = 1, g = 1, b = 1 },
ColorMarketValue = { r = 0.8, g = 0.9, b = 0 },
ColorAHRecipes = true,
ColorMerchantRecipes = true,
ColorBagRecipes = true,
AHColorLearnable = { r = 1, g = 1, b = 1 },
AHColorAltLearnable = { r = 0, g = 1, b = 0 },
AHColorWillLearn = { r = 1, g = 0.5, b = 0.15 },
AHColorAltWillLearn = { r = 1, g = 1, b = 0 },
AHColorKnown = { r = 0, g = 0, b = 1 },
AHColorUnavailable = { r = 1, g = 0, b = 0 },
RecipesOnly = false,
QuickSearch = false,
SearchMouseButton = 2,
SearchShiftKey = 2,
SavePosition = true,
FrameStrata = 1,
UIScale = 1,
-- minimap options
hide = false,
DebugMode = false,
},
realm = {
["*"] = { -- stores all known characters
knownRecipes = {}, skills = {}, skillIgnored = {}
},
},
}, "Default")
-- disable on Classic.
if WOW_PROJECT_ID == WOW_PROJECT_CLASSIC then
self:Print("WoW Classic detected. TradeSkillInfo is designed for Retail servers and will not work on Classic servers. Please download TradeSkillInfo_Classic when it becomes available.")
self:SetEnabledState(false)
return
else
GetTradeSkillLine = C_TradeSkillUI.GetTradeSkillLine
IsTradeSkillReady = C_TradeSkillUI.IsTradeSkillReady
IsTradeSkillLinked = C_TradeSkillUI.IsTradeSkillLinked
IsTradeSkillGuild = C_TradeSkillUI.IsTradeSkillGuild
IsNPCCrafting = C_TradeSkillUI.IsNPCCrafting
end
self:RegisterChatCommand("tsi", "ChatCommand")
self:RegisterChatCommand("tradeskillinfo", "ChatCommand")
self:BuildWhereUsed()
end
function TradeskillInfo:OnEnable()
self.vars.playername = UnitName("player")
self:PopulateProfessionNames()
self:HookTradeSkillUI()
self:SecureHook("ContainerFrameItemButton_OnModifiedClick")
self:SecureHook("BankFrameItemButtonGeneric_OnModifiedClick")
self:SecureHook("MerchantItemButton_OnModifiedClick")
self:SecureHook("ChatFrame_OnHyperlinkShow")
self:HookAuctionUI()
self:RegisterEvent("TRADE_SKILL_DATA_SOURCE_CHANGED", "OnTradeSkillDataSourceChanged")
self:RegisterEvent("CHAT_MSG_SKILL", "OnSkillUpdate")
self:RegisterEvent("ADDON_LOADED", "OnAddonLoaded")
-- Merchant/bank/bag colouring
self:SecureHook("MerchantFrame_UpdateMerchantInfo")
self:SecureHook("ContainerFrame_UpdateCooldown")
self:SecureHook("BankFrameItemButton_Update")
local tooltipLib = LibStub("LibExtraTip-1", true)
if tooltipLib then
tooltipLib:AddCallback({type = "item", callback = TradeskillInfo.TooltipHandler})
tooltipLib:RegisterTooltip(GameTooltip)
tooltipLib:RegisterTooltip(ItemRefTooltip)
tooltipLib:RegisterTooltip(BattlePetTooltip)
tooltipLib:RegisterTooltip(FloatingBattlePetTooltip)
end
LibStub("AceConfig-3.0"):RegisterOptionsTable("TradeSkillInfo", TradeskillInfo.CreateConfig)
self.OptionsPanel = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("TradeSkillInfo", "TradeSkillInfo")
self:ScheduleTimer("OnSkillUpdate", 1)
if DBI then
DBI:Register("TradeSkillInfo", object, self.db.profile)
end
if self.db.profile.DebugMode then
self:FindSkillsUnknownInCombines();
end
end
function TradeskillInfo:OnTradeSkillDataSourceChanged()
if IsTradeSkillReady() then
if not IsTradeSkillLinked() and not IsTradeSkillGuild() and not IsNPCCrafting() and GetTradeSkillLine() ~= "UNKNOWN" then
self:ScheduleTimer("UpdateKnownRecipes", 1)
end
end
end
function TradeskillInfo:OnSkillUpdate()
if not self.UpdateInProgress then
self.UpdateInProgress = true
self:UpdateSkills()
self:UpdateKnownRecipes()
self.UpdateInProgress = false
end
end
function TradeskillInfo:OnAddonLoaded(_, addon)
if addon == "Blizzard_AuctionUI" or addon == "TradeSkillMaster" then
self:HookAuctionUI()
elseif addon == "Blizzard_TradeSkillUI" or addon == "AdvancedTradeSkillWindow" then
self:HookTradeSkillUI()
elseif addon == "Blizzard_GuildBankUI" then
self:SecureHook("GuildBankFrame_Update")
end
end
function TradeskillInfo:ChatCommand(input)
input = input:lower():trim()
if input == "config" then self:ConfigToggle()
else self:UI_Toggle() end
end
function TradeskillInfo:LoadAndCreateConfig()
if TradeskillInfo:LoadUI() then
return TradeskillInfo:CreateConfig()
end
end
local hookedAuctionUi = false
function TradeskillInfo:HookAuctionUI()
if AuctionFrame and not hookedAuctionUi then
for j=1,8 do
local button = _G["BrowseButton"..j.."Item"]
self:HookScript(button,"OnClick","AuctionItemButton_OnClick")
button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
end
self:SecureHook("AuctionFrameBrowse_Update")
hookedAuctionUi = true
end
if TSMAPI and TSMAPI.GUI and TSMAPI.GUI.BuildFrame and (not self:IsHooked(TSMAPI.GUI, "BuildFrame")) then
self:RawHook(TSMAPI.GUI, "BuildFrame", "TsmBuildFrame")
end
-- if Auc-Advanced and not self:IsHooked(Auc-Advanced, "lib.ListUpdate")
-- self:Hook (Auc-Advanced, "lib.ListUpdate")
-- end
end
function TradeskillInfo:GetExtraItemDetailText(_, _, skill_index)
--Thanks to nogudnik for providing this code!
local _, skillType = GetTradeSkillInfo(skill_index)
if ( skillType == "header" or skillType == "subheader" ) then return end
if ( skill_index > GetNumTradeSkills() ) then return end
local link = GetTradeSkillItemLink(skill_index)
local itemId = getIdFromLink(link)
return self:GetExtraItemDataText(itemId,
self:ShowingSkillProfit(),
self:ShowingSkillLevel(),
self:ShowingSkillAuctioneerProfit())
end
function TradeskillInfo:GetExtraItemDataText(itemId, showVendorProfit, showDifficulty, showAuctioneerProfit)
local text
if self:CombineExists(itemId) then
if showAuctioneerProfit then
-- Insert item value and reagent costs from auctioneer
local value,cost,profit = self:GetCombineAuctioneerCost(itemId)
text = string.format("A: %s - %s = %s",
self:GetMoneyString(value),
self:GetMoneyString(cost),
self:GetMoneyString(profit))
end
local sep = ""
if showVendorProfit then
-- Insert item value and reagent costs
local value,cost,profit = self:GetCombineCost(itemId)
if text then sep = "\n" else text = "" end
text = text .. sep ..
string.format("V: %s - %s = %s",
self:GetMoneyString(value),
self:GetMoneyString(cost),
self:GetMoneyString(profit))
end
if showDifficulty then
if text then sep = "\n" else text = "" end
text = text .. sep .. self:GetColoredDifficulty(itemId)
end
end
return text
end
function TradeskillInfo:HookTradeSkillUI()
if TradeSkillFrame and not self:IsHooked("TradeSkillFrame_SetSelection") then
self:SecureHook(TradeSkillFrame.DetailsFrame, "RefreshDisplay", "TradeSkillFrame_SetSelection")
-- add our text fields
local fsSkillText = TradeSkillFrame.DetailsFrame:CreateFontString("TradeskillInfoSkillText", "BACKGROUND", "GameFontHighlightSmall")
local fsProfitText = TradeSkillFrame.DetailsFrame:CreateFontString("TradeskillInfoProfitText", "BACKGROUND", "GameFontHighlightSmall")
fsSkillText:SetPoint("TOPLEFT", TradeSkillFrame.DetailsFrame.Contents, "BOTTOMLEFT", 10, -10)
fsProfitText:SetPoint("TOPLEFT", fsSkillText, "BOTTOMLEFT", -2, -2)
end
if IsAddOnLoaded("AdvancedTradeSkillWindow") and not self:IsHooked("ATSWFrame_SetSelection") then
self:SecureHook("ATSWFrame_SetSelection")
-- add our text fields
local fsLabel = ATSWFrame:CreateFontString("TradeskillInfoATSWSkillLabel", "OVERLAY", "GameFontHighlightSmall")
local fsText = ATSWFrame:CreateFontString("TradeskillInfoATSWSkillText", "OVERLAY", "GameFontHighlightSmall")
fsLabel:SetPoint("TOPLEFT", ATSWSkillCooldown, "BOTTOMLEFT")
fsText:SetPoint("TOPLEFT", fsLabel, "TOPRIGHT")
end
end
function TradeskillInfo:UpdateKnownRecipes()
if not self.processingUpdates then
self.processingUpdates = true
self:UpdateKnownTradeRecipes()
self.processingUpdates = false
end
end
function TradeskillInfo:UpdateSkills()
local prof1, prof2, _, _, cook = GetProfessions()
local userData = self.db.realm[self.vars.playername]
local name, rank
if prof1 then
name, _, rank = GetProfessionInfo(prof1)
userData.skills[self.vars.skillnames[name]] = rank
end
if prof2 then
name, _, rank = GetProfessionInfo(prof2)
userData.skills[self.vars.skillnames[name]] = rank
end
if cook then
name, _, rank = GetProfessionInfo(cook)
userData.skills[self.vars.skillnames[name]] = rank
end
end
function TradeskillInfo:UpdateKnownTradeRecipes(startLine, endLine)
local recipes = C_TradeSkillUI.GetAllRecipeIDs()
if not recipes or #recipes == 0 then return end
for _, recipeID in pairs(recipes) do
local info = C_TradeSkillUI.GetRecipeInfo(recipeID)
if info.learned then
-- for key, value in pairs(info) do
-- self:Print(key, value)
-- end
self.db.realm[self.vars.playername].knownRecipes[recipeID] = self.vars.difficultyLevel[info.difficulty]
end
end
--[[
local numSkills = GetNumTradeSkills()
if not startLine then
startLine = 1
endLine = numSkills
end
for i = startLine, endLine do
local _, itemType, _, isExpanded = GetTradeSkillInfo(i)
if (itemType == "header" or itemType == "subheader") and not isExpanded then
ExpandTradeSkillSubClass(i)
self:UpdateKnownTradeRecipes(i + 1, i + GetNumTradeSkills() - numSkills)
CollapseTradeSkillSubClass(i)
elseif (itemType ~= "header" and itemType ~= "subheader") then
local link = GetTradeSkillRecipeLink(i)
if link then
local _, _, id = strfind(link, "enchant:(%d+)")
id = tonumber(id)
self.db.realm[self.vars.playername].knownRecipes[id] = self.vars.difficultyLevel[itemType]
end
end
end
]]
if self.db.profile.DebugMode then
self:Print("Scan complete. ", #recipes, " recipes scanned.")
end
end
----------------------------------------------------------------------
-- TradeSkillFrame Hook to display recipe skill level and cost/profit
----------------------------------------------------------------------
function TradeskillInfo:TradeSkillFrame_SetSelection(id)
if not IsTradeSkillReady() or IsNPCCrafting() then return end
if not TradeSkillFrame.DetailsFrame.selectedRecipeID then return end
local recipeInfo = C_TradeSkillUI.GetRecipeInfo(TradeSkillFrame.DetailsFrame.selectedRecipeID)
if not recipeInfo then return end
local spellId = recipeInfo.recipeID
local appendText = ""
if self:CombineExists(spellId) then
if self:ShowingSkillLevel() then
-- insert skill required
appendText = appendText .. "|cFFFFD200" .. L["Skill Level"] .. ": |r" .. self:GetColoredDifficulty(spellId) .. "|n"
end
if self:ShowingSkillProfit() then
local profitLabel
local value, cost, profit
if self:ShowingSkillAuctioneerProfit() then
value,cost,profit = self:GetCombineAuctioneerCost(spellId)
profitLabel = L["Auction"]
else
value,cost,profit = self:GetCombineCost(spellId)
profitLabel = L["Vendor"]
end
-- insert item value and reagent costs
appendText = appendText .. "|cFFFFD200" .. profitLabel .. ": |r" .. string.format("%s - %s = %s", self:GetMoneyString(value), self:GetMoneyString(cost), self:GetMoneyString(profit))
end
-- no, I don't like this either.
local numReagents = C_TradeSkillUI.GetRecipeNumReagents(TradeSkillFrame.DetailsFrame.selectedRecipeID)
if numReagents > 0 then
TradeSkillFrame.DetailsFrame.Contents.SourceText:SetPoint("TOP", TradeSkillFrame.DetailsFrame.Contents.Reagents[numReagents], "BOTTOM", 0, -15)
else
TradeSkillFrame.DetailsFrame.Contents.SourceText:SetPoint("TOP", TradeSkillFrame.DetailsFrame.Contents.ReagentLabel, "TOP")
end
local origText = TradeSkillFrame.DetailsFrame.Contents.SourceText:GetText()
if not origText or #origText == 0 then
TradeSkillFrame.DetailsFrame.Contents.SourceText:SetText(appendText)
else
TradeSkillFrame.DetailsFrame.Contents.SourceText:SetText(origText .. "|n|n" .. appendText)
end
TradeSkillFrame.DetailsFrame.Contents.SourceText:Show()
end
end
function TradeskillInfo:ATSWFrame_SetSelection(id)
local skillName, skillType = GetTradeSkillInfo(id)
if not skillName then return end
if ( skillType == "header" or skillType == "subheader" ) then return end
if ( GetTradeSkillSelectionIndex() > GetNumTradeSkills() ) then return end
local link = GetTradeSkillItemLink(id)
local itemId = getIdFromLink(link)
if self:CombineExists(itemId) then
if self:ShowingSkillLevel() then
-- Insert skill required.
if TradeskillInfoATSWSkillLabel then
TradeskillInfoATSWSkillLabel:SetText(L["Skill Level"] .. ": ")
TradeskillInfoATSWSkillText:SetText(self:GetColoredDifficulty(itemId))
TradeskillInfoATSWSkillLabel:Show()
TradeskillInfoATSWSkillText:Show()
end
else
TradeskillInfoATSWSkillLabel:Hide()
TradeskillInfoATSWSkillText:Hide()
end
if self:ShowingSkillAuctioneerProfit() then
-- Insert item value and reagent costs
local value,cost,profit = self:GetCombineAuctioneerCost(itemId)
ATSWReagentLabel:SetText(string.format("%s %s - %s = %s", SPELL_REAGENTS,
self:GetMoneyString(value), self:GetMoneyString(cost), self:GetMoneyString(profit)))
elseif self:ShowingSkillProfit() then
-- Insert item value and reagent costs
local value,cost,profit = self:GetCombineCost(itemId)
ATSWReagentLabel:SetText(string.format("%s %s - %s = %s", SPELL_REAGENTS,
self:GetMoneyString(value), self:GetMoneyString(cost), self:GetMoneyString(profit)))
else
--ATSWReagentLabel:SetText(SPELL_REAGENTS)
end
end
end
----------------------------------------------------------------------
-- OnClick hooks
----------------------------------------------------------------------
function TradeskillInfo:ContainerFrameItemButton_OnModifiedClick(object, button)
local link = GetContainerItemLink(object:GetParent():GetID(), object:GetID())
if self:Item_OnClick(button, link) then return end
end
function TradeskillInfo:BankFrameItemButtonGeneric_OnModifiedClick(object, button)
local link = GetContainerItemLink(BANK_CONTAINER, object:GetID())
if self:Item_OnClick(button, link) then return end
end
function TradeskillInfo:MerchantItemButton_OnModifiedClick(object, button)
local link = GetMerchantItemLink(object:GetID())
if self:Item_OnClick(button, link) then return end
end
function TradeskillInfo:ChatFrame_OnHyperlinkShow(_, _, text, button)
if self:Item_OnClick(button, text) then return end
end
function TradeskillInfo:AuctionItemButton_OnClick(object, button)
local offset = FauxScrollFrame_GetOffset(BrowseScrollFrame)
local itemID = object:GetParent():GetID() + offset
local link = GetAuctionItemLink("list", itemID)
if self:Item_OnClick(button, link) then return end
self.hooks[object].OnClick(object, button)
end
function TradeskillInfo:Item_OnClick(button, link)
if not self:LoadUI(true) then return end
if not self.db.profile.QuickSearch then return end
if button == self.vars.MouseButtons[self.db.profile.SearchMouseButton] then
local accept = true
for i, func in ipairs(self.vars.ShiftKeys) do
if i == self.db.profile.SearchShiftKey then
accept = accept and func()
else
accept = accept and not func()
end
end
if accept then
local id = getIdFromLink(link)
if not self:ComponentExists(id) then return end
local name = getNameFromLink(link)
TradeskillInfoUI:SetSearchText("id="..id.." "..name)
TradeskillInfoFrame:Show()
end
end
end
function TradeskillInfo:GetMoneyString(value)
if not value then return "???" end
local neg = value < 0 and "-" or ""
local gold = floor(math.abs(value) / 10000)
local silver = mod(floor(math.abs(value) / 100), 100)
local copper = mod(floor(math.abs(value)), 100)
if gold ~= 0 then
return format("%s%dg %ds %dc", neg, gold, silver, copper)
elseif silver ~= 0 then
return format("%s%ds %dc", neg, silver, copper)
else
return format("%s%dc", neg, copper)
end
end
----------------------------------------------------------------------
-- Combine support functions
----------------------------------------------------------------------
function TradeskillInfo:Combines()
return pairs(self.vars.combines)
end
function TradeskillInfo:CombineExists(id)
if id and self.vars.combines[id] then
return true
end
end
function TradeskillInfo:GetCombine(id)
if not self:CombineExists(id) then return end
local combine = {}
local _, _, item, skill, spec, level, _, _, _, _, recipe, yield = string.find(self.vars.combines[id], "-?(%d*)|?(%u)(%l*)(%d+)/?(%d*)/?(%d*)/?(%d*)|([^|]+)[|]?(%d*)[|]?([^|]*)[|]?(%d*)")
combine.skill = skill
combine.spec = spec
combine.level = tonumber(level)
if recipe ~= "" then combine.recipe = tonumber(recipe) end
if yield ~= "" then combine.yield = tonumber(yield) else combine.yield = 1 end
if item ~= "" then combine.item = tonumber(item) end
if combine.item then
combine.link, combine.quality, combine.itemString, combine.texture = getItemLink(combine.item)
else
combine.link, combine.quality, combine.itemString, combine.texture = getItemLink(id)
end
combine.name = self:GetCombineName(id)
return combine
end
local spellCache = {}
function TradeskillInfo:GetCombineName(id)
local name
if not spellCache[id] then
spellCache[id] = GetSpellInfo(id)
end
return spellCache[id] or tostring(id)
end
function TradeskillInfo:GetCombineEnchantId(id)
-- DELETE ME --
return tonumber(id)
end
function TradeskillInfo:GetCombineLevel(id)
if not self:CombineExists(id) then return 0 end
local _,_,level = string.find(self.vars.combines[id],"-?%d*|?%a+(%d+)")
return tonumber(level)
end
function TradeskillInfo:GetCombineDifficulty(id)
if not self:CombineExists(id) then return 0 end
local _,_,l1,l2,l3,l4 = string.find(self.vars.combines[id],"-?%d*|?%a+(%d+)/?(%d*)/?(%d*)/?(%d*)")
if l2 == "" then l2=nil end
if l3 == "" then l3=nil end
if l4 == "" then l4=nil end
return {l1, l2, l3, l4}
end
function TradeskillInfo:GetCombineSkill(id)
if not self:CombineExists(id) then return end
local _,_,skill,spec,level = string.find(self.vars.combines[id],"-?%d*|?(%u)(%l*)(%d+)")
if not spec then spec = "" end
return skill,spec,tonumber(level)
end
function TradeskillInfo:GetCombineRecipe(id)
if not self:CombineExists(id) then return end
local _, _, recipe = string.find(self.vars.combines[id],"-?%d*|?[^|]+|[^|]+[|]?(%d*)")
if recipe and recipe ~= "" then recipe = tonumber(recipe) end
if not self.vars.recipes[recipe] then recipe = "" end
return recipe
end
function TradeskillInfo:GetCombineYield(id)
if not self:CombineExists(id) then return end
local _, _, yield = string.find(self.vars.combines[id],"-?%d*|[A-Z]?[^|]+|[^|]+|%d*|(%d*)")
if yield and yield ~= "" then yield = tonumber(yield) else yield = 1 end
return yield
end
function TradeskillInfo:GetCombineItem(id)
if not self:CombineExists(id) then return end
local _, _, item = string.find(self.vars.combines[id],"-?(%d*)|?[^|]+|[^|]+[|]?%d*[|]?[^|]*[|]?%d*")
if item and item ~= "" then item = tonumber(item) else item = nil end
return item
end
function TradeskillInfo:GetCombineComponents(id, getVendorPrice, getAuctioneerPrice)
if not self:CombineExists(id) then return end
local components = {}
local _, _, compstring = string.find(self.vars.combines[id],"-?%d*|?[^|]+|([^|]+)")
for s in string.gmatch(compstring,"%S+") do
local c = {}
_,_,c.id,c.num = string.find(s,"(%d+):(%d+)")
c.id = tonumber(c.id) or tonumber(s)
c.num = tonumber(c.num) or 1
c.name,c.cost,c.source,c.aucMvCost,c.aucMvSeen = self:GetComponent(c.id, getVendorPrice, getAuctioneerPrice)
c.link, c.quality, c.itemString, c.texture = getItemLink(c.id)
table.insert(components,c)
if self.db.profile.DebugMode and not c.name then
self:Print("Unknown combine component: " .. c.id);
end
end
return components
end
function TradeskillInfo:GetCombineDescription(id)
if id < 0 then return GetSpellDescription(-id) end
end
function TradeskillInfo:GetCombineTexture(id)
if not self:CombineExists(id) then return end
local _, combineLink,combineItemString,combineTexture
local item = self:GetCombineItem(id)
if item and item ~= "" then
combineLink, _, combineItemString, combineTexture = getItemLink(tonumber(item))
elseif id < 0 then
local combineName = self:GetCombineName(id)
combineLink, _, combineItemString, combineTexture = getItemLink(id, combineName)
else
combineLink, _, combineItemString, combineTexture = getItemLink(id)
end
return combineTexture, combineLink, combineItemString
end
function TradeskillInfo:GetCombineAvailability(id)
if not self:CombineExists(id) then return end
local player,alt = 0,0
-- 0 = Unavailable, 1 = known, 2 = learnable, 3 = will be able to learn
local combineSkill,combineSpec,combineLevel = self:GetCombineSkill(id)
local playerSkillLevel = self:GetCharSkillLevel(self.vars.playername,combineSkill)
local playerSpec = self:GetCharSkillLevel(self.vars.playername,combineSpec)
if playerSkillLevel and (combineSpec=="" or playerSpec) then
if self:IsCombineKnowByChar(self.vars.playername,id) then
player = 1
elseif playerSkillLevel >= combineLevel then
player = 2
else
player = 3
end
end
for name in pairs(self.db.realm) do
local ignored = TradeskillInfo:IsSkillIgnoredForChar(name, combineSkill)
if name ~= self.vars.playername and not ignored then
local skillLevel = self:GetCharSkillLevel(name,combineSkill)
local charSpec = self:GetCharSkillLevel(name,combineSpec)
if skillLevel and (combineSpec=="" or charSpec) then
if alt <= 1 and self:IsCombineKnowByChar(name,id) then
-- Known by alt has lowest priority
alt = 1
elseif skillLevel >= combineLevel then
-- Alt can learn has highest priority. Stop if we have one of these
alt = 2
break
else
-- Alt will be able to learn: keep searching for alts who can learn
alt = 3
end
end
end
end
return player,alt
end
function TradeskillInfo:GetColoredDifficulty(id)
local diff = self:GetCombineDifficulty(id)
local s = ""
if not diff then return end
-- assume l2, l3, l4 are either all set, or all unset
if #diff > 1 then
for i, _ in ipairs(diff) do
if i == 1 then
s = self.vars.diffcolors[5-i]..diff[i].."|r"
else
s = s.."/"..self.vars.diffcolors[5-i]..diff[i].."|r"
end
end
else
s = "skill("..diff[1]..")"
end
return s
end
function TradeskillInfo:GetCombineCost(id)
if not self:CombineExists(id) then return end
local components = self:GetCombineComponents(id, true)
local value = 0
local item = self:GetCombineItem(id)
local yield = self:GetCombineYield(id)
if item then id = item end
if id > 0 then
value = select(2, self:GetComponent(id, true)) or 0
if yield > 1 then
value = value * yield
end
end
local cost = 0
for _, c in ipairs(components) do
cost = cost + ((c.cost or 0) * c.num)
end
return value, cost, value - cost
end
function TradeskillInfo:GetCombineAuctioneerCost(id)
if not self:CombineExists(id) then return end
if not (AucAdvanced and AucAdvanced.API or GetAuctionBuyout) then return end
local components = self:GetCombineComponents(id, false, true)
local value = 0
local item = self:GetCombineItem(id)
local yield = self:GetCombineYield(id)
if item then id = item end
if id > 0 then
value = select(4, self:GetComponent(id, false, true)) or 0
if yield > 1 then
value = value * yield
end
end
local cost = 0
for _, c in ipairs(components) do
cost = cost + ((c.aucMvCost or 0) * c.num)
end
return value, cost, value - cost
end
function TradeskillInfo:PrintCombine(id)
if not self:CombineExists(id) then return end
local combine = self:GetCombine(id)
local text = string.format("%s : %s(%d) %s ", combine.link or combine.name, self.vars.tradeskills[combine.skill], combine.level, self.vars.specializations[combine.spec] or "" )
for _, c in ipairs(combine.components) do
text = text .. string.format("x%d*%s ", c.num, c.link or c.name)
end
self:Print(text)
end
function TradeskillInfo:GetCombineFactionAvailable(id)
if not self:CombineExists(id) then return end
local rid = self:GetCombineRecipe(id)
if rid and rid~="" then
return self:GetRecipeFactionAvailable(rid)
end
return true
end
----------------------------------------------------------------------
-- Component support functions
----------------------------------------------------------------------
function TradeskillInfo:Components()
return pairs(self.vars.components)
end
function TradeskillInfo:ComponentExists(id)
if id and self.vars.components[id] then return true end
end
function TradeskillInfo:GetComponent(id, getVendorPrice, getAuctioneerPrice)
if not self:ComponentExists(id) then return end
local realId = id
local cost = 0
local name = GetItemInfo(realId)
if not name then name = "????" end
local _, _, source = string.find(self.vars.components[realId], "(%a+)")
-- if we need the price, get the value from Blizzard
if getVendorPrice or getAuctioneerPrice then
cost = select(11, GetItemInfo(realId)) or 0
end
-- if we have Auctioneer Advanced, also gather auction prices
local aucMvCost, aucMvSeen = 0, 0
if getAuctioneerPrice then
if AucAdvanced and AucAdvanced.API then
local itemLink = getItemLink(realId)
aucMvCost, aucMvSeen = AucAdvanced.API.GetMarketValue(itemLink)
-- if auctioneer has no idea, plug in vendor sell value
if not aucMvCost then aucMvCost = cost end
if not aucMvSeen then aucMvSeen = 0 end
elseif GetAuctionBuyout then
-- local itemLink = getItemLink(realId)
aucMvCost = GetAuctionBuyout(realId)
-- if auctioneer has no idea, plug in vendor sell value
if not aucMvCost then aucMvCost = cost end
end
end
return name, tonumber(cost), source, tonumber(aucMvCost), tonumber(aucMvSeen)
end
function TradeskillInfo:GetComponentSource(id, tooltip)
if not self:ComponentExists(id) then return end
local c = self.db.profile.ColorSource
local Ltext
local _, _, source = self:GetComponent(id)
local ret
for s in string.gmatch(source,"%u%l*") do
if self.vars.sources[s] then
local sourcename = self.vars.sources[s]
if ret then
Ltext = " "
ret = ret..", "..sourcename
else
Ltext = L["Source"]
ret = sourcename
end
if tooltip then
tooltip:AddDoubleLine(Ltext, sourcename, c.r, c.g, c.b, c.r, c.g, c.b/1.2)
end
else
self:Print(L["Found unknown source"],s)
end
end
return ret
end
----------------------------------------------------------------------
-- Where Used
----------------------------------------------------------------------
function TradeskillInfo:GetUsedIn(id, tooltip)
if not self.vars.whereUsedOverview[id] then return end
local overview
local Ltext, Rtext
local c = self.db.profile.ColorUsedIn
for s in string.gmatch(self.vars.whereUsedOverview[id],"%S+") do
local _,_,skill,num = string.find(s, "(%u+)(%d+)")
local skillname = self.vars.tradeskills[skill]
if skillname then
Rtext = skillname.." ("..tostring(num)..")"
if not overview then
overview = Rtext
Ltext = L["Used in"]
else
overview = overview..", "..Rtext
Ltext = " "
end
if tooltip then
tooltip:AddDoubleLine(Ltext, Rtext, c.r, c.g, c.b, c.r, c.g, c.b/1.2)