using UnityEngine;
using System.Collections;

public class Detector : MonoBehaviour {

	public enum e_pos {CORE, UP, DOWN, RIGHT, LEFT};

	public GameObject	theMinion;
	public e_pos				position;
	
	Detectors					detectorManager;
	bool								isMoving = false;
	
	void Awake(){
		detectorManager = theMinion.GetComponent<Detectors>();
	}
	
	void OnTriggerStay(Collider other){
		ColliderManager(other, true);
	}
	
	void OnTriggerExit(Collider other){
		ColliderManager(other, false);
	}
	
	void ColliderManager(Collider other, bool isEnter){
		bool canWalkHere = false;
		if (other.tag == "Floor" || other.tag == "Checkpoint"){
			canWalkHere = true;
		}
		if (!isEnter)
			canWalkHere = !canWalkHere;
		switch (position){
			case e_pos.CORE :
				detectorManager.currentSlot = other.tag;
				detectorManager.currentSlotObject = other.gameObject ;
				if ((other.tag == "Floor" || other.tag == "Checkpoint") && theMinion.GetComponent<Movements>().pawnType == Movements.e_pawn_type.MINION){
					other.transform.gameObject.GetComponent<FloorSlot>().whoIsHere = theMinion;
				}
				break;
			case e_pos.UP :
				detectorManager.canWalkUp = canWalkHere;
				detectorManager.slotObjectUp = other.gameObject ;
				break;
			case e_pos.DOWN :
				detectorManager.canWalkDown = canWalkHere;
				detectorManager.slotObjectDown = other.gameObject ;
				break;
			case e_pos.RIGHT :
				detectorManager.canWalkRight = canWalkHere;
				detectorManager.slotObjectRight = other.gameObject ;
				break;
			case e_pos.LEFT :
				detectorManager.canWalkLeft = canWalkHere;
				detectorManager.slotObjectLeft = other.gameObject ;
				break;
		}
	}
}
