using AI.Base;
using System;
using UnityEngine;

[CreateAssetMenu(menuName = "AI/Enemy/EnemyChaseState")]
public class EnemyChaseState : StateNode {
  public float Speed = 3f;

  private Transform Player;

  override public StateNode InitializeCopy(Transform ownerTransform) {
    var copy = ScriptableObject.CreateInstance(this.GetType()) as EnemyChaseState;
    copy.Owner = ownerTransform;
    copy.Speed = Speed;
    return copy;
  }

  override public void Start() {
    Player = GameObject.FindGameObjectWithTag("Player").transform;
    Debug.Log("Entering Chase");
  }

  override public void Tick() {
    if (Owner != null && Player != null) {
      Vector2 dir = (Player.position - Owner.position).normalized;
      Owner.position += (Vector3)dir * Speed * Time.deltaTime;
    }
  }

  override public void Stop() {
    Debug.Log("Exiting Chase");
  }
}
