|
楼主 |
发表于 2009-5-5 03:16:11
|
显示全部楼层
鉴于很小,直接发出来,供参考
require "module.room";
CurrentRoom = {}
CurrentRoom.callback = nil -- 回调函数,要求接受 room数组 为参数
CurrentRoom.hasInit = false
function CurrentRoom.GetCurrentRoom (callback)
if callback and type (callback) ~= "function" then
Note ("CurrentRoom.GetCurrentRoom () param callback is not a func")
return
end
if not hasInit then
hasInit = true
CurrentRoom.Init ()
else
EnableGroup ("current_room", true)
end
if not t_rooms or t_rooms.maxid == 0 then
load_rooms ()
end
CurrentRoom.callback = callback -- 初始化
CurrentRoom.room = {}
CurrentRoom.room.name = nil
CurrentRoom.room.desp = nil
CurrentRoom.room.entry = nil
CurrentRoom.room.adj_info = nil
CurrentRoom.temp = nil -- 临时room,辅助获取邻接房间信息
Send ("l")
Send ("say current room try pos 1")
end
-- 增加Trigger
function CurrentRoom.AddTrigger (name, match, action, sent_to, group)
DeleteTrigger(name)
AddTriggerEx (name, match, action, 1 + 32 + 16384, -1, 0, "", "", sent_to, 50)
if group and group ~= "" then
SetTriggerOption (name, "group", group)
end
end
function CurrentRoom.Init ()
CurrentRoom.AddTrigger ("current_entry_line", "^ 这里.{4}的出口是 (.*)[。]*$", "CurrentRoom.GetRoomInfo (\"%1\")", 12, "current_room")
CurrentRoom.AddTrigger ("current_try_pos", "^[> ]*你说道:「current room try pos (.*)」$", "CurrentRoom.TryPos ('%1')", 12, "current_room")
CurrentRoom.AddTrigger ("current_adj", "^[> ]*你说道:「current room adj (.*)」$", "CurrentRoom.Adj ('%1')", 12, "current_room")
end
function CurrentRoom.GetRoomInfo (entryStr)
local name, desp, entry = getRoomInfo (entryStr)
CurrentRoom.temp = {name=name, desp=desp, entry=entry}
end
function CurrentRoom.TryPos (flag)
if flag == "1" then
CurrentRoom.room.name = CurrentRoom.temp.name
CurrentRoom.room.desp = CurrentRoom.temp.desp
CurrentRoom.room.entry = CurrentRoom.temp.entry
CurrentRoom.temp = nil
end
local temp = CurrentRoom.room
local t = getRooms (temp.name, temp.desp, temp.entry, nil, temp.adj_info)
if #t == 1 then
CurrentRoom.close ()
CurrentRoom.callback (t)
elseif #t == 0 then -- 出现问题了
CurrentRoom.close ()
Note ("can not pos current room")
CurrentRoom.callback (nil)
else -- 数量超过1
if flag == "1" then -- 尚未check邻接房间
for _, v in pairs (temp.entry) do
Send ("l " .. v)
Send ("say current room adj " .. v)
end
Send ("say current room try pos 2")
elseif flag == "2" then -- 已经check邻接房间
CurrentRoom.close ()
CurrentRoom.callback (t)
end
end
end
function CurrentRoom.Adj (dir)
if not CurrentRoom.room.adj_info then
CurrentRoom.room.adj_info = {}
end
CurrentRoom.room.adj_info[dir] = CurrentRoom.temp
CurrentRoom.temp = nil
end
function CurrentRoom.close ()
EnableGroup ("current_room", false)
end |
|