#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} {} {} {} {} {} {} {}; #echo {$format1} {} {$space} {} {$nName} {} {$space} {}; #echo {$format1} {$up} {$space} {} {$space} {} {$space} {$enter}; #echo {$format2} {} {$space4} {$nw} {$lnn} {$ne} {$space4} {}; #echo {$format1} {} {$wu} {$lwu} {$nameN} {$leu} {$eu} {}; #echo {$format1} {} {$ww} {$lw} {$name} {$le} {$ee} {}; #echo {$format1} {} {$wd} {$lwd} {$nameS} {$led} {$ed} {}; #echo {$format2} {} {$space4} {$sw} {$lss} {$se} {$space4} {}; #echo {$format1} {$down} {$space} {} {$space} {} {$space} {$out}; #echo {$format1} {} {$space} {} {$sName} {} {$space} {}; #echo {$format1} {} {} {} {} {} {} {}; }; #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 提取房间中的物品信息。 // 由于有时候无法正确区分 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 提取房间中的 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 提取房间中的玩家信息。 // 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}; };