def_object.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
-rwxr-xr-x

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


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

mercurial