using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {
	public float speed;

	//itemType enum 0="none",1="weapon", 2="cloak", 3="food"
	private int itemType;
	private bool attacking;
	//currentRoom enum 1="start", 2="second", 3="third", 4="fourth", 5="boss"
	public int currentRoom;
	public int health;
	public bool itemDirty;
	private bool moving;
	private bool[] inventory;
	// Use this for initialization
	void Start () {
		attacking = false;
		currentRoom = 1;
		moving = false;
		itemType = 0;
		inventory = new bool[3]{false,false,false};
		itemDirty = false;
	}
	
	// Update is called once per frame
	void Update () {
		//player attack
		if( (Input.GetKeyDown("left shift") || Input.GetKeyDown("right shift")) && itemType == 1 ){ 
			//check attack collider
			attacking = true;
		}
		else{ attacking = false; }
		//player look
		if(	Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D) ||
		   Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow) )
		{ moving = true; }
		else{ moving = false; }

	}

	void FixedUpdate(){
		Vector3 lookForward = new Vector3(Camera.main.transform.forward.x, 0f, Camera.main.transform.forward.z);
		Vector3 lookRight = new Vector3(Camera.main.transform.right.x, 0f, Camera.main.transform.right.z);
		//rigidbody.velocity += new Vector3( Input.GetAxis("Horizontal")*speed, 0f, Input.GetAxis("Vertical")*speed );
		if(moving){ rigidbody.velocity = lookForward * Input.GetAxisRaw("Vertical")*speed + lookRight * Input.GetAxisRaw("Horizontal")*speed + new Vector3(0f, rigidbody.velocity.y, 0f); }
		else{ rigidbody.velocity = new Vector3(0f, rigidbody.velocity.y, 0f); }
	}

	public bool IsAttacking(){ return attacking; }
	public int GetCurrentRoom(){ return currentRoom; }
	public void SetCurrentRoom( int room ){ 
		currentRoom = room; 
//		if( room == 1 ){ EnterFirstRoom(); }
//		else if( room == 2 ){ EnterSecondRoom(); }
//		else if( room == 3 ){ EnterThirdRoom(); }
//		else if( room == 4 ){ EnterFourthRoom(); }
//		else if( room == 5 ){ EnterFifthRoom(); }
	}
	public int GetHealth(){ return health; }
	public int GetItemType(){ return itemType; }
	public void SetItemType( string itemName ){
		if( itemName == "Sword"){ if( itemType != 1 ){ itemDirty = true; } itemType = 1; }
		else if( itemName == "Cloak"){ if( itemType != 2 ){ itemDirty = true; } itemType = 2; }
		else if( itemName == "Food"){ if( itemType != 3 ){ itemDirty = true; } itemType = 3; }
		else{ Debug.Log ("Invalid Item Type!");}
	}
}
