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

module RubyMud

class Look < Command
	
	def words
		return ["look","l"]
	end	
	
	def initialize()
		super()
	end
	
	def lookAtRoom(clientConnection)
		room = clientConnection.player.parent
		
		exits = room.exitString
		
		clientConnection.send(room.description+"\r\n")
		clientConnection.send("<bright white>#{room.longDescription}")
		clientConnection.send("<bright green>"+room.descriptionOfMobilesInRoom(clientConnection.player))
		clientConnection.send("<green>"+room.descriptionOfItemsInRoom())
		clientConnection.send("<bright yellow>[#{exits}]\r\n") if (exits != "")
	end
	
	def execute(clientConnection,string)
		tokens = string.split(' ')

		# If only look is on the command line
		if (tokens.length == 1)
			lookAtRoom(clientConnection)
			return true
		end
		
		player = clientConnection.player
		
		# Ok, the player would most likely want to look at something
		#1. In the room
		
		inTheRoom = player.parent.getObjectByName(tokens[1])
		if (inTheRoom != nil)
			if (inTheRoom.is_a?(Item))
				clientConnection.send("You see a #{inTheRoom.name} lying here\r\n")
				return true
			end			
			if (inTheRoom.is_a?(Mobile))
				clientConnection.send("#{inTheRoom.description}\r\n")
				return true
			end			
			clientConnection.send("You doent seem to be able to look at that\r\n")
			return true
		end

		#2. On himself
		onThePlayer = player.getObjectByName(tokens[1])
		if (onThePlayer != nil)
			if (onThePlayer.is_a?(Item))
				clientConnection.send("#{onThePlayer.description}\r\n")
				return true
			end			
			clientConnection.send("Mhm, you cant look at that on yourself\r\n")
			return true
		end		
		
		clientConnection.send("You dont see anything like that here\r\n")
		
	end
		
end

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

end # module