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

require "Player.rb"

module RubyMud

class Read < Command
	
	def words
		return ["read"]
	end	
	
	def initialize()
		super()
	end
	
	# read bookname pagenum
	def execute(clientConnection,string)
		tokens = string.split(' ')

		if (tokens.length != 2)
			clientConnection.send("read <bookname>\r\n")
			return
		end
		
		# Check if the book is in the player's inventory		
		player = clientConnection.player
		book = player.getObjectByName(tokens[1])
		
		if (book == nil)
			clientConnection.send("You dont have that book\r\n")
			return
		end
		
		# Check that the item is infact a book
		if (!book.is_a?(Book))
			clientConnection.send("uhh, you cant read a #{book.name}\r\n")
			return
		end
	
        startpage = 0
        if tokens.length == 3
            startpage = tokens[2].to_i()
        end
        
		book.read(clientConnection,startpage)
				
	end
		
end

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

end #module