-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbrSkinning.lua
More file actions
111 lines (95 loc) · 3.62 KB
/
brSkinning.lua
File metadata and controls
111 lines (95 loc) · 3.62 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
---@type _,br,_
local _,br,_ = ...
---@type br.Logging
local Log = br.Logging
---@class br.Skinning
---@field Active boolean Whether the skinning module is active
---@field Skin fun(self: br.Skinning) Performs skinning actions
local Skinning = {}
Skinning.BlackList = {}
Skinning.Active = false
function Skinning:SkinTarget(target)
if br.DoSkinning and
not br.ActivePlayer:IsCasting() and
not br.ActivePlayer:IsChanneling() and
not br.ActivePlayer:IsMoving() and
not br.ActivePlayer:IsMounted() and
br.ActivePlayer:IsAlive() and
not br.ActivePlayer.InCombat then
if target and br.ObjectExists(target.guid) and not self.BlackList[target.guid] then
self.Active = true
--TODO Set timer to blacklist unreachable skinnables
Log:Log("Moving to skinnable: " .. target.name .. " at distance " .. tostring(target:Distance()))
if target:Distance() > 8 then
while target:Distance() > 8 do
br.ClickToMove(br.ObjectLocation(target.guid))
br.SendMovementHeartbeat()
end
end
Log:Log("Interacting with skinnable: " .. target.name)
br.ObjectInteract(target.guid)
self.BlackList[target.guid] = GetTime()
self.Active = false
else
if target and not br.ObjectExists(target.guid) then
--remove from OM
br.ObjectManager.Units[target.guid] = nil
end
end
--Cleanun Blacklist entries older than 60 seconds
for guid,timeAdded in pairs(self.BlackList) do
if GetTime() - timeAdded > 60 then
self.BlackList[guid] = nil
end
end
end
end
function Skinning:Skin()
if br.DoSkinning and
br.ObjectManager:SkinnableCount() > 0 and
not br.ActivePlayer:IsCasting() and
not br.ActivePlayer:IsChanneling() and
not br.ActivePlayer:IsMoving() and
not br.ActivePlayer:IsMounted() and
br.ActivePlayer:IsAlive() and
not br.ActivePlayer.InCombat then
local target = br.ObjectManager:ClosestSkinnable()
if target and br.ObjectExists(target.guid) and not self.BlackList[target.guid] then
self.Active = true
--TODO Set timer to blacklist unreachable skinnables
Log:Log("Moving to skinnable: " .. target.name .. " at distance " .. tostring(target:Distance()))
if target:Distance() > 8 then
while target:Distance() > 8 do
br.ClickToMove(br.ObjectLocation(target.guid))
br.SendMovementHeartbeat()
end
end
Log:Log("Interacting with skinnable: " .. target.name)
br.ObjectInteract(target.guid)
self.BlackList[target.guid] = GetTime()
self.Active = false
else
if target and not br.ObjectExists(target.guid) then
--remove from OM
br.ObjectManager.Units[target.guid] = nil
end
end
--Cleanun Blacklist entries older than 60 seconds
for guid,timeAdded in pairs(self.BlackList) do
if GetTime() - timeAdded > 60 then
self.BlackList[guid] = nil
end
end
end
--Retry in 0.5 second
-- C_Timer.After(0.5, function()
-- Skinning:Skin()
-- end)
end
--Kick off skinning loop 2 seconds after load
-- C_Timer.NewTimer(2, function()
-- Log:Log("Starting Skinning loop")
-- Skinning:Skin()
-- end)
br.Skinning = Skinning
Log:Log("BR Skinning module loaded")