module RubyMud

class MainTick

	include Tickable

	attr_accessor :tickTime

	def initialize()
		@tickables = []
		@tickTime = 10
	end
	
	def addTickable(tickable)
		@tickables.push(tickable)
	end	
	
	def removeTickable(tickable)
		@tickables.delete(tickable)
	end		
	
	def clear()
		@tickables = []
	end
	
	def tick()
	
		# Write out to all the players that want to see the main tick
		players = Players.getPlayers()
		for player in players
			if player.clientConnection() != nil and player.getFlagByClassName("RubyMud::SeeMainTick") != nil
				player.clientConnection().send("<red>--Tick--\r\n")
			end
		end
		
		# Tick all the tickables
		for tickable in @tickables
			tickable.tick()
		end
		
		# Add itself to the queue again
		# Tick every @tickTime seconds
		TickObject.new(self,Time.now+@tickTime)
	end
	
end

$mainTick = MainTick.new()
TickObject.new($mainTick,Time.now+10)

end #module