-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValuate.lua
More file actions
2861 lines (2524 loc) · 130 KB
/
Copy pathValuate.lua
File metadata and controls
2861 lines (2524 loc) · 130 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
-- Valuate - Stat Weight Calculator for WoW Ascension Bronzebeard
-- Interface: 30300 (WotLK 3.3.5a)
-- Addon namespace
Valuate = {}
-- Version info (read from .toc file automatically)
Valuate.version = GetAddOnMetadata("Valuate", "Version") or "Unknown"
Valuate.interface = 30300
-- Keybinding function that WoW calls when the key is pressed
-- This is registered in Bindings.xml and must be defined early
function ValuateToggleUI()
if Valuate and Valuate.ToggleUI then
Valuate:ToggleUI()
else
print("|cFFFF0000Valuate|r: UI not ready. Please try again or /reload.")
end
end
-- Equipment slot to inventory slot mapping (for upgrade comparison)
local EquipSlotToInvNumber = {
["INVTYPE_AMMO"] = { 0 },
["INVTYPE_HEAD"] = { 1 },
["INVTYPE_NECK"] = { 2 },
["INVTYPE_SHOULDER"] = { 3 },
["INVTYPE_BODY"] = { 4 },
["INVTYPE_CHEST"] = { 5 },
["INVTYPE_ROBE"] = { 5 },
["INVTYPE_WAIST"] = { 6 },
["INVTYPE_LEGS"] = { 7 },
["INVTYPE_FEET"] = { 8 },
["INVTYPE_WRIST"] = { 9 },
["INVTYPE_HAND"] = { 10 },
["INVTYPE_FINGER"] = { 11, 12 },
["INVTYPE_TRINKET"] = { 13, 14 },
["INVTYPE_CLOAK"] = { 15 },
["INVTYPE_WEAPON"] = { 16, 17 },
["INVTYPE_SHIELD"] = { 17 },
["INVTYPE_2HWEAPON"] = { 16 },
["INVTYPE_WEAPONMAINHAND"] = { 16 },
["INVTYPE_WEAPONOFFHAND"] = { 17 },
["INVTYPE_HOLDABLE"] = { 17 },
["INVTYPE_RANGED"] = { 18 },
["INVTYPE_THROWN"] = { 18 },
["INVTYPE_RANGEDRIGHT"] = { 18 },
["INVTYPE_RELIC"] = { 18 },
}
-- Slot ID to friendly name mapping
local SlotIdToName = {
[11] = "Ring 1",
[12] = "Ring 2",
[13] = "Trinket 1",
[14] = "Trinket 2",
[16] = "Main Hand",
[17] = "Off Hand",
}
-- Helper function to check if two weapon types are comparable
local function AreWeaponTypesComparable(hoverType, equippedType)
-- Handle nil or empty strings
if not hoverType or hoverType == "" or not equippedType or equippedType == "" then
return false
end
-- Shields never compare to weapons
if (hoverType == "INVTYPE_SHIELD" or hoverType == "INVTYPE_HOLDABLE") then
return (equippedType == "INVTYPE_SHIELD" or equippedType == "INVTYPE_HOLDABLE")
end
if (equippedType == "INVTYPE_SHIELD" or equippedType == "INVTYPE_HOLDABLE") then
return false
end
-- 2H weapons only compare to other 2H weapons
if hoverType == "INVTYPE_2HWEAPON" then
return equippedType == "INVTYPE_2HWEAPON"
end
if equippedType == "INVTYPE_2HWEAPON" then
return false
end
-- 1H generic weapons (INVTYPE_WEAPON) compare to other 1H generic weapons
if hoverType == "INVTYPE_WEAPON" then
return equippedType == "INVTYPE_WEAPON"
end
-- Mainhand-only weapons compare to mainhand-only and 1H generic in mainhand slot
if hoverType == "INVTYPE_WEAPONMAINHAND" then
return equippedType == "INVTYPE_WEAPONMAINHAND" or equippedType == "INVTYPE_WEAPON"
end
-- Offhand-only weapons compare to offhand-only and 1H generic in offhand slot
if hoverType == "INVTYPE_WEAPONOFFHAND" then
return equippedType == "INVTYPE_WEAPONOFFHAND" or equippedType == "INVTYPE_WEAPON"
end
-- For all other cases, types should match
return hoverType == equippedType
end
-- Frame for event handling
local frame = CreateFrame("Frame")
-- Auto-scan throttle
local lastAutoScanTime = 0
local AUTO_SCAN_THROTTLE = 2 -- seconds between auto-scans
-- Event handler
local function OnEvent(self, event, addonName, ...)
if event == "ADDON_LOADED" and addonName == "Valuate" then
-- Addon loaded, initialize
Valuate:Initialize()
elseif event == "PLAYER_ENTERING_WORLD" then
-- Player entered world, can do additional setup here
frame:UnregisterEvent("PLAYER_ENTERING_WORLD")
elseif event == "PLAYER_EQUIPMENT_CHANGED" then
-- Equipment changed, auto-scan with throttle
local currentTime = GetTime()
if currentTime - lastAutoScanTime >= AUTO_SCAN_THROTTLE then
lastAutoScanTime = currentTime
-- Scan on next frame to avoid doing it mid-combat or mid-swap
C_Timer.After(0.1, function()
if Valuate.ScanBestEquipment then
Valuate:ScanBestEquipment()
end
end)
end
end
end
-- ========================================
-- Per-Character Profile System
-- ========================================
-- Get unique character identifier (realm + character name)
function Valuate:GetCharacterKey()
local name = UnitName("player")
local realm = GetRealmName()
return realm .. "_" .. name
end
-- Get character-specific options table
function Valuate:GetOptions()
if not ValuateOptions then
ValuateOptions = {
debug = false,
decimalPlaces = 1,
rightAlign = false,
showScaleValue = true,
showBestFor = true,
chatMessages = true, -- Show chat messages (verbose mode)
showStartupMessage = true, -- Show "Valuate loaded" message
comparisonMode = "number",
characterWindowScale = nil,
showCharacterWindowDisplay = true,
minimapButtonHidden = false,
characterWindowDisplayMode = "total",
uiPosition = {},
normalizeDisplay = false,
showStatBreakdown = false,
}
end
return ValuateOptions
end
-- Get character-specific scales table
function Valuate:GetScales()
if not ValuateScales then
ValuateScales = {}
end
return ValuateScales
end
-- Get character-specific best equipment table
function Valuate:GetBestEquipment()
if not ValuateBestEquipment then
ValuateBestEquipment = {}
end
return ValuateBestEquipment
end
-- Migrate from account-wide to per-character SavedVariables
function Valuate:MigrateToPerCharacter()
-- Check if we need to migrate from account-wide to per-character
-- The SavedVariablesPerCharacter are now the main storage, but we may have
-- old account-wide data that needs to be copied to this character
-- Migration is automatic: WoW will create per-character versions of ValuateOptions
-- and ValuateScales when we use SavedVariablesPerCharacter in the .toc file
-- If this character doesn't have data yet, it will start with empty tables
-- For backwards compatibility, we don't need explicit migration code since
-- each character will get a fresh copy when logging in after the update
-- Just ensure the per-character data is initialized
if not ValuateOptions then
ValuateOptions = {}
end
if not ValuateScales then
ValuateScales = {}
end
end
-- Initialize function
function Valuate:Initialize()
-- Run migration first (if needed)
Valuate:MigrateToPerCharacter()
-- Get per-character options and initialize defaults if they don't exist
local options = Valuate:GetOptions()
-- Initialize default values for any missing options
if options.debug == nil then options.debug = false end
if options.decimalPlaces == nil then options.decimalPlaces = 1 end
if options.rightAlign == nil then options.rightAlign = false end
if options.showScaleValue == nil then options.showScaleValue = true end
if options.showBestFor == nil then options.showBestFor = true end
if options.chatMessages == nil then options.chatMessages = true end
if options.showStartupMessage == nil then options.showStartupMessage = true end
if options.comparisonMode == nil then options.comparisonMode = "number" end
if options.characterWindowScale == nil then options.characterWindowScale = nil end
if options.showCharacterWindowDisplay == nil then options.showCharacterWindowDisplay = true end
if options.minimapButtonHidden == nil then options.minimapButtonHidden = false end
if options.characterWindowDisplayMode == nil then options.characterWindowDisplayMode = "total" end
if options.uiPosition == nil then options.uiPosition = {} end
if options.normalizeDisplay == nil then options.normalizeDisplay = false end
if options.showStatBreakdown == nil then options.showStatBreakdown = false end
-- Get per-character scales
local scales = Valuate:GetScales()
-- Initialize best equipment storage
Valuate:GetBestEquipment()
-- Clean up orphaned best equipment data from deleted scales
Valuate:CleanupOrphanedBestEquipment()
-- Basic initialization
local options = self:GetOptions()
if options.showStartupMessage then
print("|cFF00FF00Valuate|r loaded (v" .. self.version .. ")")
end
-- Verify stat patterns loaded
if not ValuateStatPatterns then
print("|cFFFF0000Valuate|r: ERROR - StatDefinitions.lua failed to load!")
end
-- Hook into tooltips to parse scaled stats
Valuate:HookTooltips()
-- Create a default scale if none exist
if not next(scales) then
Valuate:CreateDefaultScale()
end
-- Initialize character window UI if available
if Valuate.InitializeCharacterWindowUI then
Valuate:InitializeCharacterWindowUI()
end
end
-- Creates a simple default scale for testing
function Valuate:CreateDefaultScale()
local defaultScale = {
DisplayName = "Default",
Color = "00FF00",
Visible = true,
Values = {
-- Example stat weights (users should customize these)
Strength = 1.0,
Agility = 1.0,
Stamina = 0.5,
Intellect = 1.0,
AttackPower = 1.0,
SpellPower = 1.0,
}
}
local scales = Valuate:GetScales()
scales["Default"] = defaultScale
end
-- ========================================
-- Stat Parsing System
-- ========================================
-- Helper function to strip color codes from text
local function StripColorCodes(text)
if not text then return "" end
-- Remove color codes like |cAARRGGBB| and |r|
text = string.gsub(text, "|c%x%x%x%x%x%x%x%x", "")
text = string.gsub(text, "|r", "")
return text
end
-- Creates or gets the hidden tooltip used for parsing
local function GetPrivateTooltip()
if not ValuatePrivateTooltip then
ValuatePrivateTooltip = CreateFrame("GameTooltip", "ValuatePrivateTooltip", nil, "GameTooltipTemplate")
ValuatePrivateTooltip:SetOwner(UIParent, "ANCHOR_NONE")
end
return ValuatePrivateTooltip
end
-- Expose GetPrivateTooltip for use in other files
function Valuate:GetPrivateTooltip()
return GetPrivateTooltip()
end
-- Parses stats from tooltip text using regex patterns
-- Returns a table with stat names as keys and values as numbers
function Valuate:ParseStatsFromTooltip(tooltipName, debug)
local stats = {}
local tooltip = _G[tooltipName]
if not tooltip then
return nil
end
-- Ensure stat patterns are loaded
if not ValuateStatPatterns then
print("|cFFFF0000Valuate|r: Stat patterns not loaded. Please reload UI.")
return nil
end
debug = debug or (Valuate:GetOptions().debug == true)
-- Track weapon slot type for assigning type-specific DPS/Speed
local weaponSlotType = nil -- IsMainHand, IsOffHand, IsOneHand, IsTwoHand, IsRanged
local isMelee = false
local isRanged = false
-- First pass: identify weapon/armor slot type and item level
for i = 1, tooltip:NumLines() do
local leftText = getglobal(tooltipName .. "TextLeft" .. i)
local rightText = getglobal(tooltipName .. "TextRight" .. i)
if leftText then
local rawText = leftText:GetText() or ""
local lineText = StripColorCodes(rawText)
-- Check for item level
local itemLevel = string.match(lineText, "^Item Level (%d+)$")
if itemLevel then
stats["ItemLevel"] = tonumber(itemLevel)
if debug then
print("|cFF00FF00[DEBUG]|r Item Level = " .. itemLevel)
end
end
-- Check for weapon slot type (appears on left side)
if ValuateWeaponSlotPatterns then
for _, patternData in ipairs(ValuateWeaponSlotPatterns) do
if string.match(lineText, patternData[1]) then
weaponSlotType = patternData[2]
stats[patternData[2]] = 1
if debug then
print("|cFF00FF00[DEBUG]|r Weapon slot: " .. patternData[2])
end
-- Determine if melee or ranged
if patternData[2] == "IsRanged" then
isRanged = true
else
isMelee = true
end
break
end
end
end
end
-- Check right side for weapon type (e.g., "Sword", "Axe")
if rightText then
local rawRightText = rightText:GetText() or ""
local rightLineText = StripColorCodes(rawRightText)
-- Check for weapon types
if ValuateWeaponTypePatterns then
for _, patternData in ipairs(ValuateWeaponTypePatterns) do
if string.match(rightLineText, patternData[1]) then
local statName = patternData[2]
-- Handle 2H weapon type conversion
if weaponSlotType == "IsTwoHand" then
if statName == "IsAxe" then statName = "Is2HAxe"
elseif statName == "IsMace" then statName = "Is2HMace"
elseif statName == "IsSword" then statName = "Is2HSword"
end
end
stats[statName] = 1
if debug then
print("|cFF00FF00[DEBUG]|r Weapon type: " .. statName)
end
break
end
end
end
-- Check for armor types
if ValuateArmorTypePatterns then
for _, patternData in ipairs(ValuateArmorTypePatterns) do
if string.match(rightLineText, patternData[1]) then
stats[patternData[2]] = 1
if debug then
print("|cFF00FF00[DEBUG]|r Armor type: " .. patternData[2])
end
break
end
end
end
-- Check for relic types
if ValuateRelicTypePatterns then
for _, patternData in ipairs(ValuateRelicTypePatterns) do
if string.match(rightLineText, patternData[1]) then
stats[patternData[2]] = 1
if debug then
print("|cFF00FF00[DEBUG]|r Relic type: " .. patternData[2])
end
break
end
end
end
end
end
-- Second pass: parse regular stats
for i = 1, tooltip:NumLines() do
local leftText = getglobal(tooltipName .. "TextLeft" .. i)
if leftText then
local rawText = leftText:GetText() or ""
local lineText = StripColorCodes(rawText)
if debug then
print("|cFF8888FF[DEBUG]|r Line " .. i .. ": '" .. lineText .. "'")
end
-- Try to match against each stat pattern
if lineText and lineText ~= "" then
-- Split by newlines in case multiple stats are in one GetText() result
-- Some tooltips return multi-line strings from a single GetText() call
local lines = {}
for line in string.gmatch(lineText, "[^\r\n]+") do
table.insert(lines, line)
end
-- If no newlines found, process the original line
if #lines == 0 then
table.insert(lines, lineText)
end
-- Process each line separately
for _, line in ipairs(lines) do
local matched = false
for _, patternData in ipairs(ValuateStatPatterns) do
local pattern = patternData[1]
local statName = patternData[2]
local matches = {string.match(line, pattern)}
if matches[1] then
local value = tonumber(matches[1])
if value then
stats[statName] = (stats[statName] or 0) + value
if debug then
print("|cFF00FF00[DEBUG]|r Matched " .. statName .. " = " .. value .. " (pattern: " .. pattern .. ")")
end
matched = true
break -- Found a match, move to next line
end
end
end
if debug and not matched then
print("|cFFFF8800[DEBUG]|r No pattern matched for: '" .. line .. "'")
end
end
end
end
end
-- Assign type-specific DPS and Speed based on weapon slot
if stats["Dps"] then
local dps = stats["Dps"]
-- Assign to slot-specific DPS
if stats["IsMainHand"] then
stats["MainHandDps"] = dps
end
if stats["IsOffHand"] then
stats["OffHandDps"] = dps
end
if stats["IsOneHand"] then
stats["OneHandDps"] = dps
end
if stats["IsTwoHand"] then
stats["TwoHandDps"] = dps
end
-- Assign to melee/ranged DPS
if isMelee then
stats["MeleeDps"] = dps
end
if isRanged or stats["IsRanged"] then
stats["RangedDps"] = dps
end
if debug then
print("|cFF00FF00[DEBUG]|r Assigned DPS to type-specific stats")
end
end
if stats["Speed"] then
local speed = stats["Speed"]
-- Assign to melee/ranged Speed
if isMelee then
stats["MeleeSpeed"] = speed
end
if isRanged or stats["IsRanged"] then
stats["RangedSpeed"] = speed
end
if debug then
print("|cFF00FF00[DEBUG]|r Assigned Speed to type-specific stats")
end
end
-- Calculate Feral AP from weapon DPS (for druids)
-- Feral AP = (Weapon DPS - 54.8) * 14
if stats["Dps"] and stats["IsStaff"] then
local feralAP = math.floor((stats["Dps"] - 54.8) * 14)
if feralAP > 0 then
stats["FeralAP"] = feralAP
if debug then
print("|cFF00FF00[DEBUG]|r Calculated Feral AP = " .. feralAP)
end
end
end
return stats
end
-- Gets stats for an item link by parsing its tooltip
-- Returns a stats table, or nil if parsing fails
-- Note: For scaled items, this reads the base item stats, not scaled values
-- Scaled values are only available when reading from the actual displayed tooltip
function Valuate:GetStatsForItemLink(itemLink)
if not itemLink or type(itemLink) ~= "string" then
return nil
end
-- Parse tooltip from the item link
-- Note: SetHyperlink uses base item data, not scaled values
local tooltip = GetPrivateTooltip()
if not tooltip then
return nil
end
tooltip:ClearLines()
local success = pcall(function() tooltip:SetHyperlink(itemLink) end)
if not success then
-- Invalid item link - SetHyperlink failed
return nil
end
-- Parse the tooltip (note: this will show base stats, not scaled stats)
local stats = Valuate:ParseStatsFromTooltip("ValuatePrivateTooltip", Valuate:GetOptions().debug)
return stats
end
-- Gets stats directly from an already-displayed tooltip
-- This reads the actual tooltip text (includes scaled values)
-- tooltipName: Name of the tooltip frame (e.g., "GameTooltip")
function Valuate:GetStatsFromDisplayedTooltip(tooltipName)
if not tooltipName then
return nil
end
-- Parse the tooltip that's already displayed (this will have scaled values)
return Valuate:ParseStatsFromTooltip(tooltipName)
end
-- ========================================
-- Tooltip Integration (Performance-Optimized)
-- ========================================
-- Helper function to extract item ID from item link
local function GetItemIdFromLink(itemLink)
if not itemLink then return nil end
local itemId = itemLink:match("item:(%d+):")
return itemId and tonumber(itemId) or nil
end
-- Track current item and whether we've added our lines
local CurrentTooltipItem = nil
local CurrentTooltipStats = nil
local ValuateLinesAdded = false
-- Store default tooltip border colors
local DefaultTooltipBorderColor = nil
-- Unique marker for detecting Valuate lines in tooltips (nearly invisible color code)
local VALUATE_MARKER = "|cFF000001"
local VALUATE_MARKER_FULL = "|cFF000001|r"
-- Determine tooltip border color based on displayed scale
-- Returns r, g, b values (0-1 range) or nil if no coloring should be applied
local function GetTooltipBorderColor(stats, itemLink)
-- Check if a character window scale is selected
local scaleName = Valuate:GetOptions().characterWindowScale
if not scaleName or scaleName == "" then
return nil -- No scale selected, use default border
end
-- Get the scale data
local scale = Valuate:GetScales()[scaleName]
if not scale or not scale.Values then
return nil -- Invalid scale
end
-- Check if item is equippable
local equipSlot = nil
if itemLink then
local _, _, _, _, _, _, _, _, itemEquipLoc = GetItemInfo(itemLink)
equipSlot = itemEquipLoc
end
if not equipSlot or equipSlot == "" then
return nil -- Non-equippable item, use default border
end
-- Check if item has any stats marked as unusable (banned) for this scale
if scale.Unusable then
-- First check parsed stats
for statName, statValue in pairs(stats) do
if scale.Unusable[statName] and statValue and statValue > 0 then
return nil -- Item has banned stat, use default border
end
end
-- Also check equipment slot type directly (in case tooltip parsing missed weapon type)
if equipSlot then
if equipSlot == "INVTYPE_2HWEAPON" and scale.Unusable["TwoHandDps"] then
return nil -- Item is 2H weapon (banned), use default border
elseif equipSlot == "INVTYPE_WEAPONOFFHAND" and scale.Unusable["OffHandDps"] then
return nil -- Item is offhand weapon (banned), use default border
elseif (equipSlot == "INVTYPE_RANGED" or equipSlot == "INVTYPE_RANGEDRIGHT" or equipSlot == "INVTYPE_THROWN") and scale.Unusable["RangedDps"] then
return nil -- Item is ranged weapon (banned), use default border
end
end
end
-- Calculate item score
local score = Valuate:CalculateItemScore(stats, scale)
if not score or score <= 0 then
return nil -- No score, use default border
end
-- Get equipped item score for comparison
local equippedScore = nil
-- Try to get equipped score from shopping tooltip first (if comparing items)
if ShoppingTooltip1 and ShoppingTooltip1:IsVisible() then
local equippedItemLink = ShoppingTooltip1:GetItem()
if equippedItemLink then
local _, _, _, _, _, _, _, _, shoppingEquipLoc = GetItemInfo(equippedItemLink)
-- Check if items are comparable (uses smart weapon comparison logic)
if shoppingEquipLoc and AreWeaponTypesComparable(equipSlot, shoppingEquipLoc) then
local equippedStats = Valuate:GetStatsFromDisplayedTooltip("ShoppingTooltip1")
if equippedStats then
equippedScore = Valuate:CalculateItemScore(equippedStats, scale)
end
end
end
end
-- Fall back to getting equipped score the normal way
if not equippedScore then
equippedScore = Valuate:GetEquippedItemScore(equipSlot, scale)
end
if not equippedScore then
return nil -- No equipped item to compare, use default border
end
-- Determine border color based on comparison
local diff = score - equippedScore
if diff > 0 then
return 0, 1, 0 -- Green for upgrades
elseif diff < 0 then
return 1, 0, 0 -- Red for downgrades
else
return nil -- Equal scores - use default border
end
end
-- Check if our Valuate lines are present in the tooltip
local function HasValuateLines(tooltip)
if not tooltip then return false end
local numLines = tooltip:NumLines()
for i = 1, numLines do
local leftText = getglobal(tooltip:GetName() .. "TextLeft" .. i)
if leftText then
local text = leftText:GetText()
if text and text:find(VALUATE_MARKER, 1, true) then
return true
end
end
end
return false
end
-- Add score lines to tooltip
local function AddScoreLinesToTooltip(tooltip, stats, itemLink)
if not tooltip or not stats then return end
-- Get active scales
local activeScales = Valuate:GetActiveScales()
if #activeScales == 0 then return end
-- Get the item's equipment slot for comparison
local equipSlot = nil
if itemLink then
local _, _, _, _, _, _, _, _, itemEquipLoc = GetItemInfo(itemLink)
equipSlot = itemEquipLoc
end
-- Check if this is a multi-slot item type (rings, trinkets, 1H weapons)
local isMultiSlot = (equipSlot == "INVTYPE_FINGER" or equipSlot == "INVTYPE_TRINKET" or equipSlot == "INVTYPE_WEAPON")
local options = Valuate:GetOptions()
local scales = Valuate:GetScales()
-- Add "Best for" line at the TOP if player owns the item and it's best for any scales
local hasScores = false
if itemLink and options.showBestFor ~= false then
local ownsItem = Valuate:PlayerOwnsItem(itemLink)
if ownsItem then
local bestScales = Valuate:IsBestInSlot(itemLink)
if bestScales and #bestScales > 0 then
-- Build colored scale names list
local scaleNamesList = {}
for _, bestScaleName in ipairs(bestScales) do
local scale = scales[bestScaleName]
if scale then
local color = scale.Color or "FFFFFF"
local displayName = scale.DisplayName or bestScaleName
table.insert(scaleNamesList, "|cFF" .. color .. displayName .. "|r")
end
end
if #scaleNamesList > 0 then
tooltip:AddLine(" ") -- Blank line before "Best for"
local scaleNamesText = table.concat(scaleNamesList, ", ")
tooltip:AddLine(VALUATE_MARKER_FULL .. " |cFFFFD700★ Best for:|r " .. scaleNamesText, nil, nil, nil, true)
hasScores = true -- Mark that we've added lines
end
end
end
end
-- Calculate and display scores
for _, scaleName in ipairs(activeScales) do
local scale = scales[scaleName]
if scale then
-- Check if item has any stats marked as unusable (banned) for this scale
local hasUnusableStat = false
if scale.Unusable then
-- First check parsed stats
for statName, statValue in pairs(stats) do
if scale.Unusable[statName] and statValue and statValue > 0 then
hasUnusableStat = true
if options.debug then
print("|cFFFF8800[Valuate Debug]|r Scale '" .. scaleName .. "' skipped: item has banned stat '" .. statName .. "'")
end
break
end
end
-- Also check equipment slot type directly (in case tooltip parsing missed weapon type)
if not hasUnusableStat and equipSlot then
if equipSlot == "INVTYPE_2HWEAPON" and scale.Unusable["TwoHandDps"] then
hasUnusableStat = true
if options.debug then
print("|cFFFF8800[Valuate Debug]|r Scale '" .. scaleName .. "' skipped: item is 2H weapon (banned by TwoHandDps)")
end
elseif equipSlot == "INVTYPE_WEAPONOFFHAND" and scale.Unusable["OffHandDps"] then
hasUnusableStat = true
if options.debug then
print("|cFFFF8800[Valuate Debug]|r Scale '" .. scaleName .. "' skipped: item is offhand weapon (banned by OffHandDps)")
end
elseif (equipSlot == "INVTYPE_RANGED" or equipSlot == "INVTYPE_RANGEDRIGHT" or equipSlot == "INVTYPE_THROWN") and scale.Unusable["RangedDps"] then
hasUnusableStat = true
if options.debug then
print("|cFFFF8800[Valuate Debug]|r Scale '" .. scaleName .. "' skipped: item is ranged weapon (banned by RangedDps)")
end
end
end
end
-- Only show score if no banned stats found on this item
if not hasUnusableStat then
local score = Valuate:CalculateItemScore(stats, scale)
if score and score > 0 then
-- Check if user wants to show scale values
local showValue = options.showScaleValue ~= false
-- Only display scale info if showValue is enabled
if showValue then
if not hasScores then
tooltip:AddLine(" ")
hasScores = true
end
local color = scale.Color or "FFFFFF"
local displayName = scale.DisplayName or scaleName
local decimals = options.decimalPlaces or 1
local formatStr = "%." .. decimals .. "f"
local scoreText = string.format(formatStr, score)
-- Build the display text based on options
local compMode = options.comparisonMode or "number"
local comparisonText = ""
-- Build icon prefix based on scale's Icon setting
local prefix = VALUATE_MARKER_FULL
local icon = scale.Icon
if icon and icon ~= "" then
prefix = prefix .. "|T" .. icon .. ":0|t "
end
-- Show detailed stat breakdown if enabled
if options.showStatBreakdown then
-- Check if this is a multi-slot item for per-slot breakdown
-- Only show multi-slot breakdown on hover tooltips (itemLink provided), not shopping tooltips
local isMultiSlotBreakdown = isMultiSlot and compMode ~= "off" and itemLink
-- For non-multi-slot items, show breakdown once
if not isMultiSlotBreakdown then
-- Try to get equipped item stats for comparison
-- Only compare if itemLink is provided (hover tooltip), not for shopping tooltips (itemLink is nil)
local equippedStats = nil
if itemLink and equipSlot and equipSlot ~= "" then
-- Try shopping tooltip first for context
if ShoppingTooltip1 and ShoppingTooltip1:IsVisible() then
local equippedItemLink = ShoppingTooltip1:GetItem()
if equippedItemLink then
local _, _, _, _, _, _, _, _, shoppingEquipLoc = GetItemInfo(equippedItemLink)
if shoppingEquipLoc and AreWeaponTypesComparable(equipSlot, shoppingEquipLoc) then
equippedStats = Valuate:GetStatsFromDisplayedTooltip("ShoppingTooltip1")
end
end
end
-- Fall back to getting equipped item stats the normal way
if not equippedStats then
local invSlots = EquipSlotToInvNumber[equipSlot]
if invSlots then
for _, slotId in ipairs(invSlots) do
local itemLink = GetInventoryItemLink("player", slotId)
if itemLink then
local _, _, _, _, _, _, _, _, equippedEquipLoc = GetItemInfo(itemLink)
if equippedEquipLoc and AreWeaponTypesComparable(equipSlot, equippedEquipLoc) then
local tooltip = GetPrivateTooltip()
tooltip:ClearLines()
tooltip:SetInventoryItem("player", slotId)
equippedStats = Valuate:ParseStatsFromTooltip("ValuatePrivateTooltip")
break -- Use first comparable equipped item
end
end
end
end
end
end
-- Use comparison breakdown if we have equipped stats
local breakdown
if equippedStats then
breakdown = Valuate:CalculateStatBreakdownWithComparison(stats, equippedStats, scale)
else
breakdown = Valuate:CalculateStatBreakdown(stats, scale)
end
if breakdown and #breakdown > 0 then
-- Display scale name as header for the breakdown
tooltip:AddLine(prefix .. "|cFF" .. color .. displayName .. ":|r")
-- Track totals for the summary line
local totalHoverContrib = 0
local totalEquippedContrib = 0
-- Display each stat contribution
for _, entry in ipairs(breakdown) do
local statDisplayName = ValuateStatNames[entry.statName] or entry.statName
if equippedStats and entry.equippedValue and compMode ~= "off" then
-- With comparison (only if comparison mode is enabled)
local hoverValueText = string.format(formatStr, entry.hoverValue)
local weightText = string.format(formatStr, entry.hoverWeight)
local hoverContribText = string.format(formatStr, entry.hoverContribution)
local equippedContribText = string.format(formatStr, entry.equippedContribution)
local diffText = string.format(formatStr, entry.diff)
local percentText = string.format("%.1f", entry.percentDiff)
-- Add to totals
totalHoverContrib = totalHoverContrib + entry.hoverContribution
totalEquippedContrib = totalEquippedContrib + entry.equippedContribution
-- Determine color for the difference values only
local diffColor
local diffSign = ""
if entry.diff > 0 then
diffColor = "00FF00" -- Green for upgrade
diffSign = "+"
elseif entry.diff < 0 then
diffColor = "FF0000" -- Red for downgrade
diffSign = "" -- Negative sign already in number
else
diffColor = "FFFF00" -- Yellow for no change (matches original scale comparison)
diffSign = ""
end
-- Build comparison text based on comparison mode
local comparisonPart = ""
if compMode == "number" then
comparisonPart = " (|r|cFF" .. diffColor .. diffSign .. diffText .. "|r|cFF" .. color .. ")"
elseif compMode == "percent" then
comparisonPart = " (|r|cFF" .. diffColor .. diffSign .. percentText .. "%|r|cFF" .. color .. ")"
elseif compMode == "both" then
comparisonPart = " (|r|cFF" .. diffColor .. diffSign .. diffText .. ", " .. diffSign .. percentText .. "%|r|cFF" .. color .. ")"
end
-- Format: " Stat: hoverValue × weight = hoverContrib (comparison)"
-- Only show the hover item's value, not the equipped item's value
if options.rightAlign then
-- Right-aligned: split into left and right parts
local leftPart = " " .. prefix .. "|cFF" .. color .. statDisplayName .. ": " ..
hoverValueText .. " × " .. weightText .. "|r"
local rightPart = "|cFF" .. color .. hoverContribText .. comparisonPart .. "|r"
tooltip:AddDoubleLine(leftPart, rightPart)
else
-- Normal: single line
local breakdownLine = " " .. prefix .. "|cFF" .. color .. statDisplayName .. ": " ..
hoverValueText .. " × " .. weightText .. " = " .. hoverContribText ..
comparisonPart .. "|r"
tooltip:AddLine(breakdownLine)
end
else
-- Without comparison (no equipped item or comparison mode is "off")
local statValueText = string.format(formatStr, entry.statValue or entry.hoverValue)
local weightText = string.format(formatStr, entry.weight or entry.hoverWeight)
local contributionText = string.format(formatStr, entry.contribution or entry.hoverContribution)
-- Add to total (no comparison)
totalHoverContrib = totalHoverContrib + (entry.contribution or entry.hoverContribution)
if options.rightAlign then
-- Right-aligned: split into left and right parts
local leftPart = " " .. prefix .. "|cFF" .. color .. statDisplayName .. ": " ..
statValueText .. " × " .. weightText .. "|r"
local rightPart = "|cFF" .. color .. contributionText .. "|r"
tooltip:AddDoubleLine(leftPart, rightPart)
else
-- Normal: single line
local breakdownLine = " " .. prefix .. "|cFF" .. color .. statDisplayName .. ": " ..
statValueText .. " × " .. weightText .. " = " .. contributionText .. "|r"
tooltip:AddLine(breakdownLine)
end
end
end
-- Display total line
if equippedStats and compMode ~= "off" then
-- With comparison - only show hover item's total with comparison
local totalHoverText = string.format(formatStr, totalHoverContrib)
local totalEquippedText = string.format(formatStr, totalEquippedContrib)
local totalDiff = totalHoverContrib - totalEquippedContrib
local totalDiffText = string.format(formatStr, totalDiff)
local totalPercentDiff = 0
if totalEquippedContrib ~= 0 then
totalPercentDiff = (totalDiff / math.abs(totalEquippedContrib)) * 100
elseif totalDiff ~= 0 then
totalPercentDiff = (totalDiff > 0) and 100 or -100
end
local totalPercentText = string.format("%.1f", totalPercentDiff)
-- Determine color for total difference
local totalDiffColor
local totalDiffSign = ""
if totalDiff > 0 then
totalDiffColor = "00FF00"
totalDiffSign = "+"
elseif totalDiff < 0 then
totalDiffColor = "FF0000"
totalDiffSign = ""
else
totalDiffColor = "FFFF00" -- Yellow for no change (matches original scale comparison)
totalDiffSign = ""