using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class StatManager : MonoBehaviour {

	public static StatManager current;

	public GameObject[] buildingButtons;

	public float bonusFlatDamage = 0;
	public float bonusTurretRange = 0;
	public float bonusFireRate = 0;
	public int bonusChamberCapacity = 0;
	public float bonusPortalSpeed = 0;
	public float bonusSoulIncome = 0;
	public float bonusBoostRange = 0;

	public float portalRegen = 0; // HPs per sec

	void Start() {
		current = this;
	}

	void Update() {
		UpdateChamberButtons();
	}

	void UpdateChamberButtons() {
		for (int i = 0; i < buildingButtons.Length; i++) {
			buildingButtons[i].GetComponent<Tooltip>().cost = BuildingCost(i);
			Text c = buildingButtons[i].transform.Find ("Cost").GetComponent<Text>();
			c.text = "$" + string.Format("{0:n0}", BuildingCost(i));

			if(BuildingCost(i) > Game.current.totalMoney) {
				c.color = Color.red;
			}
			else {
				c.color = new Color(0.2f, 0.2f, 0.2f);
			}
		}
	}

	static public int BuildingCost(int buildingIndex) {
		if(buildingIndex < 9) {
			// Is a chamber
			return (int)(Mathf.Pow(2f, buildingIndex) * 10f);
		}

		switch(buildingIndex) {
		case 9:	// Sniper
			return 100;
		case 10: // Machine Gun
			return 300;
		case 11: // Soulzooka
			return 2500;
		case 12: // Damage boost
			return 500;
		case 13: // RoF boost
			return 500;
		case 14: // Range boost
			return 500;


		}

		return 999999;
	}
}
