using System;
using UnityEngine;
using UnityEngine.AI;

namespace ftt.Gameplay.AI
{
    /* [Node documentation]
     * 
     * [Must know]
     *  INodeData compatible.
     */
    public class CatchPlayerAction : INode
    {
        MinotaurNodeData nodeData;

        NavMeshAgent agent;

        Action shootMethod;

        public CatchPlayerAction(MinotaurNodeData nodeData, Action shootMethod)
        {
            this.nodeData = nodeData;
            this.shootMethod = shootMethod;

            this.agent = nodeData.GetNavMeshAgent;
        }

        public MinotaurNodeData GetNodeData()
        {
            return nodeData;
        }

        /// <summary>
        /// Call to continuously rotate the agent towards the Target (through nodeData) and call its Action passed method.
        /// <para>Always returns true.</para>
        /// </summary>
        public bool Run()
        {
            Quaternion rotation = Quaternion.LookRotation(nodeData.GetTarget.position - agent.transform.position);
            agent.transform.rotation = Quaternion.Slerp(agent.transform.rotation, rotation, 10f * Time.deltaTime);

            //Call the passed method
            shootMethod();
            return true;
        }
    }
}