using UnityEngine;
using System.Collections;

public class targetBowMouseController : MonoBehaviour {

	public Vector3 homePosition;
	public Transform rotCenter;

	public float angleSpeed;
	public float amount;
	public Vector3 oldMousePos;
	public float mouseSpeedCoff;
	public float rotVelocity;
	public float addedVelocity;
	public float velocityRegistCoff;
	private Actor myActor;

	private bool isMouseDown;

	// Use this for initialization
	void Start () {
		myActor = transform.parent.parent.GetComponent<Actor>();
		homePosition = transform.position;
	}

	void DoInput() {
		if (Input.GetMouseButtonDown (0)) {
			oldMousePos = Input.mousePosition;
			isMouseDown = true;
		}
		if (Input.GetMouseButtonUp (0)) {
			isMouseDown = false;
		}

		amount = 0.0f;

		if (isMouseDown) {
			addedVelocity = mouseSpeedCoff * (Input.mousePosition.y - oldMousePos.y);
			rotVelocity += addedVelocity;
		}
		rotVelocity = rotVelocity * velocityRegistCoff;
		amount = Time.deltaTime * rotVelocity;

		oldMousePos = Input.mousePosition;

		if( amount != 0.0f ) {
			transform.RotateAround(rotCenter.transform.position, Vector3.forward, amount * angleSpeed * Time.deltaTime);
		}
	}

	// Update is called once per frame
	void Update () {
		if(myActor.kind == Actor.Kind.Player) {
			DoInput();
		}
	}
}
