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

public class RoomTrigger : MonoBehaviour {
	public int roomNumber;
	public EnemyController[] enemies;
	private PlayerController player;
	// Use this for initialization
	void Start () {
		player = GameObject.FindWithTag("Player").GetComponent<PlayerController>();
	}
	
	// Update is called once per frame
	void Update () {
		
	}

	void OnTriggerEnter(Collider other){
		if( other.gameObject.tag == "Player" ){
			player.SetCurrentRoom(roomNumber);
			transitionMusic();
			for(int i =0; i < enemies.Length; i++){ enemies[i].EnterRoom(roomNumber); }
		}
	}

	void transitionMusic( ){
		if(player.itemDirty){
			AudioSource[] audio = player.GetComponentsInChildren<AudioSource>();
			foreach( AudioSource a in audio ){ a.mute = true; }
			AudioSource music;
			if( player.GetItemType() == 1 ){
				music = GameObject.Find("Warrior").GetComponent<AudioSource>();
			}
			else if( player.GetItemType() == 2 ){
				music = GameObject.Find("Rogue").GetComponent<AudioSource>();
			}
			else{return;}
			music.Play();
			music.loop = true;
			music.mute = false;
			player.itemDirty = false;
		}
	}
}
