using UnityEngine;
using System.Collections;

public class Hero : Unit {	
	public static Hero instance;
	Effect attackEffect;
	
	public int maxLife = 100;
	const int INVENTORY_SIZE = 20;
	public Item[] inventory = new Item[INVENTORY_SIZE];
	bool canMove = false;
	
	void Awake () {
		attackEffect = Utils.Create<Effect>(transform, Vector3.zero);
		instance = this;
		life = 100;
		damage = 5;
		previos = new Coordinate(0, 0);
		inventory[0] = new LifeElixir();
	}
	
	public void Move(Direction needDirection){
		direction = needDirection;
		action = Action.move;
	}
	
	public override void StartTurn() {
		GameInterface.UpdateLife(life);
	}
	
	public override void EndTurn(){
		GameInterface.UpdateLife(life);
		shift = Vector3.zero;
		canMove = MoveNextPathPoint();
	}
	
	public bool HaveKey(int num){
		if (inventory != null){
			foreach(Item item in inventory){
				if (item is Key){
					if (((Key)item).number == num)
						return true;
				}
			}
		}
		return false;
	}
	
	void Start () {
		name = "hero";
		CreateUnitSprites(
			new Coordinate(0, 1),
			new Coordinate(1, 1),
			new Coordinate(2, 1),
			new Coordinate(3, 1));
	}
	
	public override void AttackUnit (Unit enemy)
	{
		base.AttackUnit (enemy);
		attackEffect.Use((int)direction);
	}
	/*
	protected override void MoveUnit(){
		base.MoveUnit();
	}
	*/
	public void MoveToPath(Direction[] newPath){
		path = newPath;
		pathPosition = 0;
	}
		
	void Update () { 
		if (canMove) {
			Level.instance.MakeTurn();	
			canMove = false;
		}
		MoveUnit();
	}
}
