using UnityEngine;
using System.Collections;

public class ComboDifficultyHandler : MonoBehaviour {

	[HideInInspector]
	public LevelManager lvlMng;

	public float speedIncrease = 0.1f;
	public float maxSpeed = 3.0f;

	public float speedDecrease = 0.1f;
	public float minSpeed = 1.0f;

	void Awake()
	{
		lvlMng = GetComponent<LevelManager>();
	}

	void OnEnable()
	{
		EventManager.StartListening(Constants.IncreaseDifficulty, IncreaseDifficulty);
		EventManager.StartListening(Constants.DecreaseDifficulty, DecreaseDifficulty);
	}

	void OnDisable()
	{
		EventManager.StopListening(Constants.IncreaseDifficulty, IncreaseDifficulty);
		EventManager.StopListening(Constants.DecreaseDifficulty, DecreaseDifficulty);
	}

	void IncreaseDifficulty()
	{
		if(lvlMng.comboTimeSpeed < maxSpeed)
			lvlMng.comboTimeSpeed += speedIncrease;
		else
			lvlMng.comboTimeSpeed = maxSpeed;
	}

	void DecreaseDifficulty()
	{
		if(lvlMng.comboTimeSpeed > 	minSpeed)
			lvlMng.comboTimeSpeed -= speedDecrease;
		else
			lvlMng.comboTimeSpeed = minSpeed;
	}
}
