| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- #nop 房间信息解析模块;
- VAR {当前房间信息} gMapRoom {};
- option.Define {ShowRoomView} {Bool} {是否显示房间风景} {false};
- option.Define {MapDebug} {Bool} {房间信息解析调试开关} {false};
- option.Define {DrawRoomMap} {Bool} {是否自行绘制房间地图} {false};
- event.Handle {option/changed} {opt/ShowRoomView/main} {map/room} {look};
- event.Handle {option/changed} {opt/MapDebug/main} {map/room} {look};
- event.Handle {option/changed} {opt/DrawRoomMap/main} {map/room} {look};
- event.Define {map/GotRoomInfo} {无参} {$MODULE} {已经获取到房间信息,并储存到 gMapRoom 全局变量。};
- event.HandleOnce {map/init} {map/room} {map} {map.Room.Watch};
- ///=== {
- // ## map.Room.Watch
- // 睁眼看世界,注册相关触发,开始捕获房间信息。
- // };
- #alias {map.Room.Watch} {
- #class map.Room.Watch open;
- errLog 待实现;
- #class map.Room.Watch close;
- };
- ///=== {
- // ## map.Room.StopWatch
- // 闭上眼睛,不再关心房间信息。
- // };
- #alias {map.Room.StopWatch} {
- #class map.Room.Watch kill;
- };
- #alias {map.Room.ShowView} {
- #if { @option.IsDisable{ShowRoomView} } {
- #line gag;
- };
- #elseif { @option.IsEnable{MapDebug} } {
- #echo {%s} {<174>房间风景<299> @Beautify{{%1}}};
- #line gag;
- };
- };
- #alias {map.Room.ShowMap} {
- #local room {@default{{%1};{$gMapRoom}}};
- #local map {$room[map]};
- #replace map {|$} {};
- #replace map {||} {;|};
- #local line {};
- #foreach {$map} {line} {
- #replace line {^|} {};
- #echo {%s} {$line};
- };
- };
- #alias {map.Room.DrawMap} {
- #local room {%1};
- #if { &room[] == 0 || &room[exitHint][] == 0 || "$gMapRoom[drawMap]" == "done" } {
- #return;
- };
- #var gMapRoom[drawMap] {done};
- #local hint {$room[exitHint]};
- #local lnw {@if{{"$hint[northwest]" != ""};{\}}};
- #local lne {@if{{"$hint[northeast]" != ""};{/}}};
- #local lse {@if{{"$hint[southeast]" != ""};{\}}};
- #local lsw {@if{{"$hint[southwest]" != ""};{/}}};
- #local lnu {@if{{"$hint[northup]" != ""};{↑}}};
- #local ln {@if{{"$hint[north]" != ""};{|}}};
- #local lnd {@if{{"$hint[northdown]" != ""};{↓}}};
- #local leu {@if{{"$hint[eastup]" != ""};{ →}}};
- #local le {@if{{"$hint[east]" != ""};{ --}}};
- #local led {@if{{"$hint[eastdown]" != ""};{ ←}}};
- #local lsu {@if{{"$hint[southup]" != ""};{↓}}};
- #local ls {@if{{"$hint[south]" != ""};{|}}};
- #local lsd {@if{{"$hint[southdown]" != ""};{↑}}};
- #local lwu {@if{{"$hint[westup]" != ""};{← }}};
- #local lw {@if{{"$hint[west]" != ""};{--}}};
- #local lwd {@if{{"$hint[westdown]" != ""};{→ }}};
- #local name {@str.AlignCenter{$gMapRoom[name];32}};
- #local nName {};
- #format nName {%+10s %+10s %+10s}
- {@str.AlignCenter{$hint[northup];10}}
- {@str.AlignCenter{$hint[north];10}}
- {@str.AlignCenter{$hint[northdown];10}};
- #local nName {@str.Left{{$nName};32}};
- #local lnn {};
- #format lnn {%+10s %+10s %+10s}
- {@str.AlignCenter{$lnu;10}}
- {@str.AlignCenter{$ln;10}}
- {@str.AlignCenter{$lnd;10}};
- #local sName {};
- #format sName {%+10s %+10s %+10s}
- {@str.AlignCenter{$hint[southup];10}}
- {@str.AlignCenter{$hint[south];10}}
- {@str.AlignCenter{$hint[southdown];10}};
- #local sName {@str.Left{{$sName};32}};
- #local lss {};
- #format lss {%+10s %+10s %+10s}
- {@str.AlignCenter{$lsu;10}}
- {@str.AlignCenter{$ls;10}}
- {@str.AlignCenter{$lsd;10}};
- #local nw {@str.AlignRight{$hint[northwest];12}};
- #local sw {@str.AlignRight{$hint[southwest];12}};
- #local ne {@str.AlignLeft{$hint[northeast];12}};
- #local se {@str.AlignLeft{$hint[southeast];12}};
- #local space {@str.Space{12}};
- #local space6 {@str.Space{6}};
- #local space4 {@str.Space{4}};
- #local nameN {};
- #local nameS {};
- #format nameN {%-10s %+10s %+10s}
- {@str.AlignLeft{$lnw;10}} {} {@str.AlignRight{$lne;10}};
- #format nameS {%-10s %+10s %+10s}
- {@str.AlignLeft{$lsw;10}} {} {@str.AlignRight{$lse;10}};
- #local up {@str.AlignRight{$hint[up];10}};
- #local down {@str.AlignRight{$hint[down];10}};
- #local enter {@str.AlignLeft{$hint[enter];10}};
- #local out {@str.AlignLeft{$hint[out];10}};
- #local wu {$hint[westup]};
- #local ww {$hint[west]};
- #local wd {$hint[westdown]};
- #local eu {$hint[eastup]};
- #local ee {$hint[east]};
- #local ed {$hint[eastdown]};
- #local format1 {%-10s %+12s %+4s %-32s %-4s %-12s %+10s};
- #local format2 {%-10s %+4s %+12s %-32s %-12s %-4s %+10s};
- #echo {$format1} {<G01>} {} {} {} {} {} {};
- #echo {$format1} {<G01>} {<G03>$space} {} {<G01>$nName} {<G03>} {$space<G01>} {};
- #echo {$format1} {<G01>$up} {<G03>$space} {} {<G01>$space} {<G03>} {$space<G01>} {$enter};
- #echo {$format2} {<G01>} {<G03>$space4} {$nw} {<G01>$lnn} {<G03>$ne} {$space4<G01>} {};
- #echo {$format1} {<G01>} {<G01>$wu} {$lwu} {<G03>$nameN} {<G01>$leu} {$eu<G01>} {};
- #echo {$format1} {<G01>} {<G01>$ww} {$lw} {<G03>$name} {<G01>$le} {$ee<G01>} {};
- #echo {$format1} {<G01>} {<G01>$wd} {$lwd} {<G03>$nameS} {<G01>$led} {$ed<G01>} {};
- #echo {$format2} {<G01>} {<G03>$space4} {$sw} {<G01>$lss} {<G03>$se} {$space4<G01>} {};
- #echo {$format1} {<G01>$down} {<G03>$space} {} {<G01>$space} {<G03>} {$space<G01>} {$out};
- #echo {$format1} {<G01>} {<G03>$space} {} {<G01>$sName} {<G03>} {$space<G01>} {};
- #echo {$format1} {<G01>} {} {} {} {} {} {};
- };
- #func {map.Room.CID} {
- #local area {@default{$gMapRoom[area][RESOLVED];未知地区}};
- #local name {@default{$gMapRoom[name];未知房间}};
- #return {$area的$name};
- };
- ///=== {
- // #@ map.Room.GetObjByName <名称> [<头衔>]
- // 根据名称提取房间中的物品信息。
- // 由于有时候无法正确区分 NPC、玩家和物品,因此本函数也可以用来查询 NPC 或玩家,
- // 此时如果同时提供了头衔,则也会判断头衔是否匹配。
- // 当然,你也可以只通过头衔来查询,只要保持名称留空即可。
- // };
- #func {map.Room.GetObjByName} {
- #local name {@default{%1;%*}};
- #local title {%2};
- #local idx {};
- #foreach {*gMapRoom[objs][]} {idx} {
- #if { "$gMapRoom[objs][$idx][name]" == "$name"
- && ("$title" == "" || @sset.Contains{{$gMapRoom[objs][$idx][title]};$title})
- } {
- #return {$gMapRoom[objs][$idx]};
- };
- };
- #return {};
- };
- ///=== {
- // #@ map.Room.GetObjByID <ID>
- // 根据 ID 提取房间中的物品信息。
- // 由于有时候无法正确区分 NPC、玩家和物品,因此本函数也可以用来查询 NPC 或玩家。
- // };
- #func {map.Room.GetObjByID} {
- #local id {%1};
- #local idx {};
- #foreach {*gMapRoom[objs][]} {idx} {
- #if { "$gMapRoom[objs][$idx][id]" == "$id" } {
- #return {$gMapRoom[objs][$idx]};
- };
- };
- #return {};
- };
- ///=== {
- // #@ map.Room.GetNpcByName <姓名> [<头衔>]
- // 根据姓名提取房间中的 NPC 信息。如果同时提供了头衔,则也会判断头衔是否匹配。
- // 当然,你也可以只通过头衔来查询,只要保持姓名留空即可。
- // NOTE: 注意并非所有的 NPC 都可以被成功识别,因此有时候你不得不用 map.Room.GetObjByName。
- // };
- #func {map.Room.GetNpcByName} {
- #local name {@default{%1;%*}};
- #local title {%2};
- #local idx {};
- #foreach {*gMapRoom[npcs][]} {idx} {
- #if { "$gMapRoom[npcs][$idx][name]" == "$name"
- && ("$title" == "" || @sset.Contains{{$gMapRoom[npcs][$idx][title]};$title})
- } {
- #return {$gMapRoom[npcs][$idx]};
- };
- };
- #return {};
- };
- ///=== {
- // #@ map.Room.GetNpcByID <ID>
- // 根据 ID 提取房间中的 NPC 信息。
- // NOTE: 注意并非所有的 NPC 都可以被成功识别,因此有时候你不得不用 map.Room.GetObjByID。
- // };
- #func {map.Room.GetNpcByID} {
- #local id {%1};
- #local idx {};
- #foreach {*gMapRoom[npcs][]} {idx} {
- #if { "$gMapRoom[npcs][$idx][id]" == "$id" } {
- #return {$gMapRoom[npcs][$idx]};
- };
- };
- #return {};
- };
- ///=== {
- // #@ map.Room.GetPlayerByName <姓名> [<头衔>]
- // 根据姓名提取房间中的玩家信息。如果同时提供了头衔,则也会判断头衔是否匹配。
- // 当然,你也可以只通过头衔来查询,只要保持姓名留空即可。
- // NOTE: 注意并非所有的玩家都可以被成功识别,因此有时候你不得不用 map.Room.GetObjByName。
- // };
- #func {map.Room.GetPlayerByName} {
- #local name {@default{%1;%*}};
- #local title {%2};
- #local idx {};
- #foreach {*gMapRoom[players][]} {idx} {
- #if { "$gMapRoom[players][$idx][name]" == "$name"
- && ("$title" == "" || @sset.Contains{{$gMapRoom[players][$idx][title]};$title})
- } {
- #return {$gMapRoom[players][$idx]};
- };
- };
- #return {};
- };
- ///=== {
- // #@ map.Room.GetPlayerByID <ID>
- // 根据 ID 提取房间中的玩家信息。
- // NOTE: 注意并非所有的玩家都可以被成功识别,因此有时候你不得不用 map.Room.GetObjByID。
- // };
- #func {map.Room.GetPlayerByID} {
- #local id {%1};
- #local idx {};
- #foreach {*gMapRoom[players][]} {idx} {
- #if { "$gMapRoom[players][$idx][id]" == "$id" } {
- #return {$gMapRoom[players][$idx]};
- };
- };
- #return {};
- };
- #func {map.Here} {
- #return {0};
- };
|