using Cirno.Scripts.Components.FSM.Player;
using Godot;

namespace Cirno.Scripts.Actors;

public partial class Ice : Area2D
{
    public double Life { get; set; } = 2f;
    //public float FreezeRange { get; private set; } = 16f;
    
    public FreezeModule FreezeModule { get; set; }

    public override void _PhysicsProcess(double delta)
    {
        Life -= delta;

        if (Life <= 0)
        {
            QueueFree();
        }

    }

    private void OnAreaEntered(Area2D area)
    {
        if (area is not Bullet bullet) return;
        if (bullet.IsFrozen) return;
        if (bullet.BulletOwner is BulletOwner.Player) return;
        if (!bullet.BulletInfo.Freezable) return;
        
        bullet.Freeze();
        var ice = bullet.CreateSibling<Ice>(FreezeModule.IceScene);
        ice.Life = Life;
        ice.FreezeModule = FreezeModule;
    }
}