require "Command.rb"
require "Commands.rb"

require "Room.rb"

module RubyMud

# List all the object in the system that derive from
# some specific object
class List < Command
	
	def words
		return ["list"]
	end	

	def canUse?(object)
		return true if object.getFlagByClass(Admin)	!= nil or object.getFlagByClass(Builder) != nil
		return false
	end
	
	def initialize()
		super()
	end
		
	#eg. dig in1;in2;in3.. out1;out2;out3...
	def execute(clientConnection,string)
		tokens = string.split(' ')
		
		if (tokens.length < 2)
			clientConnection.send("list classname\r\n")	
			return true
		end


		begin
			theclass = eval(tokens[1])
		rescue
			clientConnection.send("<red>#{tokens[1]} as a class doesnt exist\r\n")
			return true
		end
		
		clientConnection.send("<bright white>Classes that inherit from #{tokens[1]}\r\n")

		for c in BaseObject.getClasses
			next if !c.ancestors.include?(theclass)
			clientConnection.send("<bright green>#{c.name}\r\n")
		end

		return true		
	end
		
end

# Create the instance, it adds itself to the commands list
List.new()

end # module