|
发表于 2015-3-23 09:00:04
|
显示全部楼层
这是我写的
function lookroom(where)
if where=="" then
where=vil;
end
local roomnow={};
local roomall={};
roomnow.name="";
roomnow.area="";
roomnow.descriptions={};
roomnow.exits={};
roomnow.location={};
local exithere="";
Send("club ");
if where then
Send("look " .. where);
else
Send("look");
end
Send("@@");
local i=0;
l,w = wait.regexp("你晃动着手中的木棒,到处寻找目标。");
while true do
l,w = wait.regexp(".*");
if string.find(l,"你的一双眼睛瞪得比铜铃还大!") then
table.insert(roomall,"END");
break;
end
table.insert(roomall,l);
end
local descriptions_start_line,descriptions_end_line=9999,9999; --初始设定描述行的起始和终点行数
if string.find(roomall[1],"【你现在正处于(.+)】") then
_,_,roomnow.area=string.find(roomall[1],"【你现在正处于(.+)】"); --第一行是地区
else
print("警告!没找到本房间的地区");
return;
end
i=1;
while true do --从第二行开始搜索,直到找到房间名,并将之前确定为位置
i=i+1;
if string.find(roomall[i],"^>*%s*(.-)%s%-%s*$") then
_,_,roomnow.name=string.find(roomall[i],"^>*%s*(.-)%s%-%s*$");
descriptions_start_line=i+1;
break;
end
if roomall[i]=="END" then
print("警告!没找到本房间的名称");
return;
end
end
for i=2,descriptions_start_line-2 do --从第二行到房间名,都是位置
table.insert(roomnow.location,cutstr(roomall[i]));
end
i=descriptions_start_line; --从房间名的下一行开始,一直找到有空格的地方,都是描述
while true do
table.insert(roomnow.descriptions,cutstr(roomall[i]));
if string.find(roomall[i+1],"^>*%s%s%s+.*$") or string.find(roomall[i+1],"^>* .*$") then
descriptions_end_line=i;
--print(string.byte(roomall[i+1],1,10));
--print(roomall[i+1]);
break;
else
i=i+1;
if roomall[i]=="END" then
print("警告!没找到本房间描述的末尾,错误");
return;
end
end
end
i=descriptions_end_line+1;
while true do
if string.find(roomall[i],"^>*%s*这里.-的出口是(.*)$") then
if string.sub(roomall[i],-2)=="。" then
_,_,exithere=string.find(roomall[i],"^>*%s*这里.-的出口是(.-)。$");
else
_,_,exithere=string.find(roomall[i],"^>*%s*这里.-的出口是(.*)$");
exithere=exithere .. cutstr(string.sub(roomall[i+1],1,-3));
end
break;
else
i=i+1;
if roomall[i]=="END" then
print("警告!没找到本房间的出口")
return;
end
end
end
exithere=string.gsub(exithere,"和","、")
while true do
if splitstr(exithere,"、",1) then
local exit;
exit,exithere=splitstr(exithere,"、",1);
roomnow.exits[exit]={};
if exitcmds[exit] then
roomnow.exits[exit].cmd=exitcmds[exit];
else
print("方向" .. exit .. "的命令不存在");
end
else
break;
end
end
table.sort(roomnow);
return 1,roomnow;
end |
|