using Godot;

namespace Cirno.Scripts.Components.Actors;

public partial class ActorDefeatScriptHandler : ActorModule
{
    [Export] public Node2D DefeatScript { get; private set; }
    [Export] public ActivationType ActivationType { get; private set; }
    protected Actor _actor;
    
    public override void Init(Actor actor)
    {
        _actor = actor;
        DefeatScript = actor.DefeatScript;
        ActivationType = actor.ActivationType;
        _actor.OnDeath += ActorOnOnDeath;
    }

    private void ActorOnOnDeath()
    {
        ActivateDefeatScript();
    }

    public override void Update(double delta)
    {
        
    }

    public override void PhysicsUpdate(double delta)
    {
        
    }
    
    protected void ActivateDefeatScript()
    {
        if (DefeatScript is not IActivable target)
        {
            return;
        }
        
        target?.Activate();
    }
}