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

public class RadioTrapButtons : MonoBehaviour {

    public List<CharacterOne> enemy;
    public List<Button> buttonList;
    public AudioManager audMgr;
    public List<GameObject> stands;


	// Use this for initialization
	void Start () {
		
	}


    public void activateTrap1()
    {
        checkForPlayer(1);
        
        Debug.Log("Clicked Button 1");
        DeactivateButton(0);
        standBounce(0);

    }

    public void activateTrap2()
    {
        checkForPlayer(3);
        Debug.Log("Clicked Button 2");
        DeactivateButton(1);
        standBounce(1);
    }
    public void activateTrap3()
    {
        checkForPlayer(5);
        DeactivateButton(2);
        standBounce(2);
    }

    public void activateTrap4()
    {
        checkForPlayer(8);
        DeactivateButton(3);
        standBounce(3);
    }

    public void activateTrap5()
    {
        checkForPlayer(12);
        DeactivateButton(4);
        standBounce(4);
    }
    public void activateTrap6()
    {
        checkForPlayer(14);
        DeactivateButton(5);
        standBounce(5);
    }
    public void activateTrap7()
    {

    }
    public void activateTrap8()
    {

    }
    public void activateTrap9()
    {

    }


    public void checkForPlayer(int i)
    {
        bool killedSomeone = false;
        foreach(CharacterOne ch in enemy)
        {
            if (ch.currLocation == i)
            {
                //enemy.Remove(ch);
                ch.voodoo.AddComponent<Rigidbody>().useGravity = true;
                ch.alive = false;
                killedSomeone = true;
            }
        }

        CharacterOne.radioClicked = true;

        if(killedSomeone)
        {
            StartCoroutine(KillSound());
        }
        else
        {
            StartCoroutine(MissSound());
        }

    }

    public void DeactivateButton(int i)
    {
        buttonList[i].interactable = false;

    }

    IEnumerator KillSound()
    {
        audMgr.RandomizeSFX(audMgr.hits);
        yield return new WaitForSeconds(audMgr.radioSounds.clip.length);
        audMgr.RandomizeSFX(audMgr.screams);
        yield return new WaitForSeconds(audMgr.radioSounds.clip.length);
        CharacterOne.radioClicked = false;
    }

    public IEnumerator MissSound()
    {
        audMgr.RandomizeSFX(audMgr.misses);
        yield return new WaitForSeconds(audMgr.radioSounds.clip.length);
        CharacterOne.radioClicked = false;
    }

    public void standBounce(int i)
    {
        stands[i].AddComponent<Rigidbody>().AddForce(0, 400, 400);
        stands[i].GetComponent<Rigidbody>().AddTorque(30, 30, 0);
    }

}
