def_room.lua

changeset 0
cc66ad6b0d75
equal deleted inserted replaced
-1:000000000000 0:cc66ad6b0d75
1
2 classes.obj_room =
3 {
4 _properties = {};
5 _create = function (self, e)
6 self.people = {}; self._objects = createcontainertable(); self._properties.name = e.room; self._properties.server = e.server; self.jid = e.room.."@"..e.server;
7 if type(tpl_rooms[e.room]) == "table" then
8 for k, v in pairs(tpl_rooms[e.room]) do
9 self[k] = v;
10 end
11 return self._init and self._init(self, e);
12 end
13 end,
14 _addobject = function (self, e)
15 if e.class then self._objects:add(e.class:_create{room = self, name = e.name, ext = e }); end
16 end,
17 _addalias = function (self, e)
18 for k, v in ipairs(e) do
19 self._objects:addalias(e[1], v);
20 end
21 end,
22 _enter = function (self, e)
23 PSay(e.room, e.nick, " ", "You have entered "..(e.room._properties.longname or e.room._properties.name or "the room"));
24 end,
25 _findobject=function (self, tag)
26 if not tag then return nil; end
27 tag = tag:match("^the (.*)$") or tag;
28 return self._objects:findobject(tag);
29 end,
30 look = function (self, e)
31 local contents = {};
32 local contents2 = {};
33 contents = self._objects:getallobjects();
34 for o, exists in pairs(contents) do
35 table.insert(contents2, o._properties.longname or o._properties.name or "Something");
36 end
37
38 e.person:_tell("You see in this room: "..table.concat(contents2,", "));
39 end,
40 obj = function (self, e)
41 local contents = {};
42 local contents2 = {};
43 contents = self._objects:getallobjects();
44 for o, exists in pairs(contents) do
45 table.insert(contents2, (o._properties.longname or o._properties.name or "Something")..(" ("..o._properties.name or "No name")..")");
46 end
47
48 e.person:_tell("You see in this room: \n"..table.concat(contents2,"\n"));
49 end,
50 teleport = function (self, e)
51 if not e.param or #(e.param) == 0 then PSay(e.room, e.nick, " ", "Teleport to where exactly?"); end
52 MoveToRoom(e.person, e.param);
53 end,
54 where = function (self, e)
55 PSay(e.room, e.nick, " ", "You are in "..e.room._properties.name);
56 end
57 }
58
59 function classes.obj_room:_unlink(o)
60 if not self._objects then print("Attempt to _unlink from an empty room."); return nil; end
61 if type(o) == "string" then o = self._objects:findobject(o); end
62 if (not o) or (o._properties and o._properties.static == true) then return false; end
63 if self._objects:remove(o) then
64 return true;
65 end
66 end
67
68 function classes.obj_room:_get(i)
69 if not self._objects then self._objects = createcontainertable(); end
70 if not i.container:_unlink(i.object) then return false; end
71 print("room _get", self._properties.name or "o");
72 self._objects:add(i.object);
73 return true;
74 end

mercurial