-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDistanceScanner.lua
122 lines (110 loc) · 4.27 KB
/
DistanceScanner.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
HealersMate.DistanceScannerFrame = CreateFrame("Frame", "HMDistanceScannerFrame", UIParent)
local util = HMUtil
local compost = AceLibrary("Compost-2.0")
local TRACKING_MIN_DIST = 20
local TRACKING_MAX_DIST = 60
local SIGHT_MAX_DIST = 80
local almostAllUnits = util.CloneTable(util.AllUnits) -- Everything except the player
table.remove(almostAllUnits, util.IndexOf(almostAllUnits, "player"))
if HMUnitProxy then
HMUnitProxy.RegisterUpdateListener(function()
almostAllUnits = util.CloneTable(util.AllUnits) -- Everything except the player
table.remove(almostAllUnits, util.IndexOf(almostAllUnits, "player"))
end)
end
local distanceTrackedUnits = util.CloneTable(almostAllUnits) -- Initially scan all units
local sightTrackedUnits = util.CloneTable(almostAllUnits)
local preciseDistance = util.CanClientGetPreciseDistance()
local sightTrackingEnabled = util.CanClientSightCheck()
local nextTrackingUpdate = GetTime() + 0.5
local nextUpdate = GetTime() + 0.6
if not preciseDistance and not sightTrackingEnabled then
nextUpdate = nextUpdate + 99999999 -- Effectively disable updates
end
local TRACKING_UPDATE_INTERVAL = 1.25
local _G = getfenv(0)
if HMUtil.IsSuperWowPresent() then
setmetatable(HMUnitProxy, {__index = getfenv(1)})
setfenv(1, HMUnitProxy)
end
function HealersMate.RunTrackingScan()
local UnitFrames = HealersMate.UnitFrames
local time = GetTime()
if time > nextTrackingUpdate then
nextTrackingUpdate = time + TRACKING_UPDATE_INTERVAL
compost:Erase(distanceTrackedUnits)
local prevSightTrackedUnits = sightTrackedUnits
sightTrackedUnits = compost:GetTable()
if HMGuidRoster then
for guid, cache in pairs(HMUnit.GetAllUnits()) do
HealersMate.EvaluateTracking(guid)
end
else
for _, unit in ipairs(almostAllUnits) do
HealersMate.EvaluateTracking(unit)
end
end
for _, unit in ipairs(prevSightTrackedUnits) do
for ui in UnitFrames(unit) do
ui:UpdateSight()
end
end
compost:Reclaim(prevSightTrackedUnits)
--HealersMate.hmprint("Tracking dist "..table.getn(distanceTrackedUnits))
--HealersMate.hmprint("Tracking sight "..table.getn(sightTrackedUnits))
end
if time > nextUpdate then
nextUpdate = time + 0.1
for _, unit in ipairs(distanceTrackedUnits) do
local cache = HMUnit.Get(unit)
if cache and cache:UpdateDistance() then
for ui in UnitFrames(unit) do
ui:UpdateRange()
end
end
end
for _, unit in ipairs(sightTrackedUnits) do
local cache = HMUnit.Get(unit)
if cache and cache:UpdateSight() then
for ui in UnitFrames(unit) do
ui:UpdateSight()
end
end
end
end
end
function HealersMate.EvaluateTracking(unit, update)
local UnitFrames = HealersMate.UnitFrames
local cache = HMUnit.Get(unit)
local distanceChanged = cache:UpdateDistance()
local sightChanged = cache:UpdateSight()
local new = cache:CheckNew()
local dist = cache:GetDistance()
if distanceChanged or sightChanged or new then
for ui in UnitFrames(unit) do
if distanceChanged or new then
ui:UpdateRange()
end
if sightChanged or new then
ui:UpdateSight()
end
end
end
local isTarget = UnitIsUnit(unit, "target")
if HMGuidRoster then
unit = HMGuidRoster.ResolveUnitGuid(unit)
end
if isTarget or (dist < TRACKING_MAX_DIST and dist > TRACKING_MIN_DIST) then -- Only closely track units that are close to the range threshold
if not update or not util.ArrayContains(distanceTrackedUnits, unit) then
table.insert(distanceTrackedUnits, unit)
end
end
if sightTrackingEnabled and (isTarget or (dist > 0 and dist < SIGHT_MAX_DIST)) then
if not update or not util.ArrayContains(sightTrackedUnits, unit) then
table.insert(sightTrackedUnits, unit)
end
end
end
function HealersMate.StartDistanceScanner()
HealersMate.DistanceScannerFrame:SetScript("OnUpdate", HealersMate.RunTrackingScan)
end