using UnityEngine;
using System.Collections;

public class StaffCombat : MonoBehaviour {

    private float charge = 0f;
    public float chargeIncreasePerSecond = 0f;

    public float chargeMultiplierSpeedMax = 0f;
    private float chargeMultiplierSpeed = 0f;

    public float chargeMultiplierDmgMax = 0f;
    private float chargeMultiplierDmg = 0f;

    enum ChargeState { inactive, charging };
    private ChargeState chargeState = ChargeState.inactive;

    public GameObject projectile;

    public GameObject particles;
    private StaffChargeParticles staffChargeParticles;

    //private Animator animator;

    public Transform projectileSpawn;

	// Use this for initialization
	void Start () {
        staffChargeParticles = particles.GetComponent<StaffChargeParticles>();
        //animator = GetComponent<Animator>();
	}
	
	// Update is called once per frame
	void Update () {
        if (Input.GetButtonDown("Fire1"))
        {
            StartCharge();
        }
        if (Input.GetButtonUp("Fire1"))
        {
            StopCharge();
        }
	    if(chargeState == ChargeState.charging)
        {
            charge += Time.deltaTime * chargeIncreasePerSecond;
            charge = Mathf.Clamp(charge, 0f, 100f);
        }
	}

    public void StartCharge()
    {
        if(chargeState == ChargeState.inactive)
        {
            chargeState = ChargeState.charging;
            charge = 0f;
            staffChargeParticles.StartParticles();
            //animator.SetBool("Charge", true);
        }
    }

    public void StopCharge()
    {
        if(chargeState == ChargeState.charging)
        {
            chargeState = ChargeState.inactive;
            staffChargeParticles.StopParticles();
            Shoot();

        }
    }

    /**
    SHOOT
    Spawn projectile and give it the speed and damage multipliers
    **/
    public void Shoot()
    {
        GameObject currentProjectile = (GameObject)Instantiate(projectile, projectileSpawn.position, projectileSpawn.rotation);
        currentProjectile.GetComponent<Projectile>().Construct(charge, charge);
        //Debug.Log(charge);
        //animator.SetBool("Attack", true);
    }
}
