using Godot;

namespace Cirno.Scripts.Resources.Events;

[GlobalClass]
public partial class ControlActorEvent : EventResource
{
    [Export]
    public NodePath Target { get; set; }
    
    private Node2D _parent;
    
    private GameManager _gameManager;
    private bool _isComplete = false;
    public override bool IsComplete()
    {
        return _isComplete;
    }
    
    public override void Init(Node2D parent)
    {
        _gameManager = parent.GetGameManager();
        _parent = parent;
    }
    
    public override void Start(Node2D parentNode)
    {
        _isComplete = false;

        if (_parent.GetNode<Node2D>(Target) is Actor enemy)
        {
            if (GameManager.Instance.ToggleControlMode() is GameState.Controlling)
            {
                enemy.AssumeControl();
            }
        }

        _isComplete = true;
    }
    
    public override void UpdateEvent(double delta) { }
}