extends CharacterBody3D


const _SPEED = 5.0

@export var components: Components
@export var _npc_data: Script


func _physics_process(delta: float) -> void:
	if not is_on_floor():
		velocity += get_gravity() * delta
	
	var dir := Vector2.ZERO
	var direction := (transform.basis * Vector3(dir.x, 0, dir.y)).normalized()
	if direction:
		velocity.x = direction.x * _SPEED
		velocity.z = direction.z * _SPEED
	else:
		velocity.x = move_toward(velocity.x, 0, _SPEED)
		velocity.z = move_toward(velocity.z, 0, _SPEED)
	
	move_and_slide()


func _on_c_interactable_interacted(_source: Node) -> void:
	get_parent().start_trade(_npc_data)
