path.tin 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. #nop vim: set filetype=tt:;
  2. /*
  3. 本文件属于 PaoTin++ 的一部分
  4. ===========
  5. PaoTin++ © 2020~2023 的所有版权均由担子炮(dzp <danzipao@gmail.com>) 享有并保留一切法律权利
  6. 你可以在遵照 GPLv3 协议的基础之上使用、修改及重新分发本程序。
  7. ===========
  8. */
  9. #pathdir {n} {s} {1};
  10. #pathdir {e} {w} {2};
  11. #pathdir {s} {n} {4};
  12. #pathdir {w} {e} {8};
  13. #pathdir {u} {d} {16};
  14. #pathdir {d} {u} {32};
  15. #pathdir {ne} {sw} {3};
  16. #pathdir {nw} {se} {9};
  17. #pathdir {se} {nw} {6};
  18. #pathdir {sw} {ne} {12};
  19. #pathdir {nu} {sd} {17};
  20. #pathdir {eu} {wd} {18};
  21. #pathdir {su} {nd} {20};
  22. #pathdir {wu} {ed} {24};
  23. #pathdir {nd} {su} {33};
  24. #pathdir {ed} {wu} {34};
  25. #pathdir {sd} {nu} {36};
  26. #pathdir {wd} {eu} {40};
  27. #pathdir {out} {enter} {19};
  28. #pathdir {enter} {out} {44};
  29. VAR {当前路径} path-current {};
  30. event.HandleOnce {map/init} {map/path} {map} {map.path.Init};
  31. #alias {map.path.Init} {
  32. event.Handle {map/GotRoomInfo} {path.Hint} {map/path} {path.Hint};
  33. storage.Load path path-list;
  34. };
  35. ///=== {
  36. // ## path.Trace
  37. // 开始为本房间录制路径。
  38. // };
  39. #alias {path.Trace} {
  40. #local area {@map.GetArea{}};
  41. #if { "$area" == "" } {
  42. event.HandleOnce {map/GotArea} {path.Trace} {map/path} {path.Trace};
  43. #delay map.Trace.retry {map.GetArea} 1;
  44. #return;
  45. };
  46. #if { @path.isTracing{} } {
  47. errLog 录制路径工作正在进行中。;
  48. #return;
  49. };
  50. #var path-current {
  51. {from} {@map.Room.CID{}}
  52. {to} {}
  53. };
  54. event.Handle {GMCP.Move} {path.Trace} {map/path} {path.response};
  55. #path create;
  56. path.message 开始录制路径。;
  57. option.Enable KeypadWalk;
  58. ui.walk.SetCmd path.ui.move;
  59. };
  60. #alias {path.ui.move} {
  61. #local dir {%1};
  62. #local short {@dir.Short{%1}};
  63. #path insert {$short};
  64. go $dir;
  65. };
  66. #alias {path.response} {
  67. #local cmd {@ga.ThisCmd{}};
  68. #if { @isFalse{$gGMCP[Move][成功]} } {
  69. #if { "$cmd" == "go %+" } {
  70. #path delete;
  71. };
  72. #return;
  73. };
  74. #if { @dir.IsDir{$cmd} } {
  75. #local short {@dir.Short{$cmd}};
  76. #if { "$cmd" !== "$short" } {
  77. #path insert {$cmd};
  78. };
  79. };
  80. #elseif { "$cmd" != "go %*" } {
  81. warnLog 未知的移动方式,无法识别,请手动维护路径。;
  82. path.Mark {$gMapRoom[name]/$cmd};
  83. #return;
  84. };
  85. #local length {};
  86. #path get length length;
  87. path.message 路径录制中,{<139>$cmd<159>} 已添加,目前长度: $length;
  88. };
  89. ///=== {
  90. // ## path.BotStep <机器人名称> [<机器人参数> ...]
  91. // 插入一个机器人行走步骤。
  92. // 接到本指令时,PaoTin++ 会进行如下处理:
  93. // - 1: 暂停路径录制;
  94. // - 2: 在路径中插入一个机器人步骤;
  95. // - 3: 自动调用机器人行走;
  96. // - 4: 机器人行走完成后,自动恢复录制。
  97. // 按照约定,符合本规范的机器人必须发射以下事件之一:
  98. // - map/walk/continue: 代表机器人成功结束运行,通过该区域
  99. // - map/walk/failed: 代表机器人遇到了无法逾越的障碍,放弃行走
  100. // 本命令会监听以上事件并做相应处理。
  101. // };
  102. #alias {path.BotStep} {
  103. #local bot {%0};
  104. #local name {%1};
  105. #if { ! @path.isTracing{} } {
  106. errLog 路径录制尚未开始。;
  107. #return;
  108. };
  109. #if { !@existsAlias{map.$name} } {
  110. errLog 不存在机器人 $name,请检查是否拼写错误。;
  111. #return;
  112. };
  113. #class path.BotStep open;
  114. #alias {path.BotStep.done} {
  115. path.BotStep.end;
  116. path.message 机器人运行完成,继续录制路径。;
  117. };
  118. #line sub var #alias {path.BotStep.failed} {
  119. path.BotStep.end;
  120. path.message 机器人运行出错,姑且继续录制,如有不脱请取消录制。;
  121. };
  122. #line sub var #alias {path.BotStep.end} {
  123. #class path.BotStep kill;
  124. #path start;
  125. event.Handle {GMCP.Move} {path.Trace} {pathdir} {path.response};
  126. path.message <129>录制路径中…… <299>;
  127. };
  128. event.ClassHandleOnce {map/walk/continue} {map.$bot} {pathdir} {path.BotStep.done};
  129. event.ClassHandleOnce {map/walk/failed} {map.$bot} {pathdir} {path.BotStep.failed};
  130. #class path.BotStep close;
  131. event.UnHandle {GMCP.Move} {path.Trace} {pathdir};
  132. #path stop;
  133. #path insert {$bot} {$bot};
  134. path.message 已经暂停路径录制,将会在机器人运行结束后自动继续。;
  135. map.$bot;
  136. };
  137. ///=== {
  138. // ## path.Mark [<记号>]
  139. // 在录制路径的过程中,插入一个记号,方便将来手动编辑路径。
  140. // 如果省略记号,默认为当前房间名。
  141. // };
  142. #alias {path.Mark} {
  143. #local mark {@default{%1;$gMapRoom[name]}};
  144. #if { ! @path.isTracing{} } {
  145. errLog 路径录制尚未开始。;
  146. #return;
  147. };
  148. #path insert {Mark/$mark} {Mark/$mark};
  149. };
  150. #alias {map.Mark} {
  151. #local mark {%1};
  152. okLog 这里有一个记号:「$mark」。;
  153. map.BotReturn map.Mark;
  154. };
  155. ///=== {
  156. // ## path.Cancel
  157. // 取消当前正在进行的录制路径工作。
  158. // };
  159. #alias {path.Cancel} {
  160. #if { ! @path.isTracing{} } {
  161. errLog 路径录制尚未开始。;
  162. #return;
  163. };
  164. #var path-current {};
  165. #path destroy;
  166. event.UnHandle {GMCP.Move} {path.Trace};
  167. path.message 放弃了本次路径录制工作。;
  168. };
  169. ///=== {
  170. // ## path.Finish
  171. // 完成录制。
  172. // };
  173. #alias {path.Finish} {
  174. #local area {@map.GetArea{}};
  175. #if { "$area" == "" } {
  176. event.HandleOnce {map/GotArea} {path.Finish} {map/path} {path.Finish};
  177. #delay map.Finish.retry {map.GetArea} 1;
  178. #return;
  179. };
  180. #local here {@map.Room.CID{}};
  181. #var path-current[to] {$here};
  182. #path stop;
  183. event.UnHandle {GMCP.Move} {path.Trace};
  184. #local fpath {};
  185. #path save forward fpath;
  186. #local bpath {};
  187. #path save backward bpath;
  188. #if { "$path-current[from]" == "$path-current[to]" } {
  189. okLog 检测到遍历路径。;
  190. #local length {};
  191. #path get length length;
  192. #local pathName {${here}-遍历${area}-$length};
  193. #var path-list[$pathName] {$fpath};
  194. };
  195. #else {
  196. #local fpath {@path.Simplify{$fpath}};
  197. okLog 正向路径: {#$fpath#};
  198. #local pathName {${path-current[from]}-${path-current[to]}};
  199. #var path-list[$pathName] {$fpath};
  200. #local bpath {@path.Simplify{$bpath}};
  201. okLog 反向路径: {#$bpath#};
  202. #local pathName {${path-current[to]}-${path-current[from]}};
  203. #var path-list[$pathName] {$bpath};
  204. };
  205. #var path-current {};
  206. #path destroy;
  207. path.message 路径录制结束。你可以使用 {@mslp.Exec{path.List;path.List}} 命令查看本房间的关联路径。;
  208. path.Hint;
  209. storage.Save path path-list;
  210. };
  211. ///=== {
  212. // ## path.Hint
  213. // 如果此处有路径,则提醒玩家。
  214. // };
  215. #alias {path.Hint} {
  216. #nop 录制路径的过程中,提示以录制为主。;
  217. #if { @path.isTracing{} } {
  218. #return;
  219. };
  220. #local area {@map.GetArea{}};
  221. #if { "$area" == "" } {
  222. #local here {@xiaoyao.Locate{}};
  223. #if { "$here" == "" } {
  224. path.hint;
  225. #return;
  226. };
  227. };
  228. #local here {@map.Room.CID{}};
  229. #local path {@table.Keys{path-list; {${here}-%*}}};
  230. #local count {@slist.Size{$path}};
  231. #if { $count > 0 } {
  232. #local path {@fp.Transform{{$path};\@str.Replace{VALUE;{%*-%*};{&2}}}};
  233. #local path {@fp.Transform{{$path};\@mslp.Exec{{path.Walk ${here}-VALUE};<139>\@str.Replace{VALUE;{$area的};{}}<299>}} };
  234. path.hint $path;
  235. };
  236. #else {
  237. path.hint;
  238. };
  239. };
  240. ///=== {
  241. // ## path.List
  242. // 查看本房间都有哪些关联路径,类似于北侠 node 或者 walk 命令。
  243. // };
  244. #alias {path.List} {
  245. #local area {@map.GetArea{}};
  246. #if { "$area" == "" } {
  247. event.HandleOnce {map/GotArea} {path.List} {map/path} {path.List};
  248. #delay map.List.retry {map.GetArea} 1;
  249. #return;
  250. };
  251. #local here {@map.Room.CID{}};
  252. #local count {0};
  253. #local name {};
  254. #foreach {*path-list[]} {name} {
  255. #if { "$name" == "${here}-%*" } {
  256. #local path {$path-list[$name]};
  257. #local size {@slist.Size{$path}};
  258. #echo {%s(<129>$size<299>): %s} {@mslp.Exec{{path.Walk $name};<139>$name<299>}} {<169>$path<099>};
  259. #math count {$count + 1};
  260. };
  261. };
  262. #if { $count > 0 } {
  263. okLog 共列出 $count 条关联路径。;
  264. };
  265. #else {
  266. warnLog 尚未找到本房间的关联路径。;
  267. };
  268. path.message 为本房间录制更多路径请使用 {@mslp.Exec{path.Trace;path.Trace}}。;
  269. };
  270. ///=== {
  271. // #@ path.Get <路径名称>
  272. // 查询并返回路径。
  273. // };
  274. #func {path.Get} {
  275. #local name {%0};
  276. #if { "$name" == "" } {
  277. #return {};
  278. };
  279. #return {$path-list[$name]};
  280. };
  281. ///=== {
  282. // ## path.Walk <路径名称> [<回调代码>]
  283. // 沿着指定的路径名称执行行走任务。行走完成后,执行回调代码。
  284. // };
  285. #alias {path.Walk} {
  286. #local name {%1};
  287. #local callback {%2};
  288. #local path {$path-list[$name]};
  289. path.WalkSteps {$path} {$callback};
  290. };
  291. ///=== {
  292. // ## path.WalkSteps <路径> [<回调代码>]
  293. // 走一个自定义路径。行走完成后,执行回调代码。
  294. // };
  295. #alias {path.WalkSteps} {
  296. #local path {%1};
  297. #local callback {%2};
  298. #local len {@slist.Size{$path}};
  299. #local path {@fp.Transform{{$path};path.step {VALUE}}};
  300. #if { $len > 1 } {
  301. env.Set brief 3;
  302. #local path {@slist.Insert{{$path};$len;path.last-step}};
  303. };
  304. #if { "$callback" == "" } {
  305. #path load {$path;path.end};
  306. };
  307. #else {
  308. #path load {$path;path.end;$callback};
  309. };
  310. sync.Wait {#path walk};
  311. };
  312. #alias {path.step} {
  313. #class path.step open;
  314. #local cmd {@dir.Long{%1}};
  315. event.HandleOnce {map/walk/continue} {map/step} {map/path} {path.step.next};
  316. event.HandleOnce {map/walk/failed} {map/step} {map/path} {#path destroy; path.last-step};
  317. map.step.Try {} {$cmd} {};
  318. };
  319. VAR {停止走路标志} path.walk.stop {0};
  320. #alias {path.Walk.Stop} {
  321. #var path.walk.stop 1;
  322. };
  323. #alias {path.Walk.Resume} {
  324. #var path.walk.stop 0;
  325. };
  326. #alias {path.Walk.Reset} {
  327. #var path.walk.stop 0;
  328. #path destroy;
  329. };
  330. #alias {path.step.next} {
  331. #if { ! $path.walk.stop } {
  332. #path walk;
  333. };
  334. };
  335. #alias {path.last-step} {
  336. env.UnSet brief;
  337. #path walk;
  338. };
  339. #alias {path.end} {
  340. okLog 行走完成。;
  341. #local path {};
  342. #path get info {path};
  343. #if { $path[position] <= $path[length] } {
  344. sync.Wait {
  345. #path run;
  346. };
  347. };
  348. event.HandleOnce {map/GotArea} {path/end} {map/path} {path.Hint};
  349. map.GetArea;
  350. };
  351. #func {path.isTracing} {
  352. #if { &path-current[] > 0 } {
  353. #return 1;
  354. };
  355. #else {
  356. #return 0;
  357. };
  358. };
  359. #alias {path.message} {
  360. #local msg {%0};
  361. #local trace {@mslp.Exec{path.Trace;<159>path.Trace<299>}};
  362. #local cancel {@mslp.Exec{path.Cancel;<119>path.Cancel<299>}};
  363. #local finish {@mslp.Exec{path.Finish;<129>path.Finish<299>}};
  364. #if { @path.isTracing{} } {
  365. infoLog <159>$msg<299> 取消录制请使用 {$cancel},完成录制请使用 {$finish}。<299>;
  366. };
  367. #else {
  368. infoLog <159>$msg<299> 要想录制新路径,请使用 {$trace}。<299>;
  369. };
  370. path.hint %0;
  371. };
  372. VAR {map/path 模块提醒内容} {path-hint} {NOTHING};
  373. #alias {path.hint} {
  374. #local hint {%0};
  375. #if { "$path-hint" == "$hint" } {
  376. #return;
  377. };
  378. #var path-hint {$hint};
  379. #local trace {【@mslp.Exec{path.Trace;<159>开始录制<299>}】};
  380. #local cancel {【@mslp.Exec{path.Cancel;<119>取消录制<299>}】};
  381. #local finish {【@mslp.Exec{path.Finish;<129>完成录制<299>}】};
  382. #if { @path.isTracing{} } {
  383. #local hint {$finish $cancel <159>$hint<299>};
  384. };
  385. #else {
  386. #local hint {$trace <159>$hint<299>};
  387. };
  388. prompt.Set {{path}{$hint}};
  389. };