-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
306 lines (275 loc) · 9.21 KB
/
main.lua
File metadata and controls
306 lines (275 loc) · 9.21 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
global = global or { flood = 0, uid = {}, buffer = {}, regex = {} }
global.debug = { level = 0, none = 0, info = 1, trace = 2 , endless = {}}
automation = automation or {}
var = var or {}
function get_work_path()
return HOME
end
function get_script_path()
return SCRIPT
end
package.path = package.path..";"..
get_script_path().."base/?.lua;"..
get_script_path().."frame/?.lua;"..
get_script_path().."game/?.lua;"..
get_script_path().."gps/?.lua;"..
get_script_path().."control/?.lua;"..
get_script_path().."jobs/?.lua"
-- if loadstring == nil then
-- function loadstring(msg)
-- return load(msg)
-- end
-- end
require "config"
require "client"
require "common"
require "gps"
require "info"
require "action"
require "admin"
require "statistics"
if io.exists(get_work_path().."log/ui.tmp") then
ui = table.load(get_work_path().."log/ui.tmp")
os.remove(get_work_path().."log/ui.tmp")
end
ui = ui or {}
require "ui"
function UIReset()
if ui.setBoard ~= nil then
ui.setBorder()
ui.setLayout()
ui.setBoard()
ui.setMapper()
ui.setMessage()
ui.setPanel()
end
end
registerAnonymousEventHandler("sysWindowResizeEvent", UIReset)
registerAnonymousEventHandler("sysDisconnectionEvent", reconnect)
timer.add("decline", 1, "global.flood = math.max(0, (global.flood or 0) - 10)", nil, {Enable=true})
trigger.add("login", "login()", "信息采集", {Enable=true, StopEval=true}, 6, "^您目前的权限是:.*$|^重新连线完毕。$")
trigger.add("overlogin", "run(\"y\")", nil, {Enable=true}, 6, "^人物目前正在游戏当中,您可以取而代之,确定请打 Y ,否则请打 N 。确定吗\\(Y/N\\)?$")
if io.exists(get_work_path().."char.cfg") then
loadfile(get_work_path().."char.cfg")()
end
if io.exists(get_work_path().."log/global.tmp") then
global.buffer = table.load(get_work_path().."log/global.tmp")
os.remove(get_work_path().."log/global.tmp")
end
if io.exists(get_work_path().."log/automation.tmp") then
automation = table.load(get_work_path().."log/automation.tmp")
os.remove(get_work_path().."log/automation.tmp")
end
automation.timer = automation.timer or {}
automation.items = automation.items or {}
automation.killer = automation.killer or {}
local buff = {
--"invalid_fu_xuelian"
}
local debuff = {
}
local jobcd = {
-- "ftb_job_cd",
-- "songshan_job_cd",
}
state.buff = automation.buff or state.buff
state.debuff = automation.debuff or state.debuff
automation.buff = nil
automation.debuff = nil
for _,v in ipairs(buff) do
if automation.timer[v] == nil then
state.buff[v] = nil
else
local seconds = math.max(0.001, automation.timer[v].remain - (time.epoch() - automation.epoch) / 1000 )
timer.add(automation.timer[v], seconds)
automation.timer[v] = nil
end
end
for _,v in ipairs(debuff) do
if automation.timer[v] == nil then
state.debuff[v] = nil
else
local seconds = math.max(0.001, automation.timer[v].remain - (time.epoch() - automation.epoch) / 1000 )
timer.add(automation.timer[v], seconds)
automation.timer[v] = nil
end
end
automation.skill = nil
for k,v in pairs(automation.items) do
items[k] = v
end
if automation.carryon ~= nil then
carryon = automation.carryon
automation.carryon = nil
end
if automation.skills ~= nil then
skills = automation.skills
automation.skills = nil
end
global.debug.level = automation.debug or global.debug.level
automation.statistics = automation.statistics or {}
automation.statistics.date = automation.statistics.date or time.date("%Y%m%d%H")
automation.statistics.death = automation.statistics.death or {}
automation.statistics.idle = automation.statistics.idle or {}
automation.statistics.reset = automation.statistics.reset or {}
automation.statistics.connect = automation.statistics.connect or {}
automation.statistics.processing = automation.statistics.processing or {}
collectgarbage("collect")
function init()
message("trace", debug.getinfo(1).source, debug.getinfo(1).currentline, "函数[ init ]")
trigger.add("init_hide_ga", "", nil, {Enable=true, Gag=true, StopEval=true}, 40, "^> $|^\\s*$|^ 平均每天在线:|^你至少需要\\S+点的气来打坐!$")
run("wear all;dazuo 1")
if jia_max() < 0 then
trigger.delete("init_hide_ga")
show("初始化失败", "red")
return -1
end
if run_score() < 0 or run_hp() < 0 then
trigger.delete("init_hide_ga")
show("初始化失败", "red")
return -1
end
if run_skills() < 0 or run_enable() < 0 or run_prepare() < 0 then
trigger.delete("init_hide_ga")
show("初始化失败", "red")
return -1
end
if run_set() < 0 then
trigger.delete("init_hide_ga")
show("初始化失败", "red")
return -1
end
if run_i() < 0 then
trigger.delete("init_hide_ga")
show("初始化失败", "red")
return -1
end
if jia_min() < 0 then
trigger.delete("init_hide_ga")
show("初始化失败", "red")
return -1
end
if run_hp() < 0 then
return -1
end
trigger.delete("init_hide_ga")
--if locate() >= 0 then
if wait_line("set 初始化完成", 30, nil, 10, "^设定环境变量:初始化完成 = \"YES\"$", "^> $") ~= false then
show("初始化成功", "green")
return 0
end
--end
trigger.delete("init_hide_ga")
show("初始化失败", "red")
return -1
end
function login()
if automation.thread ~= nil then
return
end
coroutine.wrap(
function ()
automation.thread = coroutine.running()
init()
automation.thread = nil
end
)()
end
function load_jobs()
if automation.config_jobs ~= nil then
for k,v in pairs(automation.config_jobs) do
if type(config.jobs[k]) == "table" then
for i,j in pairs(v) do
if i ~= "enable" then
config.jobs[k][i] = j
end
end
end
end
automation.config_jobs = nil
end
for _,v in ipairs(config.jobs) do
if config.jobs[v].enable == true then
loadstring("require '"..config.jobs[v].name.."'")()
if config.jobs[v].efunc ~= nil then
config.jobs[v].efunc()
end
else
if config.jobs[v].dfunc ~= nil then
config.jobs[v].dfunc()
end
end
end
end
function reset(fresh)
automation.config = nil
if fresh == true then
automation = {}
elseif automation.thread ~= nil then
automation.thread = nil
automation.jid = (var or {}).jid
automation.config_jobs = config.jobs
automation.carryon = carryon
automation.skills = skills
end
automation.buff = state.buff
automation.debuff = state.debuff
automation.timer = {}
for _,v in ipairs(buff) do
automation.timer[v] = timer.get(v)
end
for _,v in ipairs(debuff) do
automation.timer[v] = timer.get(v)
end
for _,v in ipairs(jobcd) do
automation.timer[v] = timer.get(v)
end
automation.debug = global.debug.level
automation.epoch = time.epoch()
table.save(get_work_path().."log/automation.tmp", automation)
table.save(get_work_path().."log/global.tmp", (global.buffer or { "" }))
table.save(get_work_path().."log/ui.tmp", { reset = true })
reset_env()
end
if automation.reconnect == nil then
if #global.buffer == 0 or get_lines(-1)[1] == "请输入您的账号\\(ID\\):" or set.has(get_lines(-3), "「书剑·风云世界」共有") then
show(string.format("%-.40s%-1s", "加载 "..string.match(debug.getinfo(1).source, "(SJ/.*lua)$").." ..............................", " 成功"), "chartreuse")
else
local login = true
for _,v in ipairs(get_lines(-3)) do
if string.match(v, "^〖书剑〗:您本次总共在线") then
login = false
break
end
end
show(string.format("%-.40s%-1s", "加载 "..string.match(debug.getinfo(1).source, "(SJ/.*lua)$").." ..............................", " 成功"), "chartreuse")
if login == true then
coroutine.wrap(
function ()
automation.thread = coroutine.running()
init()
automation.thread = nil
end
)()
end
end
else
show(string.format("%-.40s%-1s", "加载 "..string.match(debug.getinfo(1).source, "(SJ/.*lua)$").." ..............................", " 成功"), "chartreuse")
require "flow"
coroutine.wrap(
function ()
automation.thread = coroutine.running()
if #global.buffer == 0 or get_lines(-1)[1] == "请输入您的账号\\(ID\\):" or set.has(get_lines(-3), "「书剑·风云世界」共有") then
automation_reset_connect()
else
loadstring(automation.reconnect)()
end
trigger.delete_group("automation_reset")
if init() < 0 then
return automation_reset()
end
load_jobs()
start()
end
)()
end