def_room.lua

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