using UnityEngine;
using System.Collections;

public class JellyfishFSM : baseFSM
{
    public float timer = 0;
    public float delay = 5;

    public enum FSMState
    {
        None,
        StandBy,
        Chase,
        Attack,
        Dead,
    }

    public FSMState curState;


    protected override void Initialize()
    {
        curState = FSMState.Chase;
    }

    protected override void FSMUpdate()
    {
        switch (curState)
        {
            case FSMState.StandBy: UpdateStandbyState(); break;
            case FSMState.Chase: UpdateChaseState(); break;
            case FSMState.Attack: UpdateAttackState(); break;
            case FSMState.Dead: UpdateDeadState(); break;
        }
    }

    protected void UpdateStandbyState()
    {
        Debug.Log("On-StandBy");
        
        timer += Time.deltaTime;

        if(timer >= delay)
        {
            curState = FSMState.Attack;
        }
        //StartCoroutine(delayTime());
        
    }

    IEnumerator delayTime()
    {
        yield return new WaitForSeconds(2);
    }
    /// <summary>
    /// Chase states
    /// </summary>
    protected void UpdateChaseState()
    {
        Debug.Log(randomTransformPoint); // Point to go big brother
        Vector3 PlayerMovingPosition = Vector3.MoveTowards(transform.position, targetTransform[randomTransformPoint].position, movementSpeed * Time.deltaTime);
        transform.position = PlayerMovingPosition;

        if(this.transform.position == targetTransform[randomTransformPoint].position)
        {
       
            curState = FSMState.StandBy;

        }

    }

    /// <summary>
    /// Attack state
    /// </summary>
    protected void UpdateAttackState()
    {
        Debug.Log("Attacking");
        anim.SetFloat("Jellyfish_Anim", 1);
        Vector3 PlayerMovingPosition = Vector3.MoveTowards(transform.position, target.transform.position, movementSpeed * Time.deltaTime);
        transform.position = PlayerMovingPosition;
    }

    /// <summary>
    /// Dead state
    /// </summary>
    protected void UpdateDeadState()
    {

    }
}