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

module RubyMud

class Help < Command
	
	def words
		return ["help"]
	end	
	
	def initialize()
		super()
	end
	
	def getHelp(clientConnection,string)
		
		helpstring="Help on "+string+" from database\r\n"
	         
		clientConnection.send(helpstring)
	end
	
	def showAllCommands(clientConnection)
		commands = Commands.getCommands()
		for i in 0...commands.length
			command = commands[i]			
		
			# Check if the current user may use the command
			next if !command.canUse?(clientConnection.player)
	
			# Look through the words
			words = command.words
			next if words == nil
			clientConnection.send(command.class.name+"->")
			for j in 0...words.length
				clientConnection.send(words[j]+" ")
			end
			
			clientConnection.send("\r\n")	
		end
		clientConnection.send("\r\n")
	end
	
	def execute(clientConnection,string)
		tokens = string.split(' ')
		# If only Help is on the command line display all help available
		if (tokens.length == 1)
			showAllCommands(clientConnection)
			return
		end
		
		if (tokens.length == 2)
			getHelp(clientConnection,tokens[1]) 
		end 
		
	end
		
end

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

end #module