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

namespace Rokojori
{
  [GlobalClass,Tool]
  public partial class Eat:Action
  {
    [Export]
    public OnCollision onCollision;

    [Export]
    public Action onAteSomething;

    [Export]
    public Pointer pointer;

    protected override void _OnTrigger()
    {
      var pigs = onCollision.GetNodesInside();  

      var hasEaten = false;

      pigs.ForEach(
        ( p )=>
        {
          var eatable = p.Get<Eatable>();

          this.LogInfo( eatable );

          if ( eatable == null ) 
          {
            
            return;
          }
          
          Trigger( eatable.onGotEaten ); 

          hasEaten = true;
          
        }

      );

      if ( hasEaten )
      {
        Trigger( onAteSomething );
      }

      this.LogInfo( pigs );
    }
  }
}