using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RelicGGJ;

public class ChaserBehaviour : EnemyController
{
    public float m_aggressiveRadius = 4f;
    public override Vector2 GetTarget()
    {
        int moveDir = Random.Range(-3, 4);
        Debug.Log(Utility.CalcDistance(m_position, PlayerController.Instance.m_previousPosition));
        Debug.Log(Utility.CalcDistance(m_position, PlayerController.Instance.m_previousPosition) + ", " + m_aggressiveRadius);
        if (Utility.CalcDistance(m_position, PlayerController.Instance.m_previousPosition) <= m_aggressiveRadius)
        {
            Debug.Log("Chasing");
            Vector2 diff = PlayerController.Instance.m_previousPosition - m_position;
            if (diff.x == 0 && diff.y < 0)
            {
                moveDir = 0;
            }
            else if (diff.x > 0 && diff.y < 0)
            {
                moveDir = Random.Range(0, 2);
            }
            else if (diff.x > 0 && diff.y == 0)
            {
                moveDir = 1;
            }
            else if (diff.x > 0 && diff.y > 0)
            {
                moveDir = Random.Range(1, 3);
            }
            else if (diff.x == 0 && diff.y > 0)
            {
                moveDir = 2;
            }
            else if (diff.x < 0 && diff.y > 0)
            {
                moveDir = Random.Range(2, 4);
            }
            else if (diff.x < 0 && diff.y == 0)
            {
                moveDir = 3;
            }
            else if (diff.x < 0 && diff.y < 0)
            {
                moveDir = Random.Range(0, 2) == 0 ? 3 : 0;
            }
        }
       
        Vector2 newPos = m_position;
        switch (moveDir)
        {
            case 0:
                newPos.y--;
                break;
            case 1:
                newPos.x++;
                break;
            case 2:
                newPos.y++;
                break;
            case 3:
                newPos.x--;
                break;
        }
        return newPos;
    }
}
