-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtetherbot.lua
More file actions
164 lines (138 loc) · 3.34 KB
/
tetherbot.lua
File metadata and controls
164 lines (138 loc) · 3.34 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
local mq = require('mq')
local co = require('co')
local str= require('str')
local mychar = require('mychar')
require('actions.s_navtocamp')
local tetherbot = {}
--
-- Globals
--
local actionqueue = {}
local State = {}
local Config = {}
--
-- Functions
--
local function log(msg)
print('(tetherbot) ' .. msg)
end
local function have_camp()
return State.TetherStatus == 'C'
end
local function paused()
return State.TetherStatus == 'P'
end
local function fleeing()
return State.TetherStatus == 'R'
end
local function nav_to_camp()
actionqueue.AddUnique(
ScpNavToCamp(
30,
false
)
)
-- mq.cmd('/nav loc ' .. State.TetherDetail .. ' log=off')
end
-- TODO: Action this
local function nav_to_id()
local id = tonumber(State.TetherDetail) or 0
mq.TLO.Spawn(id).DoTarget()
co.delay(2000, function() return mq.TLO.Target.ID() == id end)
mq.cmd('/nav target log=off')
end
local function location(mqloc)
local parts = str.Split(mqloc, ',')
local y = tonumber(str.Trim(parts[1]))
local x = tonumber(str.Trim(parts[2]))
local z = tonumber(str.Trim(parts[3]))
return x,y,z
end
local function callback_dbtether(...)
local args = { ... }
if #args > 0 then
if args[1]:lower() == 'return' then
if have_camp() then
nav_to_camp()
end
elseif args[1]:lower() == 'none' or args[1]:lower() == 'off' then
State.TetherClear()
log('Clearing tether')
elseif args[1]:lower() == 'camp' then
State.TetherCamp()
log('Camp set')
else
local id = mq.TLO.Spawn(args[1]).ID()
if id == nil or id == 0 then
State.TetherClear()
log('Could not find spawn: ' .. args[1])
else
State.TetherFollow(id)
log('Following id ' .. id)
end
end
else
log('tetherbot is up')
end
end
--
-- To Quiet EasyFind, there is a log setting in config/EasyFind.yaml
--
local function do_tether()
if State.TetherStatus ~= 'N' then
if have_camp() then
if mq.TLO.AdvPath.State() == 1 then
mq.cmd('/afollow off')
end
if Config.Tether.ModeIsActive() and not mq.TLO.Navigation.Active() and not mychar.InCombat() and State.MyCharHasNotMovedFor() > Config.Tether.ReturnTimer() then
local distance = mq.TLO.Math.Distance(State.TetherDetail)()
if distance > Config.Tether.CampMaxDistance() then
nav_to_camp()
end
end
elseif not paused() then
local id = tonumber(State.TetherDetail)
if id ~= nil and Config.Tether.ModeIsActive() then
if not mq.TLO.Navigation.Active() then
local distance = mq.TLO.Spawn(id).Distance3D()
if distance ~= nil and distance > Config.Tether.FollowMaxDistance() then
nav_to_id()
end
if mq.TLO.AdvPath.State() ~= 1 then
mq.cmd('/afollow spawn ' .. id)
end
end
end
else
if mq.TLO.AdvPath.State() == 1 then
mq.cmd('/afollow off')
end
end
elseif mq.TLO.AdvPath.State() == 1 then
mq.cmd('/afollow off')
else
if mq.TLO.Me.Name() == 'Pystoffe' then
-- print(mq.TLO.AdvPath.State())
end
end
end
--
-- Init
--
function tetherbot.Init(state, cfg, aq)
State = state
Config = cfg
actionqueue = aq
mq.bind('/dbtether', callback_dbtether)
end
---
--- Main Loop
---
function tetherbot.Run()
log('Up and running')
while true do
do_tether()
co.yield()
end
end
return tetherbot