# Inheritance
require "Mobile.rb"
require "Players.rb"

module RubyMud

class Player < Mobile

	# ###########
	# Room Events
	# ###########
	
	# Is called when this mobile enters the room
	def onEnterRoom(exit)
		
		room = @parent
		clientConnection().send(room.description+"\r\n")
		clientConnection().send("<bright green>"+room.descriptionOfMobilesInRoom(self))
		clientConnection().send("<green>"+room.descriptionOfItemsInRoom())
		clientConnection().send("<bright yellow>[#{room.exitString}]\r\n")
		# Print the prompt here		
		super
	end
		
	def onBeforeLeavingRoom(otherRoom)
		super
	end
	
	def onItemDroppedInRoom(mobile,item)
		if (mobile == self)
			clientConnection().send("You droped a "+item.name+"\r\n")
		else
			clientConnection().send(mobile.name+" droped a "+item.name+"\r\n")
		end
	end
	
	# Players dont do anything special when a mob enters the room
	def onMobileEnteredRoom(mobile)
		super
	end	
	
	# Players dont do anything special when a mob enters the room
	def onMobileLeftRoom(mobile)
		super
	end
	
	# If someone specific said something, we echo it to the player
	def onMobileSaidSomethingInRoom(mobile,something)		
		if (mobile == self)
			clientConnection().send("You "+something+"\r\n")
		else
			clientConnection().send(mobile.name+" "+something+"\r\n")
		end
	end
	
	# If the room wants to talk to the player, 
	# we echo it to the clientConnection
	def onRoomTalk(mobile,something)
		if (mobile == self)
			return
		end
		clientConnection().send(something+"\r\n")
	end	

	# Overload description
	def description
		"Player Description Not done\n"
	end	
	
	def clientConnection()	
		return Players.getConnection(self)
	end
		
	def initialize(room,name,clientConnection)
		super(room,name,"")
		
		Players.add(self,clientConnection)
	end
	
end

end