extends CharacterBody3D

class_name Interactible

signal interacted(with: int)
signal stopped_interacting(with: int)

var interacted_id: int = -1

func _ready() -> void:
	if not multiplayer.is_server():
		return
	Session.player_stopped_interacting.connect(player_stopped_interacting)

func interaction_start(player_id: int):
	if not multiplayer.is_server():
		return
	interacted.emit(player_id)
	
	interacted_id = player_id

func player_stopped_interacting(id: int):
	if interacted_id == id:
		interaction_end()

func interaction_end():
	if not multiplayer.is_server():
		return
	stopped_interacting.emit(interacted_id)
	interacted_id = -1
