using UnityEngine;
using System.Collections;

public class BossBehavorialManager : MonoBehaviour {
    public GameObject cauldronP, cauldronC, pepsi, coke, healthBar;
    float speed = 0.1f;
    private int SpawnerID;
    public int health;
    private GameObject objSpawn;

    // Use this for initialization
    void Start () {
        objSpawn = GameObject.FindWithTag("Spawner");
        health = 40;
        
    }
	
	// Update is called once per frame
	void Update () {
        pepsi.transform.position = Vector2.MoveTowards(this.transform.position, cauldronP.transform.position, speed);
        coke.transform.position = Vector2.MoveTowards(this.transform.position, cauldronC.transform.position, speed);
        
    }

    public void removeMe()
    {
        objSpawn.BroadcastMessage("killEnemy", SpawnerID);
		GameObject.Find ("CocaPepsa").GetComponent<CocaPepsaLife> ().LoseFiveLife ();
		GameObject.FindGameObjectWithTag ("Player").GetComponent<LoseGame> ().counter+=5;
        Destroy(gameObject);
    }

    // this gets called in the beginning when it is created by the spawner script
    void setName(int sName)
    {
        SpawnerID = sName;
    }

    void OnCollisionEnter2D(Collision2D coll)
    {
        if (coll.gameObject.tag == "CauldronP" || coll.gameObject.tag == "CauldronC")
        {
            removeMe();
        }
        if ((coll.gameObject.tag == "Player" && _PlayerMovement.canDie == true) || (coll.gameObject.tag == "Boomerang" && BoomerangUpgrade.canDie == true) || (coll.gameObject.tag == "Pentagram" && Pentagram.canDie == true))
        {
            health -= 5;
            Debug.Log("Hit! ");
            if(health <= 0)
            {
                removeMe();
            }
        }
    }

    void OnTriggerEnter2D(Collider2D coll)
    {
        if ((coll.gameObject.tag == "Boomerang" && BoomerangUpgrade.canDie == true))
        {
            removeMe();
        }
    }
}
