﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Supergun
{
    [CreateAssetMenu(menuName = "PluggableAI/Decision/Exit Chase Decision")]
    public class ChaseExitDecision : Decision
    {
        public override bool Decide(StateController controller)
        {
            return ExitChase(controller);
        }

        private bool ExitChase(StateController controller)
        {
            NPCMovement npc = controller.npc;
            Enemy enemyStats = controller.enemy;

            //Check if 
            RaycastHit2D hitInfo = Physics2D.Raycast(npc.rb2d.position, npc.direction, enemyStats.scanRange, enemyStats.scanMask);

            //check for obstructions we might have missed 
            if (hitInfo && hitInfo.distance < enemyStats.chaseRange)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}