room.tin 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. #nop 房间信息解析模块;
  2. VAR {当前房间信息} gMapRoom {};
  3. option.Define {ShowRoomView} {Bool} {是否显示房间风景} {false};
  4. option.Define {MapDebug} {Bool} {房间信息解析调试开关} {false};
  5. option.Define {DrawRoomMap} {Bool} {是否自行绘制房间地图} {false};
  6. event.Handle {option/changed} {opt/ShowRoomView/main} {map/room} {look};
  7. event.Handle {option/changed} {opt/MapDebug/main} {map/room} {look};
  8. event.Handle {option/changed} {opt/DrawRoomMap/main} {map/room} {look};
  9. event.Define {map/GotRoomInfo} {无参} {$MODULE} {已经获取到房间信息,并储存到 gMapRoom 全局变量。};
  10. event.HandleOnce {map/init} {map/room} {map} {map.Room.Watch};
  11. ///=== {
  12. // ## map.Room.Watch
  13. // 睁眼看世界,注册相关触发,开始捕获房间信息。
  14. // };
  15. #alias {map.Room.Watch} {
  16. #class map.Room.Watch open;
  17. errLog 待实现;
  18. #class map.Room.Watch close;
  19. };
  20. ///=== {
  21. // ## map.Room.StopWatch
  22. // 闭上眼睛,不再关心房间信息。
  23. // };
  24. #alias {map.Room.StopWatch} {
  25. #class map.Room.Watch kill;
  26. };
  27. #alias {map.Room.ShowView} {
  28. #if { @option.IsDisable{ShowRoomView} } {
  29. #line gag;
  30. };
  31. #elseif { @option.IsEnable{MapDebug} } {
  32. #echo {%s} {<174>房间风景<299> @Beautify{{%1}}};
  33. #line gag;
  34. };
  35. };
  36. #alias {map.Room.ShowMap} {
  37. #local room {@default{{%1};{$gMapRoom}}};
  38. #local map {$room[map]};
  39. #replace map {|$} {};
  40. #replace map {||} {;|};
  41. #local line {};
  42. #foreach {$map} {line} {
  43. #replace line {^|} {};
  44. #echo {%s} {$line};
  45. };
  46. };
  47. #alias {map.Room.DrawMap} {
  48. #local room {%1};
  49. #if { &room[] == 0 || &room[exitHint][] == 0 || "$gMapRoom[drawMap]" == "done" } {
  50. #return;
  51. };
  52. #var gMapRoom[drawMap] {done};
  53. #local hint {$room[exitHint]};
  54. #local lnw {@if{{"$hint[northwest]" != ""};{\}}};
  55. #local lne {@if{{"$hint[northeast]" != ""};{/}}};
  56. #local lse {@if{{"$hint[southeast]" != ""};{\}}};
  57. #local lsw {@if{{"$hint[southwest]" != ""};{/}}};
  58. #local lnu {@if{{"$hint[northup]" != ""};{↑}}};
  59. #local ln {@if{{"$hint[north]" != ""};{|}}};
  60. #local lnd {@if{{"$hint[northdown]" != ""};{↓}}};
  61. #local leu {@if{{"$hint[eastup]" != ""};{ →}}};
  62. #local le {@if{{"$hint[east]" != ""};{ --}}};
  63. #local led {@if{{"$hint[eastdown]" != ""};{ ←}}};
  64. #local lsu {@if{{"$hint[southup]" != ""};{↓}}};
  65. #local ls {@if{{"$hint[south]" != ""};{|}}};
  66. #local lsd {@if{{"$hint[southdown]" != ""};{↑}}};
  67. #local lwu {@if{{"$hint[westup]" != ""};{← }}};
  68. #local lw {@if{{"$hint[west]" != ""};{--}}};
  69. #local lwd {@if{{"$hint[westdown]" != ""};{→ }}};
  70. #local name {@str.AlignCenter{$gMapRoom[name];32}};
  71. #local nName {};
  72. #format nName {%+10s %+10s %+10s}
  73. {@str.AlignCenter{$hint[northup];10}}
  74. {@str.AlignCenter{$hint[north];10}}
  75. {@str.AlignCenter{$hint[northdown];10}};
  76. #local nName {@str.Left{{$nName};32}};
  77. #local lnn {};
  78. #format lnn {%+10s %+10s %+10s}
  79. {@str.AlignCenter{$lnu;10}}
  80. {@str.AlignCenter{$ln;10}}
  81. {@str.AlignCenter{$lnd;10}};
  82. #local sName {};
  83. #format sName {%+10s %+10s %+10s}
  84. {@str.AlignCenter{$hint[southup];10}}
  85. {@str.AlignCenter{$hint[south];10}}
  86. {@str.AlignCenter{$hint[southdown];10}};
  87. #local sName {@str.Left{{$sName};32}};
  88. #local lss {};
  89. #format lss {%+10s %+10s %+10s}
  90. {@str.AlignCenter{$lsu;10}}
  91. {@str.AlignCenter{$ls;10}}
  92. {@str.AlignCenter{$lsd;10}};
  93. #local nw {@str.AlignRight{$hint[northwest];12}};
  94. #local sw {@str.AlignRight{$hint[southwest];12}};
  95. #local ne {@str.AlignLeft{$hint[northeast];12}};
  96. #local se {@str.AlignLeft{$hint[southeast];12}};
  97. #local space {@str.Space{12}};
  98. #local space6 {@str.Space{6}};
  99. #local space4 {@str.Space{4}};
  100. #local nameN {};
  101. #local nameS {};
  102. #format nameN {%-10s %+10s %+10s}
  103. {@str.AlignLeft{$lnw;10}} {} {@str.AlignRight{$lne;10}};
  104. #format nameS {%-10s %+10s %+10s}
  105. {@str.AlignLeft{$lsw;10}} {} {@str.AlignRight{$lse;10}};
  106. #local up {@str.AlignRight{$hint[up];10}};
  107. #local down {@str.AlignRight{$hint[down];10}};
  108. #local enter {@str.AlignLeft{$hint[enter];10}};
  109. #local out {@str.AlignLeft{$hint[out];10}};
  110. #local wu {$hint[westup]};
  111. #local ww {$hint[west]};
  112. #local wd {$hint[westdown]};
  113. #local eu {$hint[eastup]};
  114. #local ee {$hint[east]};
  115. #local ed {$hint[eastdown]};
  116. #local format1 {%-10s %+12s %+4s %-32s %-4s %-12s %+10s};
  117. #local format2 {%-10s %+4s %+12s %-32s %-12s %-4s %+10s};
  118. #echo {$format1} {<G01>} {} {} {} {} {} {};
  119. #echo {$format1} {<G01>} {<G03>$space} {} {<G01>$nName} {<G03>} {$space<G01>} {};
  120. #echo {$format1} {<G01>$up} {<G03>$space} {} {<G01>$space} {<G03>} {$space<G01>} {$enter};
  121. #echo {$format2} {<G01>} {<G03>$space4} {$nw} {<G01>$lnn} {<G03>$ne} {$space4<G01>} {};
  122. #echo {$format1} {<G01>} {<G01>$wu} {$lwu} {<G03>$nameN} {<G01>$leu} {$eu<G01>} {};
  123. #echo {$format1} {<G01>} {<G01>$ww} {$lw} {<G03>$name} {<G01>$le} {$ee<G01>} {};
  124. #echo {$format1} {<G01>} {<G01>$wd} {$lwd} {<G03>$nameS} {<G01>$led} {$ed<G01>} {};
  125. #echo {$format2} {<G01>} {<G03>$space4} {$sw} {<G01>$lss} {<G03>$se} {$space4<G01>} {};
  126. #echo {$format1} {<G01>$down} {<G03>$space} {} {<G01>$space} {<G03>} {$space<G01>} {$out};
  127. #echo {$format1} {<G01>} {<G03>$space} {} {<G01>$sName} {<G03>} {$space<G01>} {};
  128. #echo {$format1} {<G01>} {} {} {} {} {} {};
  129. };
  130. #func {map.Room.CID} {
  131. #local area {@default{$gMapRoom[area][RESOLVED];未知地区}};
  132. #local name {@default{$gMapRoom[name];未知房间}};
  133. #return {$area的$name};
  134. };
  135. ///=== {
  136. // #@ map.Room.GetObjByName <名称> [<头衔>]
  137. // 根据名称提取房间中的物品信息。
  138. // 由于有时候无法正确区分 NPC、玩家和物品,因此本函数也可以用来查询 NPC 或玩家,
  139. // 此时如果同时提供了头衔,则也会判断头衔是否匹配。
  140. // 当然,你也可以只通过头衔来查询,只要保持名称留空即可。
  141. // };
  142. #func {map.Room.GetObjByName} {
  143. #local name {@default{%1;%*}};
  144. #local title {%2};
  145. #local idx {};
  146. #foreach {*gMapRoom[objs][]} {idx} {
  147. #if { "$gMapRoom[objs][$idx][name]" == "$name"
  148. && ("$title" == "" || @sset.Contains{{$gMapRoom[objs][$idx][title]};$title})
  149. } {
  150. #return {$gMapRoom[objs][$idx]};
  151. };
  152. };
  153. #return {};
  154. };
  155. ///=== {
  156. // #@ map.Room.GetObjByID <ID>
  157. // 根据 ID 提取房间中的物品信息。
  158. // 由于有时候无法正确区分 NPC、玩家和物品,因此本函数也可以用来查询 NPC 或玩家。
  159. // };
  160. #func {map.Room.GetObjByID} {
  161. #local id {%1};
  162. #local idx {};
  163. #foreach {*gMapRoom[objs][]} {idx} {
  164. #if { "$gMapRoom[objs][$idx][id]" == "$id" } {
  165. #return {$gMapRoom[objs][$idx]};
  166. };
  167. };
  168. #return {};
  169. };
  170. ///=== {
  171. // #@ map.Room.GetNpcByName <姓名> [<头衔>]
  172. // 根据姓名提取房间中的 NPC 信息。如果同时提供了头衔,则也会判断头衔是否匹配。
  173. // 当然,你也可以只通过头衔来查询,只要保持姓名留空即可。
  174. // NOTE: 注意并非所有的 NPC 都可以被成功识别,因此有时候你不得不用 map.Room.GetObjByName。
  175. // };
  176. #func {map.Room.GetNpcByName} {
  177. #local name {@default{%1;%*}};
  178. #local title {%2};
  179. #local idx {};
  180. #foreach {*gMapRoom[npcs][]} {idx} {
  181. #if { "$gMapRoom[npcs][$idx][name]" == "$name"
  182. && ("$title" == "" || @sset.Contains{{$gMapRoom[npcs][$idx][title]};$title})
  183. } {
  184. #return {$gMapRoom[npcs][$idx]};
  185. };
  186. };
  187. #return {};
  188. };
  189. ///=== {
  190. // #@ map.Room.GetNpcByID <ID>
  191. // 根据 ID 提取房间中的 NPC 信息。
  192. // NOTE: 注意并非所有的 NPC 都可以被成功识别,因此有时候你不得不用 map.Room.GetObjByID。
  193. // };
  194. #func {map.Room.GetNpcByID} {
  195. #local id {%1};
  196. #local idx {};
  197. #foreach {*gMapRoom[npcs][]} {idx} {
  198. #if { "$gMapRoom[npcs][$idx][id]" == "$id" } {
  199. #return {$gMapRoom[npcs][$idx]};
  200. };
  201. };
  202. #return {};
  203. };
  204. ///=== {
  205. // #@ map.Room.GetPlayerByName <姓名> [<头衔>]
  206. // 根据姓名提取房间中的玩家信息。如果同时提供了头衔,则也会判断头衔是否匹配。
  207. // 当然,你也可以只通过头衔来查询,只要保持姓名留空即可。
  208. // NOTE: 注意并非所有的玩家都可以被成功识别,因此有时候你不得不用 map.Room.GetObjByName。
  209. // };
  210. #func {map.Room.GetPlayerByName} {
  211. #local name {@default{%1;%*}};
  212. #local title {%2};
  213. #local idx {};
  214. #foreach {*gMapRoom[players][]} {idx} {
  215. #if { "$gMapRoom[players][$idx][name]" == "$name"
  216. && ("$title" == "" || @sset.Contains{{$gMapRoom[players][$idx][title]};$title})
  217. } {
  218. #return {$gMapRoom[players][$idx]};
  219. };
  220. };
  221. #return {};
  222. };
  223. ///=== {
  224. // #@ map.Room.GetPlayerByID <ID>
  225. // 根据 ID 提取房间中的玩家信息。
  226. // NOTE: 注意并非所有的玩家都可以被成功识别,因此有时候你不得不用 map.Room.GetObjByID。
  227. // };
  228. #func {map.Room.GetPlayerByID} {
  229. #local id {%1};
  230. #local idx {};
  231. #foreach {*gMapRoom[players][]} {idx} {
  232. #if { "$gMapRoom[players][$idx][id]" == "$id" } {
  233. #return {$gMapRoom[players][$idx]};
  234. };
  235. };
  236. #return {};
  237. };
  238. #func {map.Here} {
  239. #return {0};
  240. };