using Godot;

namespace Newlon.Components.Plants.Behaviours;

public partial class PotatomineBehaviour : BaseBehaviour
{
	[Export] private Area2D _hitbox;
	[Export] private Area2D detectionBox;
	[Export] private CollisionShape2D _unprimedShape;
	[Export] private CollisionShape2D _primedShape;
	private bool _primed = false;
	public void Prime()
	{
		_tree.Set("parameters/Tree/conditions/primed", true);

		_hitbox.Monitorable = false;

		_primed = true;
		_unprimedShape.Disabled = true;
		_primedShape.Disabled = false;

		if (detectionBox.HasOverlappingAreas())
		{
			SetupExplosion();
		}
	}

	public void OnAreaEntered(Area2D area)
	{
		if (_primed == false) return;
		SetupExplosion();
	}
	private void SetupExplosion()
	{
		_tree.Set("parameters/Tree/conditions/explode", true);
		_primed = false;
	}
}
