-
Notifications
You must be signed in to change notification settings - Fork 19
/
pawn.lua
120 lines (101 loc) · 3.78 KB
/
pawn.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
--[[
TacoTip Pawn Score module by kebabstorm
for Classic/TBC/WOTLK
Requires: Pawn 2.5.38+
--]]
local clientVersionString = GetBuildInfo()
local clientBuildMajor = string.byte(clientVersionString, 1)
-- load only on classic/tbc/wotlk
if (clientBuildMajor < 49 or clientBuildMajor > 51 or string.byte(clientVersionString, 2) ~= 46) then
return
end
local isPawnLoaded = PawnClassicLastUpdatedVersion and PawnClassicLastUpdatedVersion >= 2.0538
if (not isPawnLoaded) then
return
end
assert(LibStub, "TacoTip requires LibStub")
assert(LibStub:GetLibrary("LibClassicInspector", true), "TacoTip requires LibClassicInspector")
assert(LibStub:GetLibrary("LibDetours-1.0", true), "TacoTip requires LibDetours-1.0")
local CI = LibStub("LibClassicInspector")
local GUIDIsPlayer = C_PlayerInfo.GUIDIsPlayer
TT_PAWN = {}
local function getPlayerGUID(arg)
if (arg) then
if (GUIDIsPlayer(arg)) then
return arg
elseif (UnitIsPlayer(arg)) then
return UnitGUID(arg)
end
end
return nil
end
function TT_PAWN:GetItemScore(itemLink, class, specIndex)
if (itemLink and class and specIndex) then
local item = PawnGetItemData(itemLink)
if (item) then
return tonumber(select(2,PawnGetSingleValueFromItem(item,"\"Classic\":"..class..specIndex))) or 0
end
end
return 0
end
local function itemcacheCB(tbl, id)
for i=1,#tbl.items do
if (id == tbl.items[i]) then
table.remove(tbl.items, i)
end
end
if (#tbl.items == 0) then
TacoTip_GSCallback(tbl.guid)
end
end
function TT_PAWN:GetScore(unitorguid, useCallback)
local guid = getPlayerGUID(unitorguid)
if (guid) then
if (guid ~= UnitGUID("player")) then
local _, invTime = CI:GetLastCacheTime(guid)
if(invTime == 0) then
return 0, "", "|cffffffff"
end
end
local spec = CI:GetSpecialization(guid)
local _, class = GetPlayerInfoByGUID(guid)
local pawnScore = 0
local IsReady = true
if (spec and class) then
local scaleName = "\"Classic\":"..class..spec
local cb_table
if (useCallback) then
cb_table = {["guid"] = guid, ["items"] = {}}
end
for i = 1, 18 do
if (i ~= 4) then
local item = CI:GetInventoryItemMixin(guid, i)
if (item) then
if (item:IsItemDataCached()) then
local tempScore = TT_PAWN:GetItemScore(item:GetItemLink(),class,spec)
pawnScore = pawnScore + tempScore
else
IsReady = false
local itemID = item:GetItemID()
if (itemID) then
if (useCallback) then
table.insert(cb_table.items, itemID)
item:ContinueOnItemLoad(function()
itemcacheCB(cb_table, itemID)
end)
else
C_Item.RequestLoadItemDataByID(itemID)
end
end
end
end
end
end
if (not IsReady) then
pawnScore = 0
end
return pawnScore, CI:GetSpecializationName(class, spec, true), PawnGetScaleColor(scaleName, true) or "|cffffffff"
end
end
return 0, "", "|cffffffff"
end