using Godot;
using System.Collections;
using System.Collections.Generic;
using Godot.Collections;

namespace Rokojori
{
  [GlobalClass,Tool]
  public partial class Shooter:Action
  {
    [Export]
    public Node pigContainer;

    [Export]
    public float startChance = 10;

    [Export]
    public float endChance = 80;

    [Export]
    public float duration = 60;

    [Export]
    public Node3D bulletsContainer;

    protected override void _OnTrigger()
    {
      var random = GodotRandom.Get();
      var edr = Unique<EatDaRichGame>.Get();

      var chance = MathX.MapClamped( edr.secondsPlaying, 0, duration, startChance, endChance );
      
      if ( ! random.Chance( chance ) )
      {
        return;
      }

      var pigContainers = pigContainer.GetDirectChildren<Node>();
      var selected = GodotRandom.Get().From( pigContainers );

      if ( selected == null )
      {
        return;
      }

      var pig = selected.Get<Pig>();

      pig.Shoot( bulletsContainer );

    }

  }
}