-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInspectCore.lua
More file actions
116 lines (105 loc) · 3.38 KB
/
InspectCore.lua
File metadata and controls
116 lines (105 loc) · 3.38 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
-------------------------------------
-- InspectCore Author: M
-------------------------------------
local LibEvent = LibStub:GetLibrary("LibEvent.7000")
local LibSchedule = LibStub:GetLibrary("LibSchedule.7000")
local LibItemInfo = LibStub:GetLibrary("LibItemInfo.1000")
local guids, inspecting = {}, false
-- Global API
function GetInspectInfo(unit, timelimit, checkhp)
local guid = UnitGUID(unit)
if (not guid or not guids[guid]) then return end
if (checkhp and UnitHealthMax(unit) ~= guids[guid].hp) 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 = UnitGUID(unit)
if (not guid) then return end
local data = guids[guid]
if (not data) then return end
local ilevel, weaponLevel, maxLevel = LibItemInfo:GetUnitItemLevel(unit)
data.timer = time()
data.ilevel = ilevel
data.weaponLevel = weaponLevel
data.maxLevel = maxLevel
LibEvent:trigger("UNIT_REINSPECT_READY", data)
end
-- Global API @todo
function GetInspectSpec(unit)
end
-- Clear
hooksecurefunc("ClearInspectPlayer", function()
inspecting = false
end)
-- @trigger UNIT_INSPECT_STARTED
hooksecurefunc("NotifyInspect", function(unit)
local guid = 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,
hp = UnitHealthMax(unit),
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 data = guids[guid]
if (not data) then return end
LibSchedule:AddTask({
identity = guid,
timer = 0.6,
elasped = 0.8,
expired = GetTime() + 3,
data = data,
onTimeout = function(self) inspecting = false end,
onExecute = function(self)
local ilevel, weaponLevel, maxLevel = LibItemInfo:GetUnitItemLevel(self.data.unit)
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.weaponLevel = weaponLevel
self.data.maxLevel = maxLevel
self.data.spec = GetInspectSpec(self.data.unit)
self.data.hp = UnitHealthMax(self.data.unit)
LibEvent:trigger("UNIT_INSPECT_READY", self.data)
inspecting = false
return true
end,
})
end)