- ---遍历指定深度找房间
- ---输入参数
- ---roomname string 目标房间名称
- ---roomway sting 目标房间出口
- ---wayarray array 起步出口数组
- ---steps number 遍历深度
- ---输出参数
- ---1 Boolean 是否发现目标房间
- ---2 string 发现目标的完整路径
- function goallwaytofind(roomname,roomway,thisroomarray,steps)
- local room=""; local way=""; local forward=""; local fw=""; local found=false
- if thisroomarray=={} then return found,forward end
- for j in ipairs(thisroomarray) do
- exe(thisroomarray[j])
- while true do
- l,w=wait.regexp("^(\\S*)\\s*-\\s*$|^>*\\s*绿萼白了你一眼道.*|^>*\\s*店小二一下挡在楼梯前.*|^>*\\s*这里通向神的世界.*|你小心翼翼往前挪动|青海湖畔美不胜收,你不由停下脚步,欣赏起了风景。")
- if string.find(l,"%s+-%s+$") then --正常行走部分
- room=w[1]
- break
- elseif string.find(l,"绿萼白了你一眼道") or string.find(l,"店小二一下挡在楼梯前") --无法通过部分
- or string.find(l,"这里通向神的世界") then
- local roomarray={}
- for i,k in ipairs(thisroomarray) do
- if i>j then roomarray[i-j]=k end --忽略过不去的方向.
- end
- found,fw=goallwaytofind(roomname,roomway,roomarray,steps) --剩余方向继续遍历.
- forward=forward..";"..fw
- forward=formatway(forward)
- return found,forward
- elseif string.find(l,"你小心翼翼往前挪动") or string.find(l,"青海湖畔美不胜收") --需缓慢行走部分
- wait.time(3)
- end
- end --end while true do
- l,w=wait.regexp("^\\s*这里.*的出口是\\s*(.*)。$")
- if string.find(l,"的出口是") then
- way=w[1]
- forward=forward..";"..thisroomarray[j]
- end
- if isrightroom(roomname,roomway,room,way,step_count) then
- found=true
- break
- elseif steps>1 then
- if room="苗岭边缘" then way=removesamedirection(way,"southup") end
- found,fw=goallwaytofind(roomname,roomway,splitway(removesamedirection(formatway(way),reverse[thisroomarray[j]])),steps-1)
- forward=forward..";"..fw
- if found then break end
- end
-
- exe(reverse[thisroomarray[j]])
- l,w=wait.regexp("^\\s*这里.*的出口是\\s*.*。$")
- forward=forward..";"..reverse[thisroomarray[j]]
- end ---for j in ipairs(bt[steps.."-"..tostring(i)]) do
- forward=formatway(forward)
- return found,forward
- end
复制代码 最近解决推车乱入问题,顺便写了个小遍历,共享一下.请各位同好斧正.
北大侠客行MUD,中国最好的MUD |