using Godot;
using Newlon.Components.Level;

namespace Newlon.Components.Plants;

// Shoot component of some plants
public partial class Shooter : Node2D
{
    [Export] protected PackedScene _projectile;
    [Export] protected Timer _timer;

    protected RuntimePlantData _plantData;

    public override void _Ready()
    {
        _plantData = GetParent<RuntimePlantData>();
    }


    public void Shoot()
    {
        if (_timer.TimeLeft > 0) return;

        _timer.Start();
        SpawnProjectile();
    }

    public virtual void SpawnProjectile()
    {
        var instance = _projectile.Instantiate<Node2D>();
        PoolContainer.Instance.Projectiles.AddChild(instance);
        instance.GlobalTransform = GlobalTransform;
    }
}
