// Update is called once per frame
    void Update()
    {
        if (!isActive)
        {
            return;
        }

        anim.SetFloat("DirZ", 0);

        #region Aggressive State Machine

        //Aggressive State Machine
        if (AIPersonality == AIPersonalities.Aggressive)
        {
            //Aggressive State Machine
            switch (AIState)
            {
            case AIStates.Start:
                ChangeState(AIStates.GetHexInfo);
                break;

            case AIStates.GetHexInfo:
                FindCurrentHexandMinions();
                if (currentHex.minions == minionsToKill)
                {
                    ChangeState(AIStates.KillMinions);
                }
                if (CanSee(GameManager.instance.playersList))
                {
                    ChangeState(AIStates.ChasePlayer);
                }
                if (isHealthBelow(0))
                {
                    ChangeState(AIStates.Dead);
                }
                break;

            case AIStates.KillMinions:
                KillMinions();
                if (minionsToKill.Count == 0)
                {
                    ChangeState(AIStates.CaptureTile);
                }
                if (CanSee(GameManager.instance.playersList))
                {
                    ChangeState(AIStates.ChasePlayer);
                }
                if (isHealthBelow(0))
                {
                    ChangeState(AIStates.Dead);
                }

                break;

            case AIStates.CaptureTile:
                WalkToCapturePoint();
                if (data.ownedHexes.Contains(currentHex))
                {
                    nextHex = currentHex.AI_GetNextHex(this);
                    ChangeState(AIStates.MoveToNextHex);
                }
                if (CanSee(GameManager.instance.playersList))
                {
                    ChangeState(AIStates.ChasePlayer);
                }
                if (isHealthBelow(0))
                {
                    ChangeState(AIStates.Dead);
                }
                break;

            case AIStates.ChasePlayer:
                Chase(currentPlayerTarget.transform);
                if (isHealthBelow(0))
                {
                    ChangeState(AIStates.Dead);
                }
                if (isHealthBelow(0))
                {
                    ChangeState(AIStates.Dead);
                }
                break;

            case AIStates.MoveToNextHex:
                MoveToTargetWithObsAvoidance(nextHex.playerSpawnPoint);
                if ((data.mover.tf.position - nextHex.playerSpawnPoint.position).magnitude < closeEnoughDistance)
                {
                    ClearMinionsToKillList();
                    ClearWaypointList();
                    currentHex = null;
                    nextHex    = null;
                    ChangeState(AIStates.GetHexInfo);
                }
                if (CanSee(GameManager.instance.playersList))
                {
                    ChangeState(AIStates.ChasePlayer);
                }
                if (isHealthBelow(0))
                {
                    ChangeState(AIStates.Dead);
                }
                break;

            case AIStates.Idle:
                ChangeState(AIStates.MoveToCurrentHex);
                if (isHealthBelow(0))
                {
                    ChangeState(AIStates.Dead);
                }
                UnityEngine.Debug.Log("I'm currently Idling");
                break;

            case AIStates.Dead:
                data.mover.enabled    = false;
                data.currentHitPoints = 0;
                UnityEngine.Debug.Log("Dead");
                break;
            }
        }

        #endregion

        #region Passive State Machine
        //Passive State Machine
        if (AIPersonality == AIPersonalities.Passive)
        {
            //Passive State Machine
            switch (AIState)
            {
            case AIStates.Start:
                ChangeState(AIStates.GetHexInfo);
                break;

            case AIStates.GetHexInfo:
                FindCurrentHexandMinions();
                if (currentHex.minions == minionsToKill)
                {
                    ChangeState(AIStates.KillMinions);
                }
                if (isHealthBelow(0))
                {
                    ChangeState(AIStates.Dead);
                }
                break;

            case AIStates.KillMinions:
                if (CanSee(GameManager.instance.playersList))
                {
                    ChangeState(AIStates.FleeFromPlayer);
                }
                KillMinions();
                if (minionsToKill.Count == 0)
                {
                    ChangeState(AIStates.CaptureTile);
                }

                break;

            case AIStates.CaptureTile:
                WalkToCapturePoint();
                if (data.ownedHexes.Contains(currentHex))
                {
                    nextHex = currentHex.AI_GetNextHex(this);
                    ChangeState(AIStates.MoveToNextHex);
                }
                if (CanSee(GameManager.instance.playersList))
                {
                    ChangeState(AIStates.FleeFromPlayer);
                }
                if (isHealthBelow(0))
                {
                    ChangeState(AIStates.Dead);
                }
                break;

            case AIStates.FleeFromPlayer:
                Flee(currentPlayerTarget.transform);
                if (isHealthBelow(0))
                {
                    ChangeState(AIStates.Dead);
                }
                break;

            case AIStates.MoveToNextHex:
                MoveToTargetWithObsAvoidance(nextHex.playerSpawnPoint);
                if ((data.mover.tf.position - nextHex.playerSpawnPoint.position).magnitude < closeEnoughDistance)
                {
                    ClearMinionsToKillList();
                    ClearWaypointList();
                    currentHex = null;
                    nextHex    = null;
                    ChangeState(AIStates.GetHexInfo);
                }
                if (CanSee(GameManager.instance.playersList))
                {
                    ChangeState(AIStates.FleeFromPlayer);
                }
                if (isHealthBelow(0))
                {
                    ChangeState(AIStates.Dead);
                }
                break;

            case AIStates.MoveToCurrentHex:
                MoveToTargetWithObsAvoidance(currentHex.playerSpawnPoint);
                if ((data.mover.tf.position - currentHex.playerSpawnPoint.position).magnitude < closeEnoughDistance && currentHex.minions.Count == 0)
                {
                    ClearMinionsToKillList();
                    ClearWaypointList();
                    currentHex = null;
                    nextHex    = null;
                    ChangeState(AIStates.GetHexInfo);
                }
                else
                {
                    ChangeState(AIStates.KillMinions);
                }
                if (CanSee(GameManager.instance.playersList))
                {
                    ChangeState(AIStates.FleeFromPlayer);
                }
                if (isHealthBelow(0))
                {
                    ChangeState(AIStates.Dead);
                }
                break;

            case AIStates.Idle:
                ChangeState(AIStates.MoveToCurrentHex);
                if (isHealthBelow(0))
                {
                    ChangeState(AIStates.Dead);
                }
                break;

            case AIStates.Dead:
                data.mover.enabled    = false;
                data.currentHitPoints = 0;
                break;
            }
        }

        #endregion

        #region Defensive State Machine
        //Defensive State Machine
        if (AIPersonality == AIPersonalities.Defensive)
        {
            //Defensive State Machine
            switch (AIState)
            {
            case AIStates.Start:
                ChangeState(AIStates.GetHexInfo);
                break;

            case AIStates.GetHexInfo:
                FindCurrentHexandMinions();
                if (currentHex.minions == minionsToKill)
                {
                    ChangeState(AIStates.KillMinions);
                }
                break;

            case AIStates.KillMinions:
                KillMinions();
                if (minionsToKill.Count == 0)
                {
                    ChangeState(AIStates.CaptureTile);
                }
                break;

            case AIStates.CaptureTile:
                WalkToCapturePoint();
                if (data.ownedHexes.Contains(currentHex))
                {
                    nextHex = currentHex.AI_GetNextHex(this);
                    ChangeState(AIStates.MoveToNextHex);
                }
                if (CanSee(GameManager.instance.playersList))
                {
                    ChangeState(AIStates.ChasePlayer);
                }
                break;

            case AIStates.ChasePlayer:
                Chase(currentPlayerTarget.transform);

                break;

            case AIStates.MoveToNextHex:
                MoveToTargetWithObsAvoidance(nextHex.playerSpawnPoint);
                if ((data.mover.tf.position - nextHex.playerSpawnPoint.position).magnitude < closeEnoughDistance)
                {
                    ClearMinionsToKillList();
                    ClearWaypointList();
                    currentHex = null;
                    nextHex    = null;
                    ChangeState(AIStates.GetHexInfo);
                }
                break;

            case AIStates.PatrolOwnedTerritory:

                break;

            case AIStates.Idle:
                UnityEngine.Debug.Log("I'm currently Idling");
                break;

            case AIStates.Dead:
                UnityEngine.Debug.Log("Dead");
                break;
            }
        }

        #endregion

        #region Dark State Machine
        //Dark State Machine
        if (AIPersonality == AIPersonalities.Dark)
        {
            //Dark State Machine
            switch (AIState)
            {
            case AIStates.Start:
                ChangeState(AIStates.GetHexInfo);
                break;

            case AIStates.GetHexInfo:
                FindCurrentHexandMinions();
                if (currentHex.minions == minionsToKill)
                {
                    ChangeState(AIStates.KillMinions);
                }
                break;

            case AIStates.KillMinions:
                KillMinions();
                if (minionsToKill.Count == 0)
                {
                    ChangeState(AIStates.CaptureTile);
                }
                break;

            case AIStates.CaptureTile:
                WalkToCapturePoint();
                if (data.ownedHexes.Contains(currentHex))
                {
                    nextHex = currentHex.AI_GetNextHex(this);
                    ChangeState(AIStates.MoveToNextHex);
                }
                if (CanSee(GameManager.instance.playersList))
                {
                    ChangeState(AIStates.ChasePlayer);
                }
                break;

            case AIStates.ChasePlayer:
                Chase(currentPlayerTarget.transform);

                break;

            case AIStates.MoveToNextHex:
                MoveToTargetWithObsAvoidance(nextHex.playerSpawnPoint);
                if ((data.mover.tf.position - nextHex.playerSpawnPoint.position).magnitude < closeEnoughDistance)
                {
                    ClearMinionsToKillList();
                    ClearWaypointList();
                    currentHex = null;
                    nextHex    = null;
                    ChangeState(AIStates.GetHexInfo);
                }
                break;

            case AIStates.Idle:
                UnityEngine.Debug.Log("I'm currently Idling");
                break;

            case AIStates.Dead:
                UnityEngine.Debug.Log("Dead");
                break;
            }
        }
        #endregion
    }