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


using HamJam.Character;

public class SoundManager : MonoBehaviour {

	public AudioSource efxSource;
	public AudioSource musicSource;

    public List<GameObject> talkSounds;

    public GameObject magicMissileSound;
    public GameObject bowSound;
    public GameObject crawlerSound;
    public GameObject fireSound;
    public GameObject bossSword;
    public GameObject spiritHit;
    public GameObject warriorSword;

	
	public static SoundManager instance = null;
	

	// Ensure there is only one Sound Manager
	void Awake () {
		if (instance == null){
			instance = this;
		}
		else if (instance != this){
			Destroy (gameObject);
		}

		
		// Preserve sound between Scene changes
		DontDestroyOnLoad(gameObject);
	}
	
	// Play a single audio clip, one time.
	public void PlaySingle(AudioClip clip) {
		efxSource.clip = clip;
		efxSource.Play();
	}
	
	// Play a single audio clip, and Loop.
	public void PlayMusic(AudioClip clip) {
		musicSource.clip = clip;
		musicSource.Play();
	}
	
	// Update is called once per frame
	void Update () {
	    
	}

    public void PlayTalkSound()
    {
        int i = Random.Range(1, 7);

        GameObject chatSound = talkSounds[i];
        Instantiate(chatSound);
    }

	public void PlayAttackSound(AttackTypes attackType) {

        switch (attackType)
        {
            case AttackTypes.WizardHealingBolt:
                Instantiate(this.magicMissileSound);
                break;
            case AttackTypes.ArrowToTheKnee:
                Instantiate(this.bowSound);
                break;
            case AttackTypes.CrawlerHit:
                Instantiate(this.crawlerSound);
                break;
            case AttackTypes.RaidBossFireBarrage:
                Instantiate(this.fireSound);
                break;
            case AttackTypes.RaidBossSword:
                Instantiate(this.bossSword);
                break;
            case AttackTypes.SpiritHit:
                Instantiate(this.crawlerSound);
                break;
            case AttackTypes.SpitterSkag:
                Instantiate(this.crawlerSound);
                break;
            case AttackTypes.WarriorSwing:
                Instantiate(this.crawlerSound);
                break;
            case AttackTypes.WizardFireBall:
                Instantiate(this.fireSound);
                break;
            default:
                Debug.LogWarning("SoundManager: AttackTypes Outside of expected Enum\n");
                break;
        }
	}
}
