-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.lua
More file actions
173 lines (163 loc) · 7.03 KB
/
common.lua
File metadata and controls
173 lines (163 loc) · 7.03 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
local run_hide = {
["hp"] = function() trigger.enable("hide_hp")
trigger.add(nil, "trigger.disable('hide_hp')", nil, {Enable=true, OneShot=true}, 10, "^·饮水·\\s+\\d+\\.\\d+%\\s+·经验· \\S+ \\(\\d+\\.\\d+%\\)$")
end,
["score"] = function() trigger.enable("hide_score")
trigger.add(nil, "trigger.disable('hide_score')", nil, {Enable=true, OneShot=true}, 10, "^┗[━]+┛$")
end,
["i"] = function() trigger.enable("hide_i")
trigger.add("disable_hide_i", "trigger.disable('hide_i')", nil, {Enable=false, OneShot=true}, 10, "^> $")
trigger.add(nil, "trigger.enable('disable_hide_i')", nil, {Enable=true, OneShot=true}, 10, "^你身上携带物品的别称如下\\(右方\\):$|^目前你身上没有任何东西。$")
end,
["skills"] = function() trigger.enable("hide_skills")
trigger.add("disable_hide_skills", "trigger.disable('hide_skills')", nil, {Enable=false, OneShot=true}, 10, "^> $")
trigger.add(nil, "trigger.enable('disable_hide_skills')", nil, {Enable=true, OneShot=true}, 10, "^【你的技能表】:总共\\S+项技能$")
end,
["enable"] = function() trigger.enable("hide_enable")
trigger.add("disable_hide_enable", "trigger.disable('hide_enable')", nil, {Enable=false, OneShot=true}, 10, "^> $")
trigger.add(nil, "trigger.enable('disable_hide_enable')", nil, {Enable=true, OneShot=true}, 10, "^以下是你目前使用中的特殊技能。$")
end,
["prepare"] = function() trigger.enable("hide_prepare")
trigger.add("disable_hide_prepare", "trigger.disable('hide_prepare')", nil, {Enable=false, OneShot=true}, 10, "^> $")
trigger.add(nil, "trigger.enable('disable_hide_prepare')", nil, {Enable=true, OneShot=true}, 10, "^以下是你目前组合中的特殊技能:$|^你现在没有(?:组合|准备)任何特殊(?:|拳脚)技能。$")
end,
["set"] = function() trigger.enable("hide_set")
trigger.add("disable_hide_set", "trigger.disable('hide_set')", nil, {Enable=false, OneShot=true}, 10, "^> $")
trigger.add(nil, "trigger.enable('disable_hide_set')", nil, {Enable=true, OneShot=true}, 10, "^你目前设定的环境变量有:$")
end
}
function run(cmd)
if not string.is_empty(cmd) then
local splited = string.split(cmd, ";")
global.flood = global.flood + #splited
for _,v in ipairs(splited) do
if run_hide[v] ~= nil then
run_hide[v]()
end
end
return send_cmd(cmd)
end
end
threads = threads or {}
waits = waits or {}
function wait(seconds)
local name = "wait_"..unique_id()
threads[name] = coroutine.running()
if threads[name] == nil then
show("必须使用协程", "orange")
return false
end
waits[name] = true
timer.add(name, seconds, "wait_resume('"..name.."')", nil, {Enable=true, OneShot=true})
return coroutine.yield()
end
function wait_resume(name)
local thread = (threads or {})[name]
if thread == nil then
show("协程不存在", "orange")
return false
end
threads[name] = nil
waits[name] = nil
local success,msg = coroutine.resume(thread)
if success == false then
show(msg, "red")
show(debug.traceback(thread), "gray")
return false
end
return true
end
function wait_line(action, timeout, options, order, ...)
local name = "wait_line_"..unique_id()
threads[name] = { coroutine.running() }
if threads[name][1] == nil then
show("必须使用协程", "orange")
return false
end
local pattern
options = options or {}
options.Enable = false
options.OneShot = true
if select("#", ...) > 1 then
pattern = {...}
threads[name][2] = {}
trigger.add(name.."_"..tostring(#pattern), "wait_line_trigger('"..name.."', "..tostring(#pattern)..", true)", name, options, order, set.last(pattern))
for i = #pattern-1, 1, -1 do
trigger.add(name.."_"..tostring(i), "wait_line_trigger('"..name.."', "..tostring(i)..", false)", name, {Enable=false, OneShot=true}, order, pattern[i])
end
trigger.enable(name.."_1")
else
pattern = select(1, ...)
options.Enable = true
trigger.add(name, "wait_line_trigger('"..name.."')", name, options, order, pattern)
end
timeout = timeout or 0
waits[name] = true
if timeout > 0 then
timer.add(name, timeout, "wait_line_timer('"..name.."')", nil, {Enable=true, OneShot=true})
end
run(action)
return coroutine.yield() or false
end
function wait_line_trigger(name, n, islast)
if n == nil then
timer.delete(name)
threads[name][2] = get_matches()
wait_line_resume(name)
else
if islast == true then
timer.delete(name)
threads[name][2][n] = get_matches()
wait_line_resume(name)
else
threads[name][2][n] = get_matches()
trigger.enable(name.."_"..tostring(n+1))
end
end
end
function wait_line_timer(name)
trigger.delete_group(name)
threads[name][2] = nil
wait_line_resume(name)
end
function wait_line_resume(name)
trigger.delete_group(name)
local thread = ((threads or {})[name] or {})[1]
if thread == nil then
show("Coroutine lost", "orange")
return false
end
if coroutine.status(thread) == "suspended" then
local args = threads[name][2]
threads[name] = nil
waits[name] = nil
local success,msg = coroutine.resume(thread, args)
if success == false then
show(msg, "red")
show(debug.traceback(thread), "gray")
end
else
timer.add(nil, 0, "wait_line_resume('"..name.."')", nil, {Enable=true, OneShot=true})
end
end
function message(level, file, row, output, head)
if global.debug[level] <= global.debug.level then
local lua = set.last(string.split(file, "/"))
head = string.rep(" ", head or 0)
show(string.format("\n%-24s%-s%-s", lua.." - "..tostring(row)..":", head, output))
if global.debug.level > 1 then
if time.epoch() - (global.debug.endless[output] or 0) < 1 then
global.debug.endless.count = (global.debug.endless.count or 0) + 1
else
global.debug.endless.count = 0
end
if global.debug.endless.count > 1000 then
print("发现死锁")
wait(300)
automation_reset()
end
global.debug.endless[output] = time.epoch()
end
end
end
show(string.format("%-.40s%-1s", "加载 "..string.match(debug.getinfo(1).source, "(SJ/.*lua)$").." ..............................", " 成功"), "chartreuse")