using UnityEngine;
using System.Collections;

public class MonsterStatus : MonoBehaviour {

	public int Health=1;
	public AudioClip DeathClip;
	public JuiceDropper DamageJuiceDropper;

	//public Vector2 StunDir { get; set; }

	private bool dead = false;
	private bool stunned = false;
	private float stunUntil;
	
	private GameController gc;
	//private MonsterDeathScene deathScene;
	
	// Use this for initialization
	void Start () {
		
		GameObject cgo = GameObject.Find ("GameController");
		gc = cgo.GetComponent<GameController>();
		
		//deathScene = gameObject.GetComponent<MonsterDeathScene>();
		
	}
	
	public bool IsDead()
	{
		return dead;
	}
	
	public bool IsStunned()
	{
		return Time.time < stunUntil;
	}
	
	public void Die()
	{
		dead = true;
		//deathScene.MarkForDeath();
		gc.ReportKill();
		if(DeathClip != null)
			iTween.Stab(gc.gameObject, iTween.Hash ("audiosource", gc.RewardAudio, "audioclip", DeathClip, "volume", gc.Volume));

		GameObject.Destroy(gameObject);
	}
	
	public void Stun(float t, Vector2 direction)
	{
		stunUntil = Time.time + t;
		//StunDir = direction;
		//iTween.PunchPosition(gameObject, StunDir, t);
		//iTween.MoveBy(gameObject, direction, t);
		Vector3 amt = (Vector3) direction;
		iTween.MoveBy(gameObject, iTween.Hash("amount",amt,"time",t,"easetype",iTween.EaseType.easeOutBack));			
		//iTween.ColorFrom(gameObject, Color.yellow, 0.0025f);
	}

	public void TakeDamage(int dmg)
	{
		iTween.PunchScale(gameObject, new Vector3(0.5f, 1.5f, 0), 0.51f);
		Stun (0.5f, new Vector2(0,-1));
		Health -= dmg;
		if(DamageJuiceDropper != null)
			DamageJuiceDropper.StartDropping();
		if(Health<=0)
			Die ();
	}

}
