-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathInspectCore.lua
More file actions
146 lines (136 loc) · 4.46 KB
/
InspectCore.lua
File metadata and controls
146 lines (136 loc) · 4.46 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
-------------------------------------
-- InspectCore Author: M
-------------------------------------
local _, ns = ...
local T = ns.T
local LibEvent = LibStub:GetLibrary("LibEvent.7000")
local LibSchedule = LibStub:GetLibrary("LibSchedule.7000")
local LibItemInfo = LibStub:GetLibrary("LibItemInfo.7000")
local guids, inspecting = {}, false
-- Global API
function GetInspectInfo(unit, timelimit)
local guid = T:UnitGUID(unit)
if (not guid or not guids[guid]) then return end
if (not timelimit or timelimit == 0) then
return guids[guid]
end
if (guids[guid].timer > time()-timelimit) then
return guids[guid]
end
end
-- Global API
function GetInspecting()
if (InspectFrame and InspectFrame.unit) then
local guid = UnitGUID(InspectFrame.unit)
return guids[guid] or { inuse = true }
end
if (inspecting and inspecting.expired > time()) then
return inspecting
end
end
-- Global API @trigger UNIT_REINSPECT_READY
function ReInspect(unit)
local guid = T:UnitGUID(unit)
if (not guid) then return end
local data = guids[guid]
if (not data) then return end
LibSchedule:AddTask({
identity = guid,
timer = 0.5,
elasped = 0.5,
expired = GetTime() + 3,
data = data,
unit = unit,
onExecute = function(self)
local count, ilevel, _, weaponLevel, isArtifact, maxLevel = LibItemInfo:GetUnitItemLevel(self.unit)
if (ilevel <= 0) then return true end
if (count == 0 and ilevel > 0) then
self.data.timer = time()
self.data.ilevel = ilevel
self.data.maxLevel = maxLevel
self.data.weaponLevel = weaponLevel
self.data.isArtifact = isArtifact
LibEvent:trigger("UNIT_REINSPECT_READY", self.data)
return true
end
end,
})
end
-- Global API
function GetInspectSpec(unit)
local specID, specName
if (unit == "player") then
specID = C_SpecializationInfo.GetSpecialization()
specName = select(2, C_SpecializationInfo.GetSpecializationInfo(specID))
else
specID = GetInspectSpecialization(unit)
if (specID and specID > 0) then
specName = select(2, GetSpecializationInfoByID(specID))
end
end
return specName or ""
end
-- Clear
hooksecurefunc("ClearInspectPlayer", function()
inspecting = false
end)
-- @trigger UNIT_INSPECT_STARTED
hooksecurefunc("NotifyInspect", function(unit)
local guid = T:UnitGUID(unit)
if (not guid) then return end
local data = guids[guid]
if (data) then
data.unit = unit
data.name, data.realm = UnitName(unit)
else
data = {
unit = unit,
guid = guid,
class = select(2, UnitClass(unit)),
level = UnitLevel(unit),
ilevel = -1,
spec = nil,
timer = time(),
}
data.name, data.realm = UnitName(unit)
guids[guid] = data
end
if (not data.realm) then
data.realm = GetRealmName()
end
data.expired = time() + 3
inspecting = data
LibEvent:trigger("UNIT_INSPECT_STARTED", data)
end)
-- @trigger UNIT_INSPECT_READY
LibEvent:attachEvent("INSPECT_READY", function(this, guid)
local unit = guids[guid] and guids[guid].unit
if not unit or T:UnitGUID(unit) ~= guid then
return
end
LibSchedule:AddTask({
identity = guid,
timer = 0.1,
elasped = 0.1,
expired = GetTime() + 3,
data = guids[guid],
onTimeout = function(self) inspecting = false end,
onExecute = function(self)
local count, ilevel, _, weaponLevel, isArtifact, maxLevel = LibItemInfo:GetUnitItemLevel(self.data.unit)
if (ilevel <= 0) then return true end
if (count == 0 and ilevel > 0) then
self.data.timer = time()
self.data.name = UnitName(self.data.unit)
self.data.class = select(2, UnitClass(self.data.unit))
self.data.ilevel = ilevel
self.data.maxLevel = maxLevel
self.data.spec = GetInspectSpec(self.data.unit)
self.data.weaponLevel = weaponLevel
self.data.isArtifact = isArtifact
LibEvent:trigger("UNIT_INSPECT_READY", self.data)
inspecting = false
return true
end
end,
})
end)