class_name Item extends Node3D
## Base class for item pick-ups in the world.

signal on_collect(player: WorldPlayer)

## Quantity of the underlying item this pick-up will grant when collected.
## What this actually means is implementation-dependent.
@export var amount: int = 1

@onready var explosion_player: AnimationPlayer = %ExplosionPlayer


func collect(player: WorldPlayer) -> void:
	# Note that this animation will call `queue_free` in 5 seconds!
	explosion_player.play("explode")
	_collect(player)
	on_collect.emit(player)


func _collect(_player: WorldPlayer) -> void:
	pass  # Defined in derived type


func _on_collection_area_body_entered(body: Node3D) -> void:
	if body is GameBall:
		var ball: GameBall = body
		if ball.player:
			collect(ball.player)
