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

public class BattleCanvasScript : MonoBehaviour {

	float fill1;
	float fill2;
	List<Monster> mp1;
	List<Monster> mp2;
	float monsterhp1;
	float monsterhp2;
	float monsterhpc1;
	float monsterhpc2;
	float hp1;
	float hp2;
	public Text pn1;
	public Text pn2;

	// Use this for initialization
	void Start () {
		fill1 = GameObject.Find ("full1").GetComponent<Image>().fillAmount;
		fill2 = GameObject.Find ("full2").GetComponent<Image>().fillAmount;
		mp1 = GameMaster.players [0].GetMonsters ();
		mp2 = GameMaster.players [1].GetMonsters ();
		monsterhp1 = mp1 [GameMaster.players [0].GetActiveMonster()].GetHealth ();
		monsterhp2 = mp2 [GameMaster.players [1].GetActiveMonster()].GetHealth ();
		monsterhpc1 = monsterhp1;
		monsterhpc2 = monsterhp2;
		pn1.text = ""+GameMaster.players[0].GetName();
		pn2.text = ""+GameMaster.players[1].GetName();
	}
	
	// Update is called once per frame
	void Update () {
		monsterhpc1 = mp1 [GameMaster.players [0].GetActiveMonster()].GetHealth ();
		monsterhpc2 = mp2 [GameMaster.players [1].GetActiveMonster()].GetHealth ();
		hp1 = monsterhpc1 / monsterhp1;
		hp2 = monsterhpc2 / monsterhp2;

		//Debug.Log ("fill1 before" + fill1);

		fill1 = Mathf.Lerp (fill1, hp1, 2*Time.deltaTime);
		fill2 = Mathf.Lerp (fill2, hp2, 2*Time.deltaTime);

		//Debug.Log ("fill1 after" + fill1);
		//Debug.Log ("hp1 " + hp1);

		GameObject.Find ("full1").GetComponent<Image>().fillAmount = fill1;
		GameObject.Find ("full2").GetComponent<Image>().fillAmount = fill2;
		//Debug.Log (fill1);
		//Debug.Log (fill2);
	}

	public void changeMaxHp(int newMonster) {
		if(newMonster == 0) {
			monsterhp1 = mp1 [GameMaster.players [0].GetActiveMonster()].GetHealth ();
		} else {
			monsterhp2 = mp2 [GameMaster.players [1].GetActiveMonster()].GetHealth ();
		}
	}
}
