using UnityEngine;
using System.Collections;

public class Human : Movable {

	public Transform selectedArrow;
	public float workForce = 1f;

	public Area currArea;

	bool selected = false;
	public bool Selected {
		get { return selected; }
		set {
			selected = value;
			OnSelectedChange();
		}
	}

	protected override void Start () {
		base.Start();
		OnSelectedChange();
	}

	bool InRitual { get { return currArea != null && currArea.name == "ritual"; } }

	public void UpdateDance () {
		
		anim.SetBool("Dancing", InRitual && Game.instance.ritualArea.BonfireOn);
	}

	public override void OnEnterArea (Area area) {
		if (area.resource == "IGNORE")
			return;
		currArea = area;
		area.totalWorkForce += workForce;
		if (area.name == "ritual")
			UpdateDance();


		if (area.name == "goats")
			Game.PlaySfx("goats");

		else if (area.name == "well")
			Game.PlaySfx("well");

		else if (area.name == "wheat")
			Game.PlaySfx("wheat");

	}

	public override void OnExitArea (Area area) {
		if (area.resource == "IGNORE")
			return;
		currArea = null;
		area.totalWorkForce -= workForce;
		if (area.name == "ritual")
			UpdateDance();
	}

	public void OnSelectedChange () {
		selectedArrow.gameObject.SetActive(selected);
	}

	public void WorkTick () {
		
		if (currArea == null || !currArea.HasResources)
			return;
		
		float amount = workForce * currArea.harvestRate;
		Game.instance.Harvest(currArea.resource, amount);
		icon.Show(currArea.resource, amount >= 3);
	}
}
