path.tin 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  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 {当前路径} map.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 map-path map.path.list;
  34. };
  35. ///=== {
  36. // ## path.Trace [<是否可翻转>] [<是否可压缩>]
  37. // 开始为本房间录制路径。
  38. // 两个参数指定了本次即将录制的路径特点,并会在录制完成时真正运用。
  39. // 如果省略参数,则默认为可翻转、可压缩。
  40. // 在录制完成之前,你仍然可以随时用 path.SetType 来重新设置。
  41. // };
  42. #alias {path.Trace} {
  43. #local reversible {@default{%1;true}};
  44. #local compact {@default{%2;true}};
  45. #if { @path.isTracing{} } {
  46. errLog 录制路径工作正在进行中。;
  47. #return;
  48. };
  49. #local area {@map.GetArea{}};
  50. #if { "$area" == "" } {
  51. event.HandleOnce {map/GotArea} {path.Trace} {map/path} {path.Trace};
  52. #delay map.Trace.retry {map.GetArea} 1;
  53. #return;
  54. };
  55. #var map.path.current {
  56. {from} {@map.Room.CID{}}
  57. {to} {}
  58. {reversible} {$reversible}
  59. {compact} {$compact}
  60. };
  61. event.Handle {GMCP.Move} {path.Trace} {map/path} {path.response};
  62. #path create;
  63. path.message 开始录制路径。;
  64. option.Enable KeypadWalk;
  65. ui.walk.SetCmd path.ui.move;
  66. };
  67. ///=== {
  68. // ## path.SetType [<是否可翻转>] [<是否可压缩>]
  69. // 重新设置当前正在录制的路径特点。
  70. // 两个参数指定了此时正在录制的路径特点,并会在录制完成时真正运用。
  71. // 如果省略参数,则默认为前值,不予改变。
  72. // 在录制完成之前,你仍然可以随时用 path.SetType 来重新设置。
  73. // };
  74. #alias {path.SetType} {
  75. #if { "%0" == "" } {
  76. xtt.Usage %90;
  77. #return;
  78. };
  79. #if { ! @path.isTracing{} } {
  80. errLog 尚未开始录制。;
  81. #return;
  82. };
  83. #local reversible {@default{%1;$map.path.current[reversible]}};
  84. #local compact {@default{%2;$map.path.current[compact]}};
  85. #var map.path.current[reversible] {$reversible};
  86. #var map.path.current[compact] {$compact};
  87. };
  88. #alias {path.ui.move} {
  89. #local dir {%1};
  90. #local short {@dir.Short{%1}};
  91. #path insert {$short};
  92. go $dir;
  93. };
  94. #alias {path.response} {
  95. #local cmd {@ga.ThisCmd{}};
  96. #if { @isFalse{$gGMCP[Move][成功]} } {
  97. #if { "$cmd" == "go %+" } {
  98. #path delete;
  99. };
  100. #return;
  101. };
  102. #if { @dir.IsDir{$cmd} } {
  103. #local short {@dir.Short{$cmd}};
  104. #if { "$cmd" !== "$short" } {
  105. #path insert {$cmd};
  106. };
  107. };
  108. #elseif { "$cmd" != "go %*" } {
  109. warnLog 未知的移动方式,无法识别,请手动维护路径。;
  110. path.Mark {$gMapRoom[name]/$cmd};
  111. #return;
  112. };
  113. #local length {};
  114. #path get length length;
  115. path.message 路径录制中,{<139>$cmd<159>} 已添加,目前长度: $length;
  116. };
  117. ///=== {
  118. // ## path.BotStep <机器人名称> [<机器人参数> ...]
  119. // 插入一个机器人行走步骤。
  120. // 接到本指令时,PaoTin++ 会进行如下处理:
  121. // - 1: 暂停路径录制;
  122. // - 2: 在路径中插入一个机器人步骤;
  123. // - 3: 自动调用机器人行走;
  124. // - 4: 机器人行走完成后,自动恢复录制。
  125. // 按照约定,符合本规范的机器人必须发射以下事件之一:
  126. // - map/walk/continue: 代表机器人成功结束运行,通过该区域
  127. // - map/walk/failed: 代表机器人遇到了无法逾越的障碍,放弃行走
  128. // 本命令会监听以上事件并做相应处理。
  129. // };
  130. #alias {path.BotStep} {
  131. #local bot {%1};
  132. #info arguments save;
  133. #local args {$info[ARGUMENTS]};
  134. #unvar info[ARGUMENTS];
  135. #unlocal args[0];
  136. #if { "$bot" == "" } {
  137. xtt.Usage %90;
  138. #return;
  139. };
  140. #if { ! @path.isTracing{} } {
  141. errLog 路径录制尚未开始。;
  142. #return;
  143. };
  144. #if { !@existsAlias{map.$bot} } {
  145. errLog 不存在机器人 $bot,请检查是否拼写错误。;
  146. #return;
  147. };
  148. #class path.BotStep open;
  149. #alias {path.BotStep.done} {
  150. path.BotStep.end;
  151. path.message 机器人运行完成,继续录制路径。;
  152. };
  153. #line sub var #alias {path.BotStep.failed} {
  154. path.BotStep.end;
  155. path.message 机器人运行出错,姑且继续录制,如有不脱请取消录制。;
  156. };
  157. #line sub var #alias {path.BotStep.end} {
  158. #class path.BotStep kill;
  159. #path start;
  160. event.Handle {GMCP.Move} {path.Trace} {pathdir} {path.response};
  161. path.message <129>录制路径中…… <299>;
  162. };
  163. event.ClassHandleOnce {map/walk/continue} {map.$bot} {pathdir} {path.BotStep.done};
  164. event.ClassHandleOnce {map/walk/failed} {map.$bot} {pathdir} {path.BotStep.failed};
  165. #class path.BotStep close;
  166. event.UnHandle {GMCP.Move} {path.Trace} {pathdir};
  167. #local step {$bot};
  168. #local count {&args[]};
  169. #if { $count > 1 } {
  170. #local idx {};
  171. #loop 2 {$count} {idx} {
  172. #local arg {$args[$idx]};
  173. #if { "$arg" == "%*;%*" } {
  174. #cat {step} {/{$arg}};
  175. };
  176. #else {
  177. #cat {step} {/$arg};
  178. };
  179. };
  180. };
  181. #path stop;
  182. #path insert {$step} {$step};
  183. path.message 已经暂停路径录制,将会在机器人运行结束后自动继续。;
  184. map.%0;
  185. };
  186. ///=== {
  187. // ## path.Mark [<记号>]
  188. // 在录制路径的过程中,插入一个记号,方便将来手动编辑路径。
  189. // 如果省略记号,默认为当前房间名。
  190. // };
  191. #alias {path.Mark} {
  192. #local mark {@default{%1;$gMapRoom[name]}};
  193. #if { ! @path.isTracing{} } {
  194. errLog 路径录制尚未开始。;
  195. #return;
  196. };
  197. #path insert {Mark/$mark} {Mark/$mark};
  198. };
  199. #alias {map.Mark} {
  200. #local mark {%1};
  201. okLog 这里有一个记号:「$mark」。;
  202. map.BotReturn map.Mark;
  203. };
  204. ///=== {
  205. // ## path.Cancel
  206. // 取消当前正在进行的录制路径工作。
  207. // };
  208. #alias {path.Cancel} {
  209. #if { ! @path.isTracing{} } {
  210. errLog 路径录制尚未开始。;
  211. #return;
  212. };
  213. #var map.path.current {};
  214. #path destroy;
  215. event.UnHandle {GMCP.Move} {path.Trace};
  216. path.message 放弃了本次路径录制工作。;
  217. };
  218. ///=== {
  219. // ## path.Finish
  220. // 完成录制。
  221. // };
  222. #alias {path.Finish} {
  223. #local area {@map.GetArea{}};
  224. #if { "$area" == "" } {
  225. event.HandleOnce {map/GotArea} {path.Finish} {map/path} {path.Finish};
  226. #delay map.Finish.retry {map.GetArea} 1;
  227. #return;
  228. };
  229. #local here {@map.Room.CID{}};
  230. #var map.path.current[to] {$here};
  231. #path stop;
  232. event.UnHandle {GMCP.Move} {path.Trace};
  233. #local fpath {};
  234. #path save forward fpath;
  235. #local bpath {};
  236. #path save backward bpath;
  237. #if { "$map.path.current[from]" == "$map.path.current[to]" } {
  238. okLog 检测到遍历路径。;
  239. #local length {};
  240. #path get length length;
  241. #local pathName {${here}-遍历${area}-$length};
  242. #var map.path.list[$pathName] {$fpath};
  243. };
  244. #else {
  245. #if { @isTrue{$map.path.current[compact]} } {
  246. #local fpath {@path.Simplify{$fpath}};
  247. };
  248. okLog 正向路径: {#$fpath#};
  249. #local pathName {${map.path.current[from]}-${map.path.current[to]}};
  250. #var map.path.list[$pathName] {$fpath};
  251. #if { @isTrue{$map.path.current[reversible]} } {
  252. #if { @isTrue{$map.path.current[compact]} } {
  253. #local bpath {@path.Simplify{$bpath}};
  254. };
  255. okLog 反向路径: {#$bpath#};
  256. #local pathName {${map.path.current[to]}-${map.path.current[from]}};
  257. #var map.path.list[$pathName] {$bpath};
  258. };
  259. };
  260. #var map.path.current {};
  261. #path destroy;
  262. path.message 路径录制结束。你可以使用 {@mslp.Exec{path.List;path.List}} 命令查看本房间的关联路径。;
  263. path.Hint;
  264. storage.Save map-path map.path.list;
  265. };
  266. ///=== {
  267. // ## path.Hint
  268. // 如果此处有路径,则提醒玩家。
  269. // };
  270. #alias {path.Hint} {
  271. #nop 录制路径的过程中,提示以录制为主。;
  272. #if { @path.isTracing{} } {
  273. #return;
  274. };
  275. #local area {@map.GetArea{}};
  276. #if { "$area" == "" } {
  277. #local here {@xiaoyao.Locate{}};
  278. #if { "$here" == "" } {
  279. path.hint;
  280. #return;
  281. };
  282. };
  283. #local here {@map.Room.CID{}};
  284. #local path {@table.Keys{map.path.list; {${here}-%*}}};
  285. #local count {@slist.Size{$path}};
  286. #if { $count > 0 } {
  287. #local path {@fp.Transform{{$path};\@str.Replace{VALUE;{%*-%*};{&2}}}};
  288. #local path {@fp.Transform{{$path};\@mslp.Exec{{path.Walk ${here}-VALUE};<139>\@str.Replace{VALUE;{$area的};{}}<299>}} };
  289. path.hint $path;
  290. };
  291. #else {
  292. path.hint;
  293. };
  294. };
  295. ///=== {
  296. // ## path.List
  297. // 查看本房间都有哪些关联路径,类似于北侠 node 或者 walk 命令。
  298. // };
  299. #alias {path.List} {
  300. #local area {@map.GetArea{}};
  301. #if { "$area" == "" } {
  302. event.HandleOnce {map/GotArea} {path.List} {map/path} {path.List};
  303. #delay map.List.retry {map.GetArea} 1;
  304. #return;
  305. };
  306. #local here {@map.Room.CID{}};
  307. #local count {0};
  308. #local name {};
  309. #foreach {*map.path.list[]} {name} {
  310. #if { "$name" == "${here}-%*" } {
  311. #local path {$map.path.list[$name]};
  312. #local size {@slist.Size{$path}};
  313. #echo {%s(<129>$size<299>): %s} {@mslp.Exec{{path.Walk $name};<139>$name<299>}} {<169>$path<099>};
  314. #math count {$count + 1};
  315. };
  316. };
  317. #if { $count > 0 } {
  318. okLog 共列出 $count 条关联路径。;
  319. };
  320. #else {
  321. warnLog 尚未找到本房间的关联路径。;
  322. };
  323. path.message 为本房间录制更多路径请使用 {@mslp.Exec{path.Trace;path.Trace}}。;
  324. };
  325. ///=== {
  326. // #@ path.Get <路径名称>
  327. // 查询并返回路径。
  328. // };
  329. #func {path.Get} {
  330. #local name {%0};
  331. #if { "$name" == "" } {
  332. #return {};
  333. };
  334. #return {$map.path.list[$name]};
  335. };
  336. VAR {千里通步进推进器} {path.Walk.Stepper} {};
  337. ///=== {
  338. // ## path.Walk.SetStepper <步进推进器>
  339. // 设置路径行走的步进推进器。如果设置了步进推进器,则千里通将进入步进推进模式。
  340. // 你推一步,它就走一步,不推就不走。
  341. // 你可以用 path.Walk.Resume 来推动千里通继续前进,一次一步。
  342. // 注意,步进推进器仅在下一次行走任务中生效。一旦行走结束,无论成功失败,步进推进器设置将被清空。
  343. // };
  344. #alias {path.Walk.SetStepper} {
  345. #local stepper {%21};
  346. #if { "$stepper" == "" } {
  347. xtt.Usage %90;
  348. #return;
  349. };
  350. #var path.Walk.Stepper {$stepper};
  351. };
  352. ///=== {
  353. // ## path.Walk <路径名称> [<回调代码>]
  354. // 沿着指定的路径名称执行行走任务。行走完成后,执行回调代码。
  355. // 如果省略回调代码,用户仍可通过订阅 map/walk/continue 事件获得回调机会。
  356. // 注意约定的回调钩子名称为 map/path/end。
  357. // };
  358. #alias {path.Walk} {
  359. #local name {%1};
  360. #local callback {%22};
  361. #local path {$map.path.list[$name]};
  362. #if { "$name" == "" } {
  363. xtt.Usage %90;
  364. #return;
  365. };
  366. #if { "$callback" != "" } {
  367. #line sub {escapes;var} event.HandleOnce map/walk/continue {map/path/end} {map/path} {$callback};
  368. };
  369. path.WalkSteps {$path};
  370. };
  371. ///=== {
  372. // ## path.WalkSteps <路径> [<回调代码>]
  373. // 走一个自定义路径。行走完成后,执行回调代码。
  374. // };
  375. #alias {path.WalkSteps} {
  376. #local path {%1};
  377. #local callback {%22};
  378. #local len {@slist.Size{$path}};
  379. #if { $len == 0 } {
  380. xtt.Usage %90;
  381. #return;
  382. };
  383. #local path {@fp.Transform{{$path};path.step {VALUE}}};
  384. #if { $len > 1 } {
  385. env.Set brief 3;
  386. #local path {@slist.Insert{{$path};$len;path.last-step}};
  387. };
  388. #if { "$callback" != "" } {
  389. #line sub {escapes;var} event.HandleOnce map/walk/continue {map/path/end} {map/path} {$callback};
  390. };
  391. #path load {$path;path.end};
  392. sync.Wait {#path walk};
  393. };
  394. #alias {path.step} {
  395. #class path.step open;
  396. #local cmd {@dir.Long{%1}};
  397. #if { "$path.Walk.Stepper" === "" } {
  398. event.HandleOnce {map/walk/continue} {map/step} {map/path} {path.step.next};
  399. };
  400. #else {
  401. #line sub {escapes;var} event.HandleOnce {map/walk/continue} {map/step} {map/path} {$path.Walk.Stepper};
  402. };
  403. event.HandleOnce {map/walk/failed} {map/step} {map/path} {#path destroy; path.last-step; path.end};
  404. map.step.Try {} {$cmd} {};
  405. };
  406. VAR {停止走路标志} path.walk.stop {0};
  407. #alias {path.Walk.Stop} {
  408. #var path.walk.stop 1;
  409. };
  410. #alias {path.Walk.Resume} {
  411. #var path.walk.stop 0;
  412. path.step.next;
  413. };
  414. #alias {path.Walk.Reset} {
  415. #var path.walk.stop 0;
  416. #path destroy;
  417. };
  418. #alias {path.step.next} {
  419. #if { ! $path.walk.stop } {
  420. #path walk;
  421. };
  422. };
  423. #alias {path.last-step} {
  424. env.UnSet brief;
  425. #path walk;
  426. };
  427. #alias {path.end} {
  428. okLog 行走完成。;
  429. #local path {};
  430. #path get info {path};
  431. #if { $path[position] <= $path[length] } {
  432. sync.Wait {
  433. #path run;
  434. };
  435. };
  436. #var path.Walk.Stepper {};
  437. event.Emit {map/walk/continue} {map/path/end};
  438. event.HandleOnce {map/GotArea} {path/end} {map/path} {path.Hint};
  439. map.GetArea;
  440. };
  441. #func {path.isTracing} {
  442. #if { &map.path.current[] > 0 } {
  443. #return 1;
  444. };
  445. #else {
  446. #return 0;
  447. };
  448. };
  449. #alias {path.message} {
  450. #local msg {%0};
  451. #local trace {@mslp.Exec{path.Trace;<159>path.Trace<299>}};
  452. #local cancel {@mslp.Exec{path.Cancel;<119>path.Cancel<299>}};
  453. #local finish {@mslp.Exec{path.Finish;<129>path.Finish<299>}};
  454. #if { @path.isTracing{} } {
  455. infoLog <159>$msg<299> 取消录制请使用 {$cancel},完成录制请使用 {$finish}。<299>;
  456. };
  457. #else {
  458. infoLog <159>$msg<299> 要想录制新路径,请使用 {$trace}。<299>;
  459. };
  460. path.hint %0;
  461. };
  462. VAR {map/path 模块提醒内容} {path-hint} {NOTHING};
  463. #alias {path.hint} {
  464. #local hint {%0};
  465. #if { "$path-hint" == "$hint" } {
  466. #return;
  467. };
  468. #var path-hint {$hint};
  469. #local trace {【@mslp.Exec{path.Trace;<159>开始录制<299>}】};
  470. #local cancel {【@mslp.Exec{path.Cancel;<119>取消录制<299>}】};
  471. #local finish {【@mslp.Exec{path.Finish;<129>完成录制<299>}】};
  472. #if { @path.isTracing{} } {
  473. #local hint {$finish $cancel <159>$hint<299>};
  474. };
  475. #else {
  476. #local hint {$trace <159>$hint<299>};
  477. };
  478. prompt.Set {{path}{$hint}};
  479. };