-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGearScoreLite.lua
More file actions
632 lines (552 loc) · 24.7 KB
/
Copy pathGearScoreLite.lua
File metadata and controls
632 lines (552 loc) · 24.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
-------------------------------------------------------------------------------
-- GearScoreLite (Enhanced) --
-- Version 3x06+ Turbo --
-- Mirrikat45 & Leo (Optimized) --
-------------------------------------------------------------------------------
-- Cache System for Instant Calculations (0ms lag)
local GS_Cache = {}
local GS_LastInspectTime = 0
local GS_PendingUnit = nil
local GS_PendingGUID = nil
local GS_INSPECT_THROTTLE = 0.8 -- Min seconds between inspect requests to avoid server drop
-- Helper: Get current player/target/unit GearScore with cache
local function GS_GetCachedScore(guid)
if not guid then return nil end
local entry = GS_Cache[guid]
if entry then
-- Cache valid for 300 seconds (5 minutes)
if (GetTime() - entry.time) < 300 then
return entry.score, entry.avg, entry.items
end
end
return nil
end
local function GS_SetCachedScore(guid, score, avg, items, name)
if not guid or not score or score <= 0 then return end
GS_Cache[guid] = {
score = score,
avg = avg,
time = GetTime(),
items = items or {},
name = name
}
end
-- OnEvent handle gearscore, ilvl, dkp updates and INSPECT_READY
function GearScore_OnEvent(self, event, ...)
if ( event == "PLAYER_EQUIPMENT_CHANGED" ) then
MyPaperDoll();
local pGuid = UnitGUID("player")
if pGuid then
local myScore, myAvg = GearScore_GetScore(UnitName("player"), "player")
GS_SetCachedScore(pGuid, myScore, myAvg, nil, UnitName("player"))
end
end
if ( event == "ADDON_LOADED" ) then
local addonName = ...
if ( addonName == "GearScoreLite" ) then
if not ( GS_Guilds ) then GS_Guilds = {} end
if not ( GS_Guids ) then GS_Guids = {} end
if not ( GS_MyTip ) then GS_MyTip = GS_DefaultMyTip end
if not ( GS_Settings ) then GS_Settings = GS_DefaultSettings end
if not ( GS_Data ) then GS_Data = {}; end; if not ( GS_Data[GetRealmName()] ) then GS_Data[GetRealmName()] = { ["Players"] = {} }; end
for i, v in pairs(GS_DefaultSettings) do if not ( GS_Settings[i] ) then GS_Settings[i] = GS_DefaultSettings[i]; end; end
end
if ( addonName == "Blizzard_InspectUI" ) then
GearScore_HookInspectUI()
end
end
-- Handle INSPECT_READY event from server
if ( event == "INSPECT_READY" ) then
local inspectGUID = ...
-- Match current mouseover or target
local targetUnit = nil
if UnitGUID("mouseover") == inspectGUID or (not inspectGUID and UnitExists("mouseover")) then
targetUnit = "mouseover"
elseif UnitGUID("target") == inspectGUID or (not inspectGUID and UnitExists("target")) then
targetUnit = "target"
end
if targetUnit and UnitIsPlayer(targetUnit) then
local tName = UnitName(targetUnit)
local tGuid = UnitGUID(targetUnit)
local score, avg = GearScore_GetScore(tName, targetUnit)
if score and score > 0 and tGuid then
GS_SetCachedScore(tGuid, score, avg, nil, tName)
-- If tooltip is currently showing this unit, update it on the fly
if GameTooltip:IsShown() then
local ttName, ttUnit = GameTooltip:GetUnit()
if (ttUnit and UnitGUID(ttUnit) == tGuid) or (ttName and ttName == tName) then
GearScore_UpdateUnitTooltip(tName, targetUnit, score, avg)
end
end
-- If InspectPaperDollFrame is open, update inspect frame
if InspectPaperDollFrame and InspectPaperDollFrame:IsShown() and InspectFrame.unit then
GearScore_UpdateInspectFrame(InspectFrame.unit)
end
end
end
end
end
-------------------------- Get Mouseover / Target Score -----------------------------------
function GearScore_GetScore(Name, Target)
if not ( Target and UnitIsPlayer(Target) ) then return 0, 0 end
local isPlayer = UnitIsUnit(Target, "player")
local guid = UnitGUID(Target)
local PlayerClass, PlayerEnglishClass = UnitClass(Target);
local GearScore = 0; local PVPScore = 0; local ItemCount = 0; local LevelTotal = 0; local TitanGrip = 1; local TempEquip = {}; local TempPVPScore = 0
local mainHandLink = GetInventoryItemLink(Target, 16)
local offHandLink = GetInventoryItemLink(Target, 17)
if ( mainHandLink and offHandLink ) then
local ItemName, ItemLink, ItemRarity, ItemLevel, ItemMinLevel, ItemType, ItemSubType, ItemStackCount, ItemEquipLoc = GetItemInfo(mainHandLink)
if ( ItemEquipLoc == "INVTYPE_2HWEAPON" ) then TitanGrip = 0.5; end
end
if ( offHandLink ) then
local ItemName, ItemLink, ItemRarity, ItemLevel, ItemMinLevel, ItemType, ItemSubType, ItemStackCount, ItemEquipLoc = GetItemInfo(offHandLink)
if ( ItemEquipLoc == "INVTYPE_2HWEAPON" ) then TitanGrip = 0.5; end
local TempScore, ItemLvl = GearScore_GetItemScore(offHandLink);
if ( PlayerEnglishClass == "HUNTER" ) then TempScore = TempScore * 0.3164; end
GearScore = GearScore + (TempScore or 0) * TitanGrip;
ItemCount = ItemCount + 1;
LevelTotal = LevelTotal + (ItemLvl or 0)
end
for i = 1, 18 do
if ( i ~= 4 ) and ( i ~= 17 ) then
local ItemLink = GetInventoryItemLink(Target, i)
if ( ItemLink ) then
local ItemName, _, ItemRarity, ItemLvl, ItemMinLevel, ItemType, ItemSubType, ItemStackCount, ItemEquipLoc = GetItemInfo(ItemLink)
local TempScore = GearScore_GetItemScore(ItemLink);
if ( i == 16 ) and ( PlayerEnglishClass == "HUNTER" ) then TempScore = TempScore * 0.3164; end
if ( i == 18 ) and ( PlayerEnglishClass == "HUNTER" ) then TempScore = TempScore * 5.3224; end
if ( i == 16 ) then TempScore = TempScore * TitanGrip; end
GearScore = GearScore + (TempScore or 0);
ItemCount = ItemCount + 1;
LevelTotal = LevelTotal + (ItemLvl or 0)
end
end
end
if ( GearScore <= 0 ) and not isPlayer then
return 0, 0;
end
local finalScore = floor(GearScore)
local finalAvg = (ItemCount > 0) and floor(LevelTotal / ItemCount) or 0
if guid and finalScore > 0 then
GS_SetCachedScore(guid, finalScore, finalAvg, nil, Name)
end
return finalScore, finalAvg
end
-------------------------------------------------------------------------------
function GearScore_GetEnchantInfo(ItemLink, ItemEquipLoc)
if not ItemLink or not ItemEquipLoc then return 1 end
local enchantId = string.match(ItemLink, "item:%d+:(%d+)")
if (not enchantId or enchantId == "0" or enchantId == "") and ( GS_ItemTypes[ItemEquipLoc] and GS_ItemTypes[ItemEquipLoc]["Enchantable"] ) then
local percent = ( floor((-2 * ( GS_ItemTypes[ItemEquipLoc]["SlotMOD"] )) * 100) / 100 );
return (1 + (percent / 100));
else
return 1;
end
end
------------------------------ Get Item Score ---------------------------------
function GearScore_GetItemScore(ItemLink)
local QualityScale = 1; local PVPScale = 1; local PVPScore = 0; local GearScore = 0
if not ( ItemLink ) then return 0, 0, 50, 1, 1, 1, 0, "", 1; end
local ItemName, _, ItemRarity, ItemLevel, ItemMinLevel, ItemType, ItemSubType, ItemStackCount, ItemEquipLoc = GetItemInfo(ItemLink);
if not ItemLevel or not ItemRarity then return 0, 0, 50, 1, 1, 1, 0, "", 1 end
local Table = {}; local Scale = 1.8618
if ( ItemRarity == 5 ) then QualityScale = 1.3; ItemRarity = 4;
elseif ( ItemRarity == 1 ) then QualityScale = 0.005; ItemRarity = 2
elseif ( ItemRarity == 0 ) then QualityScale = 0.005; ItemRarity = 2 end
if ( ItemRarity == 7 ) then ItemRarity = 3; ItemLevel = 187.05; end
if ( GS_ItemTypes[ItemEquipLoc] ) then
if ( ItemLevel > 120 ) then Table = GS_Formula["A"]; else Table = GS_Formula["B"]; end
if ( Table and Table[ItemRarity] ) and ( ItemRarity >= 2 ) and ( ItemRarity <= 4 ) then
local Red, Green, Blue = GearScore_GetQuality((floor(((ItemLevel - Table[ItemRarity].A) / Table[ItemRarity].B) * 1 * Scale)) * 11.25 )
GearScore = floor(((ItemLevel - Table[ItemRarity].A) / Table[ItemRarity].B) * GS_ItemTypes[ItemEquipLoc].SlotMOD * Scale * QualityScale)
if ( ItemLevel == 187.05 ) then ItemLevel = 0; end
if ( GearScore < 0 ) then GearScore = 0; Red, Green, Blue = GearScore_GetQuality(1); end
local percent = GearScore_GetEnchantInfo(ItemLink, ItemEquipLoc) or 1
GearScore = floor(GearScore * percent)
return GearScore, ItemLevel, GS_ItemTypes[ItemEquipLoc].ItemSlot, Red, Green, Blue, 0, ItemEquipLoc, percent;
end
end
return -1, ItemLevel, 50, 1, 1, 1, 0, ItemEquipLoc, 1
end
-------------------------------- Get Quality ----------------------------------
function GearScore_GetQuality(ItemScore)
if not ItemScore then return 0.1, 0.1, 0.1, "Trash" end
if ( ItemScore > 5999 ) then ItemScore = 5999; end
for i = 0, 6 do
if ( ItemScore > i * 1000 ) and ( ItemScore <= ( ( i + 1 ) * 1000 ) ) then
local Red = GS_Quality[( i + 1 ) * 1000].Red["A"] + (((ItemScore - GS_Quality[( i + 1 ) * 1000].Red["B"])*GS_Quality[( i + 1 ) * 1000].Red["C"])*GS_Quality[( i + 1 ) * 1000].Red["D"])
local Blue = GS_Quality[( i + 1 ) * 1000].Green["A"] + (((ItemScore - GS_Quality[( i + 1 ) * 1000].Green["B"])*GS_Quality[( i + 1 ) * 1000].Green["C"])*GS_Quality[( i + 1 ) * 1000].Green["D"])
local Green = GS_Quality[( i + 1 ) * 1000].Blue["A"] + (((ItemScore - GS_Quality[( i + 1 ) * 1000].Blue["B"])*GS_Quality[( i + 1 ) * 1000].Blue["C"])*GS_Quality[( i + 1 ) * 1000].Blue["D"])
return Red, Green, Blue, GS_Quality[( i + 1 ) * 1000].Description
end
end
return 0.1, 0.1, 0.1, "Trash"
end
----------------------------- Dynamic Tooltip Renderer -------------------------
function GearScore_UpdateUnitTooltip(Name, Unit, Score, Average)
if not GameTooltip:IsShown() then return end
if not Score or Score <= 0 then return end
local Red, Blue, Green = GearScore_GetQuality(Score)
if ( GS_Settings["iLvlMode"] == 1 ) then
GameTooltip:AddLine("iLevel: "..Average, Red, Green, Blue)
elseif ( GS_Settings["Player"] == 1 ) then
if ( GS_Settings["Level"] == 1 ) then
GameTooltip:AddDoubleLine("GearScore: "..Score, "(iLevel: "..Average..")", Red, Green, Blue, Red, Green, Blue)
else
GameTooltip:AddLine("GearScore: "..Score, Red, Green, Blue)
end
if ( GS_Settings["Compare"] == 1 ) then
local MyGearScore = GearScore_GetScore(UnitName("player"), "player");
local TheirGearScore = Score
if ( MyGearScore > TheirGearScore ) then GameTooltip:AddDoubleLine("YourScore: "..MyGearScore, "(+"..(MyGearScore - TheirGearScore)..")", 0,1,0, 0,1,0); end
if ( MyGearScore < TheirGearScore ) then GameTooltip:AddDoubleLine("YourScore: "..MyGearScore, "(-"..(TheirGearScore - MyGearScore)..")", 1,0,0, 1,0,0); end
if ( MyGearScore == TheirGearScore ) then GameTooltip:AddDoubleLine("YourScore: "..MyGearScore, "(+0)", 0,1,1, 0,1,1); end
end
if ( GS_Settings["Special"] == 1 ) and ( GS_Special[Name] ) then GameTooltip:AddLine(GS_Special[GS_Special[Name].Type], 1, 0, 0 ); end
end
GameTooltip:Show()
end
----------------------------- Hook Set Unit -----------------------------------
function GearScore_HookSetUnit(arg1, arg2)
local Name, Unit = GameTooltip:GetUnit();
if not Name or not Unit or not UnitIsPlayer(Unit) then return end
local guid = UnitGUID(Unit)
local cachedScore, cachedAvg = GS_GetCachedScore(guid)
-- 1. Check instant cache first (0ms latency)
if cachedScore and cachedScore > 0 then
GearScore_UpdateUnitTooltip(Name, Unit, cachedScore, cachedAvg)
else
-- 2. If inspecting self:
if UnitIsUnit(Unit, "player") then
local myScore, myAvg = GearScore_GetScore(Name, "player")
GearScore_UpdateUnitTooltip(Name, "player", myScore, myAvg)
-- 3. If inspecting other player:
elseif CanInspect(Unit) and CheckInteractDistance(Unit, 1) then
local now = GetTime()
if (now - GS_LastInspectTime) >= GS_INSPECT_THROTTLE then
GS_LastInspectTime = now
GS_PendingUnit = Unit
GS_PendingGUID = guid
NotifyInspect(Unit)
end
-- Try immediate read in case client already has data
local curScore, curAvg = GearScore_GetScore(Name, Unit)
if curScore and curScore > 0 then
GearScore_UpdateUnitTooltip(Name, Unit, curScore, curAvg)
end
end
end
-- Check DKP/Guild/Tip
if guid ~= nil and UnitIsFriend("player", Unit) ~= nil and (Name ~= "Unknown") then
if GearScoreToolTip_Exists and GearScoreToolTip_Exists(Name) then
GameTooltip:AddLine(GS_ToolTips[Name].Tip, 1, 0, 0);
elseif GearScoreToolTip_Request then
GearScoreToolTip_Request(Name);
end
end
end
----------------------------- Hook Item Tooltips -------------------------------
function GearScore_HookSetItem() ItemName, ItemLink = GameTooltip:GetItem(); GearScore_HookItem(ItemName, ItemLink, GameTooltip); end
function GearScore_HookRefItem() ItemName, ItemLink = ItemRefTooltip:GetItem(); GearScore_HookItem(ItemName, ItemLink, ItemRefTooltip); end
function GearScore_HookCompareItem() ItemName, ItemLink = ShoppingTooltip1:GetItem(); GearScore_HookItem(ItemName, ItemLink, ShoppingTooltip1); end
function GearScore_HookCompareItem2() ItemName, ItemLink = ShoppingTooltip2:GetItem(); GearScore_HookItem(ItemName, ItemLink, ShoppingTooltip2); end
function GearScore_HookItem(ItemName, ItemLink, Tooltip)
if not ItemLink or not Tooltip then return end
local PlayerClass, PlayerEnglishClass = UnitClass("player");
-- Display Item ID
if GS_Settings["ItemID"] == 1 then
local itemString = string.match(ItemLink, "item[%-?%d:]+");
if itemString then
local _, ItemID = strsplit(":", itemString)
if ItemID then
Tooltip:AddDoubleLine("ID: "..ItemID, "", 0.7, 0.7, 0.7, 0.7, 0.7, 0.7);
end
end
end
if not ( IsEquippableItem(ItemLink) ) then return; end
local ItemScore, ItemLevel, EquipLoc, Red, Green, Blue, PVPScore, ItemEquipLoc, enchantPercent = GearScore_GetItemScore(ItemLink);
if ( ItemScore and ItemScore >= 0 ) then
if ( GS_Settings["Item"] == 1 ) then
if ( ItemLevel ) and ( GS_Settings["Level"] == 1 ) then
Tooltip:AddDoubleLine("GearScore: "..ItemScore, "(iLevel "..ItemLevel..")", Red, Blue, Green, Red, Blue, Green);
if ( PlayerEnglishClass == "HUNTER" ) then
if ( ItemEquipLoc == "INVTYPE_RANGEDRIGHT" ) or ( ItemEquipLoc == "INVTYPE_RANGED" ) then
Tooltip:AddLine("HunterScore: "..floor(ItemScore * 5.3224), Red, Blue, Green)
end
if ( ItemEquipLoc == "INVTYPE_2HWEAPON" ) or ( ItemEquipLoc == "INVTYPE_WEAPONMAINHAND" ) or ( ItemEquipLoc == "INVTYPE_WEAPONOFFHAND" ) or ( ItemEquipLoc == "INVTYPE_WEAPON" ) or ( ItemEquipLoc == "INVTYPE_HOLDABLE" ) then
Tooltip:AddLine("HunterScore: "..floor(ItemScore * 0.3164), Red, Blue, Green)
end
end
else
Tooltip:AddDoubleLine("GearScore: "..ItemScore, "", Red, Blue, Green, Red, Blue, Green);
if ( PlayerEnglishClass == "HUNTER" ) then
if ( ItemEquipLoc == "INVTYPE_RANGEDRIGHT" ) or ( ItemEquipLoc == "INVTYPE_RANGED" ) then
Tooltip:AddLine("HunterScore: "..floor(ItemScore * 5.3224), Red, Blue, Green)
end
if ( ItemEquipLoc == "INVTYPE_2HWEAPON" ) or ( ItemEquipLoc == "INVTYPE_WEAPONMAINHAND" ) or ( ItemEquipLoc == "INVTYPE_WEAPONOFFHAND" ) or ( ItemEquipLoc == "INVTYPE_WEAPON" ) or ( ItemEquipLoc == "INVTYPE_HOLDABLE" ) then
Tooltip:AddLine("HunterScore: "..floor(ItemScore * 0.3164), Red, Blue, Green)
end
end
end
end
else
if ( GS_Settings["iLevel"] == 1 ) and ( ItemLevel ) then
Tooltip:AddLine("iLevel "..ItemLevel)
end
end
end
function GearScore_OnEnter(Name, ItemSlot, Argument)
if ( UnitName("target") ) and CanInspect("target") and CheckInteractDistance("target", 1) then
local now = GetTime()
if (now - GS_LastInspectTime) >= GS_INSPECT_THROTTLE then
GS_LastInspectTime = now
NotifyInspect("target");
end
end
local OriginalOnEnter = GearScore_Original_SetInventoryItem(Name, ItemSlot, Argument);
return OriginalOnEnter
end
----------------------------- Character PaperDoll (Positioned below feet) ------
function MyPaperDoll()
local MyGearScore, MyItemLevel = GearScore_GetScore(UnitName("player"), "player");
local Red, Blue, Green = GearScore_GetQuality(MyGearScore)
if GS_Settings["DKP"] == 1 and GearScoreDKP_GetDKP then
GearScoreDKP_GetDKP();
end
if PersonalGearScore then
PersonalGearScore:SetText("GS: "..MyGearScore);
PersonalGearScore:SetTextColor(Red, Green, Blue, 1);
PersonalGearScore:ClearAllPoints();
if GS_Settings["iLevel"] == 1 then
PersonalGearScore:SetPoint("BOTTOM", CharacterModelFrame, "BOTTOM", 0, 18);
else
PersonalGearScore:SetPoint("BOTTOM", CharacterModelFrame, "BOTTOM", 0, 10);
end
end
if PersonalItemLevel then
if (GS_Settings["iLevel"] == 1) then
PersonalItemLevel:SetText("iLevel: "..MyItemLevel);
PersonalItemLevel:SetTextColor(Red, Green, Blue, 1);
PersonalItemLevel:ClearAllPoints();
PersonalItemLevel:SetPoint("TOP", PersonalGearScore, "BOTTOM", 0, -1);
PersonalItemLevel:Show();
else
PersonalItemLevel:SetText("");
PersonalItemLevel:Hide();
end
end
end
----------------------------- Inspect Window Support ---------------------------
function GearScore_HookInspectUI()
if not InspectPaperDollFrame then return end
if InspectPaperDollFrame.GS_Score then return end
local gsText = InspectPaperDollFrame:CreateFontString("InspectGearScoreText", "OVERLAY")
gsText:SetFont("Fonts\\FRIZQT__.TTF", 11, "OUTLINE")
gsText:SetJustifyH("CENTER")
gsText:SetPoint("BOTTOM", InspectModelFrame or InspectPaperDollFrame, "BOTTOM", 0, 18)
gsText:SetText("GS: 0")
InspectPaperDollFrame.GS_Score = gsText
local ilvlText = InspectPaperDollFrame:CreateFontString("InspectItemLevelText", "OVERLAY")
ilvlText:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
ilvlText:SetJustifyH("CENTER")
ilvlText:SetPoint("TOP", gsText, "BOTTOM", 0, -1)
ilvlText:SetText("")
InspectPaperDollFrame.GS_iLvl = ilvlText
InspectPaperDollFrame:HookScript("OnShow", function()
if InspectFrame and InspectFrame.unit then
GearScore_UpdateInspectFrame(InspectFrame.unit)
end
end)
end
function GearScore_UpdateInspectFrame(unit)
if not InspectPaperDollFrame or not InspectPaperDollFrame.GS_Score then return end
if not unit or not UnitExists(unit) then return end
local name = UnitName(unit)
local score, avg = GearScore_GetScore(name, unit)
if score and score > 0 then
local r, b, g = GearScore_GetQuality(score)
InspectPaperDollFrame.GS_Score:SetText("GS: " .. score)
InspectPaperDollFrame.GS_Score:SetTextColor(r, g, b, 1)
InspectPaperDollFrame.GS_iLvl:SetText("iLevel: " .. avg)
InspectPaperDollFrame.GS_iLvl:SetTextColor(r, g, b, 1)
else
InspectPaperDollFrame.GS_Score:SetText("GS: Cargando...")
InspectPaperDollFrame.GS_Score:SetTextColor(0.7, 0.7, 0.7, 1)
InspectPaperDollFrame.GS_iLvl:SetText("")
end
end
-- Timer for update checker
local timerEnabled = false;
local total = 0;
local function onUpdate(self, elapsed)
if not timerEnabled then return end
total = total + elapsed;
if total >= 5 then
if GS_VerCheck then
timerEnabled = false;
total = 0;
print("Your version of GSLite is up to date");
end
end
end
local timer = CreateFrame("frame");
timer:SetScript("OnUpdate", onUpdate);
----------------------------- Slash Commands -----------------------------------
function GS_MANSET(Command)
if not Command then Command = "" end
local cmd = strlower(Command)
if (cmd == "dkp" ) then
GS_Settings["DKP"] = GS_Settings["DKP"] * -1;
if GS_Settings["DKP"] == 1 then
if GearScoreDKP_GetDKP then GearScoreDKP_GetDKP(); end
print("DKP: On");
else
if PersonalDKP_Net then PersonalDKP_Net:SetText(""); end
if PersonalDKP_Tot then PersonalDKP_Tot:SetText(""); end
print("DKP: Off");
end
return
end
if (cmd == "ilvlmode") then
GS_Settings["iLvlMode"] = GS_Settings["iLvlMode"] * -1;
if GS_Settings["iLvlMode"] == 1 then
GS_Settings["Player"] = -1;
print("Only iLevel will be displayed on player tooltips.");
else
GS_Settings["Player"] = 1;
print("GearScore is now displayed on player tooltips.");
end
return
end
if (cmd == "version") then
print("GSLite Version: "..GS_Version);
print("Requesting updates..");
timerEnabled = true;
GS_VerCheck = true;
if GSU_BroadCast then
GSU_BroadCast("REQUEST", "RAID");
GSU_BroadCast("REQUEST", "GUILD");
end
return
end
if (string.sub(cmd, 1, 3) == "tip") then
if GearScoreTips_PlayerKey and GearScoreToolTip_Broadcast then
GS_MyTip[GearScoreTips_PlayerKey()] = string.sub(Command, 5, 44);
GearScoreToolTip_Broadcast(GS_MyTip[GearScoreTips_PlayerKey()]);
print("Your tooltip is now: "..GS_MyTip[GearScoreTips_PlayerKey()]);
end
return
end
if (string.sub(cmd, 1, 7) == "set dkp") then
local s,e,n = string.find(Command, "set dkp (%d+)");
if n and GearScoreDKP_SetCap then
GearScoreDKP_SetCap(tonumber(n));
print("DKP Max is now "..n);
end
return
end
if (cmd == "ilevel" ) then
GS_Settings["iLevel"] = GS_Settings["iLevel"] * -1;
MyPaperDoll();
if (GS_Settings["iLevel"] == 1) then
print("Item Levels: On");
else
print("Item Levels: Off");
end
return
end
if (cmd == "level") then
GS_Settings["Level"] = GS_Settings["Level"] * -1;
print("Level display toggled.");
return
end
if (cmd == "") or (cmd == "options") or (cmd == "option") or (cmd == "help") then
if GS_CommandList then
for i,v in ipairs(GS_CommandList) do print(v); end
end
return
end
if (cmd == "player") then
GS_Settings["Player"] = GS_ShowSwitch[GS_Settings["Player"]];
if (GS_Settings["Player"] == 1) or (GS_Settings["Player"] == 2) then
print("Player Scores: On");
GS_Settings["iLvlMode"] = -1;
else
print("Player Scores: Off");
end
return
end
if (cmd == "item") then
GS_Settings["Item"] = GS_ItemSwitch[GS_Settings["Item"]];
if (GS_Settings["Item"] == 1) or (GS_Settings["Item"] == 3) then
print("Item Scores: On");
else
print("Item Scores: Off");
end
return
end
if (cmd == "compare") then
GS_Settings["Compare"] = GS_Settings["Compare"] * -1;
if (GS_Settings["Compare"] == 1) then
print("Comparisons: On");
else
print("Comparisons: Off");
end
return
end
if (cmd == "clearcache" or cmd == "wipe") then
GS_Cache = {}
print("GearScoreLite: Memoria caché reiniciada.");
return
end
print("GearScore: Unknown Command. Type '/gs' for a list of options")
end
------------------------ GUI REGISTRATION --------------------------------------
local f = CreateFrame("Frame", "GearScore", UIParent);
f:SetScript("OnEvent", GearScore_OnEvent);
f:RegisterEvent("PLAYER_EQUIPMENT_CHANGED");
f:RegisterEvent("ADDON_LOADED");
f:RegisterEvent("INSPECT_READY");
GameTooltip:HookScript("OnTooltipSetUnit", GearScore_HookSetUnit)
GameTooltip:HookScript("OnTooltipSetItem", GearScore_HookSetItem)
ShoppingTooltip1:HookScript("OnTooltipSetItem", GearScore_HookCompareItem)
ShoppingTooltip2:HookScript("OnTooltipSetItem", GearScore_HookCompareItem2)
ItemRefTooltip:HookScript("OnTooltipSetItem", GearScore_HookRefItem)
PaperDollFrame:HookScript("OnShow", MyPaperDoll)
-- Create FontStrings on CharacterModelFrame for perfect 3D centering below feet
CharacterModelFrame:CreateFontString("PersonalGearScore", "OVERLAY")
CharacterModelFrame:CreateFontString("PersonalItemLevel", "OVERLAY")
PaperDollFrame:CreateFontString("PersonalDKP_Tot", "OVERLAY")
PaperDollFrame:CreateFontString("PersonalDKP_Net", "OVERLAY")
-- DKP Total
PersonalDKP_Tot:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
PersonalDKP_Tot:SetText("")
PersonalDKP_Tot:SetPoint("BOTTOMRIGHT", CharacterModelFrame, "BOTTOMRIGHT", -10, 10)
PersonalDKP_Tot:Show()
-- DKP Net
PersonalDKP_Net:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
PersonalDKP_Net:SetText("")
PersonalDKP_Net:SetPoint("BOTTOMRIGHT", PersonalDKP_Tot, "TOPRIGHT", 0, 2)
PersonalDKP_Net:Show()
-- GS (Centered directly below character feet)
PersonalGearScore:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
PersonalGearScore:SetText("GS: 0")
PersonalGearScore:SetJustifyH("CENTER")
PersonalGearScore:SetPoint("BOTTOM", CharacterModelFrame, "BOTTOM", 0, 18)
PersonalGearScore:Show()
-- iLvl (Stacked neatly under GS)
PersonalItemLevel:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
PersonalItemLevel:SetText("")
PersonalItemLevel:SetJustifyH("CENTER")
PersonalItemLevel:SetPoint("TOP", PersonalGearScore, "BOTTOM", 0, -1)
PersonalItemLevel:Show()
GearScore_Original_SetInventoryItem = GameTooltip.SetInventoryItem
GameTooltip.SetInventoryItem = GearScore_OnEnter
SlashCmdList["MY2SCRIPT"] = GS_MANSET
SLASH_MY2SCRIPT1 = "/gs"
SLASH_MY2SCRIPT2 = "/gearscore"
-- Check if Blizzard_InspectUI is already loaded at init
if IsAddOnLoaded("Blizzard_InspectUI") then
GearScore_HookInspectUI()
end