def_room.lua

Sat, 27 Mar 2010 17:43:08 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Sat, 27 Mar 2010 17:43:08 +0000
changeset 0
cc66ad6b0d75
permissions
-rw-r--r--

Initial commit (importing from old SVN repo which got lost)

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

mercurial