forked from whatisboom/EnchantCheck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
executable file
·761 lines (678 loc) · 23.2 KB
/
main.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
----------------------------------------------
-- Module
----------------------------------------------
EnchantCheck = LibStub("AceAddon-3.0"):NewAddon("Enchant Check", "AceConsole-3.0", "AceEvent-3.0", "AceHook-3.0", "AceTimer-3.0");
----------------------------------------------
-- Localization
----------------------------------------------
local L = LibStub("AceLocale-3.0"):GetLocale("EnchantCheck", true)
local LI = LibStub("LibBabble-Inventory-3.0"):GetLookupTable()
----------------------------------------------
-- Other libs
----------------------------------------------
local libItemUpgrade = LibStub("LibItemUpgradeInfo-1.0")
----------------------------------------------
-- Version
----------------------------------------------
EnchantCheck.version = "@project-version@"
EnchantCheck.authors = "nyyr, bsmorgan, whatisboom"
-- Current max level for automated self-checks
local MAX_LEVEL = 60
-- Setup class colors
local ClassColor = {
["MAGE"] = "69CCF0",
["WARLOCK"] = "9482C9",
["PRIEST"] = "FFFFFF",
["DRUID"] = "FF7D0A",
["SHAMAN"] = "0070DE",
["PALADIN"] = "F58CBA",
["ROGUE"] = "FFF569",
["HUNTER"] = "ABD473",
["WARRIOR"] = "C79C6E",
["DEATHKNIGHT"] = "C41F3B",
["MONK"] = "00FF96",
["DEMONHUNTER"] = "A330C9",
["EVOKER"] = "33937F",
}
-- What slots need enchants?
local CheckSlotEnchant = {
[INVSLOT_HEAD] = false,
[INVSLOT_NECK] = false,
[INVSLOT_SHOULDER] = false,
[INVSLOT_BACK] = true,
[INVSLOT_CHEST] = true,
[INVSLOT_BODY] = false, -- shirt
[INVSLOT_TABARD] = false,
[INVSLOT_WRIST] = true,
[INVSLOT_HAND] = false,
[INVSLOT_WAIST] = false,
[INVSLOT_LEGS] = true,
[INVSLOT_FEET] = true,
[INVSLOT_FINGER1] = true,
[INVSLOT_FINGER2] = true,
[INVSLOT_TRINKET1] = false,
[INVSLOT_TRINKET2] = false,
[INVSLOT_MAINHAND] = true,
[INVSLOT_OFFHAND] = true,
}
-- What slots must have an item?
local CheckSlotMissing = {
[INVSLOT_HEAD] = true,
[INVSLOT_NECK] = true,
[INVSLOT_SHOULDER] = true,
[INVSLOT_BACK] = true,
[INVSLOT_CHEST] = true,
[INVSLOT_BODY] = false, -- shirt
[INVSLOT_TABARD] = false,
[INVSLOT_WRIST] = true,
[INVSLOT_HAND] = true,
[INVSLOT_WAIST] = true,
[INVSLOT_LEGS] = true,
[INVSLOT_FEET] = true,
[INVSLOT_FINGER1] = true,
[INVSLOT_FINGER2] = true,
[INVSLOT_TRINKET1] = true,
[INVSLOT_TRINKET2] = true,
[INVSLOT_MAINHAND] = true,
[INVSLOT_OFFHAND] = true,
}
-- Which main-hand weapons require an off-hand item?
local CheckOffHand = {
[LI["Bows"]] = false,
[LI["Crossbows"]] = false,
[LI["Daggers"]] = true,
[LI["Guns"]] = false,
[LI["Fishing Poles"]] = false,
[LI["Fist Weapons"]] = true,
[LI["Miscellaneous"]] = true,
[LI["One-Handed Axes"]] = true,
[LI["One-Handed Maces"]] = true,
[LI["One-Handed Swords"]] = true,
[LI["Polearms"]] = false,
[LI["Staves"]] = false,
[LI["Thrown"]] = false,
[LI["Two-Handed Axes"]] = false,
[LI["Two-Handed Maces"]] = false,
[LI["Two-Handed Swords"]] = false,
[LI["Wands"]] = true,
}
----------------------------------------------
-- Config options
----------------------------------------------
EnchantCheck.defaults = {
profile = {
enable = true,
rescanTimer = 1,
rescanCount = 2,
},
}
----------------------------------------------
-- Debugging levels
-- 0 Off
-- 1 Warning
-- 2 Info
-- 3 Notice
----------------------------------------------
local d_warn = 1
local d_info = 2
local d_notice = 3
local debugLevel = d_warn
----------------------------------------------
-- Print debug message
----------------------------------------------
function EnchantCheck:Debug(level, msg, ...)
if (level <= debugLevel) then
self:Printf(msg, ...)
end
end
----------------------------------------------
--- Init
----------------------------------------------
function EnchantCheck:OnInitialize()
-- Load our database
self.db = LibStub("AceDB-3.0"):New("EnchantCheckDB", EnchantCheck.defaults, "profile");
EnchantCheckFrameTitle:SetText("Enchant Check "..self.version);
CharacterFrameEnchantCheckButton:SetText(L["BTN_CHECK_ENCHANTS"]);
InspectFrameEnchantCheckButton:SetText(L["BTN_CHECK_ENCHANTS"]);
EnchantCheckItemsFrame.titleFont:SetText(L["UI_ITEMS_TITLE"]);
EnchantCheckGemsFrame.titleFont:SetText(L["UI_GEMS_TITLE"]);
EnchantCheckEnchantsFrame.titleFont:SetText(L["UI_ENCHANTS_TITLE"]);
if self.db.profile.enable then
self:Enable();
end
self:Debug(d_notice, L["LOADED"]);
end
----------------------------------------------
-- OnEnable()
----------------------------------------------
function EnchantCheck:OnEnable()
self:RegisterEvent("INSPECT_READY");
self:RegisterEvent("UNIT_INVENTORY_CHANGED");
self:RegisterEvent("PLAYER_ENTERING_WORLD");
self:RegisterEvent("PLAYER_LOGIN");
self:Debug(d_notice, L["ENABLED"]);
end
----------------------------------------------
-- OnDisable()
----------------------------------------------
function EnchantCheck:OnDisable()
self:UnregisterEvent("INSPECT_READY");
self:UnregisterEvent("UNIT_INVENTORY_CHANGED");
self:UnregisterEvent("PLAYER_ENTERING_WORLD");
self:UnregisterEvent("PLAYER_LOGIN");
self:Debug(d_notice, L["DISABLED"]);
end
----------------------------------------------
-- OnConfigUpdate()
----------------------------------------------
function EnchantCheck:OnConfigUpdate()
-- Enable
if (self.db.profile.enable) then
if not EnchantCheck:IsEnabled() then
EnchantCheck:Enable()
end
else
if EnchantCheck:IsEnabled() then
EnchantCheck:Disable()
end
end
end
----------------------------------------------
-- Item link functions
----------------------------------------------
function EnchantCheck:GetActualItemLevel(link)
if (link) then
return libItemUpgrade:GetUpgradedItemLevel(link)
else
return 0
end
end
function EnchantCheck:GetItemLinkInfo(link)
local itemColor, itemString, itemName;
local pattern = "(|c%x+)|Hitem:([-%d:]*)|h%[(.-)%]|h|r";
local itemColorPattern = "(|c%x+)";
local itemStringPattern = "|Hitem:([-%d:]*)";
local itemNamePattern = "|h%[(.-)%]|h|r";
-- print("link", link);
if ( link ) then
itemColor = link:match(itemColorPattern);
itemString = link:match(itemStringPattern);
itemName = link:match(itemNamePattern);
-- itemColor, itemString, itemName = link:match(pattern);
-- print("link:match", link:match(pattern));
-- print("itemColor", itemColor);
-- print("itemString", itemString);
-- print("itemName", itemName);
end
return itemName, itemString, itemColor;
end
function EnchantCheck:GetItemId(link)
local itemId, suffixId;
if ( link ) then
itemId, suffixId = link:match("item:([-%d]+):[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([-%d]+)");
if ( not itemId ) then
itemId = link:match("item:([-%d]+)");
end
end
return itemId, suffixId;
end
----------------------------------------------
-- Item string functions
----------------------------------------------
function EnchantCheck:StringSplit(separator, value)
local fields = {};
gsub(value..separator, "([^"..separator.."]*)"..separator, function(v) table.insert(fields, v) end);
return fields;
end
function EnchantCheck:SplitValue(value)
if ( value == "" ) then
value = "0"
end
return tonumber(value)
end
local gemIds = {};
function EnchantCheck:GetItemGemString(link)
local _, itemString = self:GetItemLinkInfo(link);
local gemString;
-- itemId:enchantId:jewelId1:jewelId2:jewelId3:jewelId4:suffixId:uniqueId:linkLevel
if ( itemString ) then
print("itemString", itemString);
local ids = self:StringSplit(":", itemString);
local gemLink, hasGems;
for i = 1, 4 do
gemIds[i] = "0";
if ( ids[i + 2] ~= "0" and ids[i + 2] ~= "" ) then
_, gemLink = _G.GetItemGem(link, i);
if ( gemLink ) then
hasGems = true;
gemIds[i] = self:GetItemId(gemLink);
end
end
end
if ( hasGems ) then
gemString = table.concat(gemIds, ":");
end
end
return gemString;
end
----------------------------------------------
-- CheckGear(unit)
----------------------------------------------
function EnchantCheck:CheckGear(unit, items, iter, printWarnings)
local report = {}
local warnings = {}
local missingItems = {}
local missingGems = {}
local missingEnchants = {}
local missingBlacksmithGems = {}
local hasMissingItems, hasMissingEnchants, hasMissingGems, hasMissingBlacksmithGems
local hasMissingBeltGem
local twoHanded
local itemLevelMin = 0
local itemLevelMax = 0
local itemLevelSum = 0
local avgItemLevel = 0
local doRescan
local statStrings = {
["STRENGTH"] = "STRENGTH",
["AGILITY"] = "AGILITY",
["INTELLECT"] = "INTELLECT",
};
local primaryStats = {
[1] = statStrings.STRENGTH,
[2] = statStrings.AGILITY,
[4] = statStrings.INTELLECT,
};
-- print("unit", unit);
local isInspect = not UnitIsUnit("player", unit);
-- print("isInspect", isInspect);
local currentSpec = GetSpecialization();
-- if isInspect and currentSpec == nil then
-- currentSpec = GetInspectSpecialization(unit);
-- end
-- print("currentSpec", currentSpec);
local primaryStatIndex = select(6, GetSpecializationInfo(currentSpec));
local primaryStat = primaryStats[primaryStatIndex];
-- -- No Longer needed as DF doesn't support primary stats in these slots
-- if isInspect then
-- -- cannot determine accurately primary stat for inspected targets
-- -- https://wowpedia.fandom.com/wiki/API_GetSpecializationInfo#Details
-- CheckSlotEnchant[INVSLOT_FEET] = true;
-- CheckSlotEnchant[INVSLOT_WRIST] = true;
-- CheckSlotEnchant[INVSLOT_HAND] = true;
-- elseif primaryStat == statStrings.AGILITY then
-- CheckSlotEnchant[INVSLOT_FEET] = true;
-- CheckSlotEnchant[INVSLOT_WRIST] = false;
-- CheckSlotEnchant[INVSLOT_HAND] = false;
-- elseif primaryStat == statStrings.STRENGTH then
-- CheckSlotEnchant[INVSLOT_FEET] = false;
-- CheckSlotEnchant[INVSLOT_WRIST] = false;
-- CheckSlotEnchant[INVSLOT_HAND] = true;
-- elseif primaryStat == statStrings.INTELLECT then
-- CheckSlotEnchant[INVSLOT_FEET] = false;
-- CheckSlotEnchant[INVSLOT_WRIST] = true;
-- CheckSlotEnchant[INVSLOT_HAND] = false;
-- end
if not items then items = {} end
if not iter then iter = 0 end
self.scanInProgress = true
libItemUpgrade:CleanCache()
-- iterate over equipment slots
for i = 1,18 do
local itemName, itemLink, itemRarity, itemLevel, itemMinLevel,
itemType, itemSubType, itemStackCount, itemEquipLoc,
itemTexture, itemSellPrice
local item = {}
item.id = GetInventoryItemID(unit, i)
item.link = GetInventoryItemLink(unit, i)
if item.link then
itemName, itemLink, itemRarity, itemLevel, itemMinLevel,
itemType, itemSubType, itemStackCount, itemEquipLoc,
itemTexture, itemSellPrice = GetItemInfo(item.link)
end
if item.link and itemLink then
-- print("slot= "..tostring(i)..", itemName= "..tostring(itemName))
local printable = gsub(itemLink, "\124", "\124\124");
-- print("itemLink: \""..printable.."\"")
local _, itemString = self:GetItemLinkInfo(item.link)
-- print("itemString: \""..itemString.."\"")
local ids = self:StringSplit(":", itemString)
-- print("#ids= "..tostring(#ids))
-- itemId:enchantId:jewelId1:jewelId2:jewelId3:jewelId4:suffixId:uniqueId:linkLevel
Enchant = self:SplitValue(ids[2])
Gem1 = self:SplitValue(ids[3])
Gem2 = self:SplitValue(ids[4])
Gem3 = self:SplitValue(ids[5])
Gem4 = self:SplitValue(ids[6])
LinkLvl= self:SplitValue(ids[9])
-- print("Enchant= "..tostring(Enchant)..", Gem1= "..tostring(Gem1)..", Gem2= "..tostring(Gem2)..", Gem3= "..tostring(Gem3)..", Gem4= "..tostring(Gem4)..", LinkLvl= "..tostring(LinkLvl))
-- gems
item.gems = 0
if Gem1 > 0 then item.gems = item.gems + 1 end
if Gem2 > 0 then item.gems = item.gems + 1 end
if Gem3 > 0 then item.gems = item.gems + 1 end
if Gem4 > 0 then item.gems = item.gems + 1 end
-- misc
item.rarity = itemRarity
item.stats = GetItemStats(item.link)
-- sockets
item.sockets =
(item.stats['EMPTY_SOCKET_RED'] or 0) +
(item.stats['EMPTY_SOCKET_YELLOW'] or 0) +
(item.stats['EMPTY_SOCKET_BLUE'] or 0) +
(item.stats['EMPTY_SOCKET_META'] or 0) +
(item.stats['EMPTY_SOCKET_PRISMATIC'] or 0) +
(item.stats['EMPTY_SOCKET_DOMINATION'] or 0) +
(item.stats['EMPTY_SOCKET_PRIMORDIAL'] or 0)
-- missing gems
if item.gems < item.sockets then
table.insert(missingGems, i)
hasMissingGems = true
end
-- enchant
item.enchant = Enchant -- enchant ID
if (item.enchant == 0) and CheckSlotEnchant[i] then
if (not (libItemUpgrade:IsArtifact(item.link) or (i == INVSLOT_OFFHAND and itemType ~= WEAPON))) then
table.insert(missingEnchants, i)
hasMissingEnchants = true
end
end
-- item level
item.level = self:GetActualItemLevel(item.link)
-- print("slot= "..tostring(i)..", item.level= "..tostring(item.level))
if (i ~= INVSLOT_BODY) and (i ~= INVSLOT_TABARD) then
if item.level < itemLevelMin or itemLevelMin == 0 then
itemLevelMin = item.level
end
if item.level > itemLevelMax then
itemLevelMax = item.level
end
itemLevelSum = itemLevelSum + item.level
end
-- two-hander?
if i == INVSLOT_MAINHAND then
twoHanded = not CheckOffHand[itemSubType]
end
elseif item.id then
--self:Debug(d_warn, "Item link for ID "..tostring(item.id).." not ready yet!")
doRescan = true
else
if CheckSlotMissing[i] and ((i ~= INVSLOT_OFFHAND) or not twoHanded) then
table.insert(missingItems, i)
hasMissingItems = true
end
end
items[i] = item
end
if doRescan then
if iter < self.db.profile.rescanCount then
self:Debug(d_info, "|cffFFFF00" .. L["RESCAN"] .. "|cffFFFFFF")
self.rescanTimer = self:ScheduleTimer("CheckGear", self.db.profile.rescanTimer, unit, items, iter+1)
return
else
self:Debug(d_warn, "|cffFF0000" .. L["SCAN_INCOMPLETE"] .. "|cffFFFFFF")
self.scanInProgress = nil
return
end
end
local items_state = true
local gems_state = true
local enchants_state = true
-- header
table.insert(report, "------------")
local displayClass, class = UnitClass(unit)
local name = UnitName(unit)
table.insert(report, string.format(L["ENCHANT_REPORT_HEADER"],
"|cff"..ClassColor[class]..name.."|cffFFFFFF",
UnitLevel(unit), "|cff"..ClassColor[class]..displayClass.."|cffFFFFFF"))
-- average item level
if twoHanded then
avgItemLevel = itemLevelSum / 15
else
avgItemLevel = itemLevelSum / 16
end
table.insert(report, string.format(L["AVG_ITEM_LEVEL"], floor(avgItemLevel), itemLevelMin, itemLevelMax))
EnchantCheckItemsFrame.titleInfoFont:SetText(string.format("%d (%d -> %d)", floor(avgItemLevel), itemLevelMin, itemLevelMax))
-- check for extremely low item levels
for i = 1,18 do
if items[i].link then
if (items[i].level < avgItemLevel*0.8) and
(i ~= INVSLOT_BODY) and (i ~= INVSLOT_TABARD) and
(items[i].rarity ~= 7) -- heirloom
then
table.insert(report, "|cffFF0000"..L["LOW_ITEM_LEVEL"].."|cffFFFFFF "..items[i].link)
table.insert(warnings, report[#report])
EnchantCheckItemsFrame.messages:AddMessage(report[#report])
items_state = false
end
end
end
-- check for missing items
if hasMissingItems then
local s = ""
for k,i in ipairs(missingItems) do
s = s .. L["INVSLOT_"..i]
if k < #missingItems then
s = s .. ", "
end
end
table.insert(report, "|cffFF0000" .. L["MISSING_ITEMS"] .. "|cffFFFFFF " .. s)
table.insert(warnings, report[#report])
EnchantCheckItemsFrame.messages:AddMessage(report[#report])
items_state = false
end
-- check for missing gems
if hasMissingGems then
local s = ""
for k,i in ipairs(missingGems) do
s = s .. L["INVSLOT_"..i]
if k < #missingGems then
s = s .. ", "
end
end
table.insert(report, "|cffFF0000" .. L["MISSING_GEMS"] .. "|cffFFFFFF " .. s)
table.insert(warnings, report[#report])
EnchantCheckGemsFrame.messages:AddMessage(report[#report])
gems_state = false
else
table.insert(report, "|cff00FF00" .. L["PROPER_GEMS"] .. "|cffFFFFFF ")
EnchantCheckGemsFrame.messages:AddMessage(report[#report])
end
--[[ belt buckle (no longer available in at level 100)
if hasMissingBeltGem then
table.insert(report, "|cffFFFF00" .. L["MISSING_BELT_BUCKLE"] .. "|cffFFFFFF")
table.insert(warnings, report[#report])
EnchantCheckGemsFrame.messages:AddMessage(report[#report])
end
]]
--[[ check for missing blacksmith gems (no longer available in at level 100)
if hasMissingBlacksmithGems then
local s = ""
for k,i in ipairs(missingBlacksmithGems) do
s = s .. L["INVSLOT_"..i]
if k < #missingBlacksmithGems then
s = s .. ", "
end
end
table.insert(report, "|cffFFFF00" .. L["MISSING_BS_SOCKETS"] .. "|cffFFFFFF " .. s)
table.insert(warnings, report[#report])
EnchantCheckGemsFrame.messages:AddMessage(report[#report])
end
]]
-- check for missing enchants
if hasMissingEnchants then
local s = ""
for k,i in ipairs(missingEnchants) do
s = s .. L["INVSLOT_"..i]
if k < #missingEnchants then
s = s .. ", "
end
end
table.insert(report, "|cffFF0000" .. L["MISSING_ENCHANTS"] .. "|cffFFFFFF " .. s)
table.insert(warnings, report[#report])
EnchantCheckEnchantsFrame.messages:AddMessage(report[#report])
enchants_state = false
else
table.insert(report, "|cff00FF00" .. L["PROPER_ENCHANTS"] .. "|cffFFFFFF ")
EnchantCheckEnchantsFrame.messages:AddMessage(report[#report])
end
-- footer
table.insert(report, "------------")
self:SetCheckFrame(EnchantCheckItemsFrame, items_state)
self:SetCheckFrame(EnchantCheckGemsFrame, gems_state)
self:SetCheckFrame(EnchantCheckEnchantsFrame, enchants_state)
-- print to self
if printWarnings then
for i,v in ipairs(warnings) do
self:Print(v)
end
end
self.scanInProgress = nil
end
----------------------------------------------
-- CheckCharacter()
----------------------------------------------
function EnchantCheck:CheckCharacter()
if not self.scanInProgress then
if EnchantCheckFrame:GetParent() ~= CharacterModelScene then
EnchantCheckFrame:Hide()
EnchantCheckFrame:SetParent(CharacterModelScene)
EnchantCheckFrame:ClearAllPoints()
EnchantCheckFrame:SetAllPoints()
elseif EnchantCheckFrame:IsShown() then
EnchantCheckFrame:Hide()
return
end
EnchantCheck:ClearCheckFrame(EnchantCheckItemsFrame)
EnchantCheck:ClearCheckFrame(EnchantCheckGemsFrame)
EnchantCheck:ClearCheckFrame(EnchantCheckEnchantsFrame)
EnchantCheckFrame:Show()
self:CheckGear("player")
end
end
----------------------------------------------
-- CheckInspected()
----------------------------------------------
function EnchantCheck:CheckInspected()
if InspectFrame.unit and CanInspect(InspectFrame.unit) then
if not self.scanInProgress then
if EnchantCheckFrame:GetParent() ~= InspectModelFrame then
EnchantCheckFrame:Hide()
EnchantCheckFrame:SetParent(InspectModelFrame)
EnchantCheckFrame:ClearAllPoints()
EnchantCheckFrame:SetAllPoints()
elseif EnchantCheckFrame:IsShown() then
EnchantCheckFrame:Hide()
return
end
EnchantCheck:ClearCheckFrame(EnchantCheckItemsFrame)
EnchantCheck:ClearCheckFrame(EnchantCheckGemsFrame)
EnchantCheck:ClearCheckFrame(EnchantCheckEnchantsFrame)
EnchantCheckFrame:Show()
self:Debug(d_info, "|cff00FF00" .. L["SCAN"] .. "|cffFFFFFF")
NotifyInspect(InspectFrame.unit)
self.pendingInspection = true
end
else
self:Debug(d_warn, "No inspected unit found!")
end
end
----------------------------------------------
-- ClearCheckFrame(frame)
----------------------------------------------
function EnchantCheck:ClearCheckFrame(frame)
-- clean up
frame.titleFont:SetTextColor(1, 1, 0)
frame.titleInfoFont:SetText("")
frame.readyTex:Hide()
frame.notReadyTex:Hide()
frame.waitingTex:Show()
frame.messages:Clear()
end
----------------------------------------------
-- SetCheckFrame(frame, value)
-- value: nil/false - red, 1/true - green, anything else - yellow
----------------------------------------------
function EnchantCheck:SetCheckFrame(frame, value)
if value == 1 or value == true then
frame.titleFont:SetTextColor(0, 1, 0)
frame.readyTex:Show()
frame.notReadyTex:Hide()
frame.waitingTex:Hide()
elseif not value then
frame.titleFont:SetTextColor(1, 0, 0)
frame.readyTex:Hide()
frame.notReadyTex:Show()
frame.waitingTex:Hide()
else
frame.titleFont:SetTextColor(1, 1, 0)
frame.readyTex:Hide()
frame.notReadyTex:Hide()
frame.waitingTex:Show()
end
end
----------------------------------------------
-- INSPECT_READY()
----------------------------------------------
function EnchantCheck:INSPECT_READY(event, guid)
-- inspect frame is load-on-demand, add buttons once it is loaded
if not InspectFrameEnchantCheckButton:GetParent() and InspectPaperDollFrame then
local isElvUILoaded = IsAddOnLoaded("ElvUI");
local topPosition = isElvUILoaded and -50 or 20;
InspectFrameEnchantCheckButton:SetParent(InspectPaperDollFrame);
InspectFrameEnchantCheckButton:ClearAllPoints();
InspectFrameEnchantCheckButton:SetPoint("LEFT", InspectPaperDollFrame, "BOTTOMLEFT", 10, topPosition);
InspectFrameEnchantCheckButton:Show();
self:HookScript(InspectFrame, "OnHide", "InspectFrame_OnHide");
--self:Debug(d_notice, "Added inspect buttons")
end
--self:Debug(d_notice, "INSPECT_READY")
if self.pendingInspection and (UnitGUID(InspectFrame.unit) == guid) then
if EnchantCheckFrame:IsShown() then
self:CheckGear(InspectFrame.unit)
end
self.pendingInspection = nil
end
end
----------------------------------------------
-- UNIT_INVENTORY_CHANGED()
----------------------------------------------
function EnchantCheck:UNIT_INVENTORY_CHANGED(event, unit)
if EnchantCheckFrame:IsShown() then
EnchantCheckFrame:Hide()
EnchantCheck:ClearCheckFrame(EnchantCheckItemsFrame)
EnchantCheck:ClearCheckFrame(EnchantCheckGemsFrame)
EnchantCheck:ClearCheckFrame(EnchantCheckEnchantsFrame)
end
end
----------------------------------------------
-- InspectFrame_OnHide()
----------------------------------------------
function EnchantCheck:InspectFrame_OnHide()
if EnchantCheckFrame:IsShown() then
EnchantCheckFrame:Hide()
EnchantCheck:ClearCheckFrame(EnchantCheckItemsFrame)
EnchantCheck:ClearCheckFrame(EnchantCheckGemsFrame)
EnchantCheck:ClearCheckFrame(EnchantCheckEnchantsFrame)
end
end
----------------------------------------------
-- PLAYER_ENTERING_WORLD()
----------------------------------------------
function EnchantCheck:PLAYER_ENTERING_WORLD(event)
local inInstance, instanceType = IsInInstance()
if inInstance and (instanceType ~= "none") and (UnitLevel("player") == MAX_LEVEL) then
self:CheckGear("player", nil, nil, true)
end
end
----------------------------------------------
-- PLAYER_LOGIN()
----------------------------------------------
function EnchantCheck:PLAYER_LOGIN(event)
local isElvUILoaded = IsAddOnLoaded("ElvUI");
local checkButton = CharacterFrameEnchantCheckButton;
if isElvUILoaded and checkButton then
checkButton:ClearAllPoints();
checkButton:SetPoint("RIGHT", checkButton:GetParent(), "BOTTOMRIGHT", "-10", "15");
end
end