room.tin 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. #func {map.Room.GetObjByName} {
  136. #local name {%1};
  137. #local title {@default{%2;%*}};
  138. #local idx {};
  139. #foreach {*gMapRoom[objs][]} {idx} {
  140. #if { "$gMapRoom[objs][$idx][title]" == "$title" && "$gMapRoom[objs][$idx][name]" == "$name" } {
  141. #return {$gMapRoom[objs][$idx]};
  142. };
  143. };
  144. #return {};
  145. };
  146. #func {map.Room.GetObjByID} {
  147. #local id {%1};
  148. #local idx {};
  149. #foreach {*gMapRoom[objs][]} {idx} {
  150. #if { "$gMapRoom[objs][$idx][id]" == "$id" } {
  151. #return {$gMapRoom[objs][$idx]};
  152. };
  153. };
  154. #return {};
  155. };
  156. #func {map.Room.GetNpcByName} {
  157. #local name {%1};
  158. #local title {%2};
  159. #local idx {};
  160. #foreach {*gMapRoom[npcs][]} {idx} {
  161. #if { "$gMapRoom[npcs][$idx][title]" == "$title" && "$gMapRoom[npcs][$idx][name]" == "$name" } {
  162. #return {$gMapRoom[npcs][$idx]};
  163. };
  164. };
  165. #return {};
  166. };
  167. #func {map.Room.GetNpcByID} {
  168. #local id {%1};
  169. #local idx {};
  170. #foreach {*gMapRoom[npcs][]} {idx} {
  171. #if { "$gMapRoom[npcs][$idx][id]" == "$id" } {
  172. #return {$gMapRoom[npcs][$idx]};
  173. };
  174. };
  175. #return {};
  176. };
  177. #func {map.Here} {
  178. #return {0};
  179. };