extends Area3D

@export var weapon_spawner: MultiplayerSpawner
@export var weapon_system: WeaponSystem

func _ready() -> void:
	if is_multiplayer_authority() == false: return
	
	body_entered.connect(on_body_entered)

func on_body_entered(body: Node3D):
	if body is DroppableWeapon:
		if weapon_system.can_add(body.slot) == false or (body.team != Session.TEAMS.UNASSIGNED and get_parent().team != body.team):
			return
		weapon_spawner.spawn({
			"ammo": body.weapon.ammo,
			"remaining_ammo": body.weapon.remaining_ammo,
			"scene_file_path": body.weapon.scene_file_path,
			"slot": body.slot
		})
		
		Session.despawn(body.get_path())

func start_temp_ignore():
	if is_multiplayer_authority() == false:
		return
	monitoring = false
	get_tree().create_timer(0.5).timeout.connect(stop_temp_ignore)

func stop_temp_ignore():
	if is_multiplayer_authority() == false:
		return
	monitoring = true
