def_object.lua

changeset 0
cc66ad6b0d75
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/def_object.lua	Sat Mar 27 17:43:08 2010 +0000
@@ -0,0 +1,56 @@
+
+classes.default._properties = { name = "object", longname = "An object", desc = "You see nothing of interest" }
+
+function classes.default:_create(e)
+	local obj = CreateObject(self, e.name);
+	obj._room = e.room;
+	return obj;
+end
+			
+function classes.default:look (e)
+	FSay(e.room, e.nick, "/me looks at "..(self._properties.prepend or "The ")..self._properties.name or "____");
+	PSay(e.room, e.nick, "", self._properties.desc);
+end
+
+function classes.default:_say(text, room)
+	FSay(room or self._room, (self._properties.prepend or "The ")..self._properties.name, text);
+end
+
+function classes.default:_action(text, room)
+	return self:_say("/me "..text, room);
+end
+
+function classes.default:_findobject(name, where)
+	if not (self._contents and self._contents[where or "in"]) then return nil; end
+	if self._properties.locked then return false; end
+	return self._contents[where or "in"]:findobject(name);
+end
+
+function classes.default:_unlink(object)
+	if not (self._contents and self._contents["in"]) then print("Attempt to _unlink on a non-container."); return nil; end
+	if type(object) == "string" then object = self._contents["in"]:findobject(object); end
+	if not object then return false; end
+	if self._contents["in"]:remove(object) then
+		return true;
+	end
+end
+
+function classes.default:_get(i)
+	if not (self._contents and self._contents["in"]) then print("Attempt for a non-container to _get"); return nil; end
+	if not (i.container:_unlink(i.object)) then return false; end
+	self._contents["in"]:add(i.object);
+	return true;
+end
+
+classes.default["look in"] =
+	function (self, e)
+		local contents = {};
+		local contents2 = {};
+		if not (self._contents and self._contents["in"]) then e.person:_tell("That is not a container."); return; end
+		contents = self._contents["in"]:getallobjects();
+		for o, exists in pairs(contents) do
+			print("o");
+			table.insert(contents2, o._properties.longname or o._properties.name or "Something");
+		end
+		e.person:_tell("You see: "..table.concat(contents2,", "));
+	end
\ No newline at end of file

mercurial