extends CharacterBody3D

class_name Player

@export var team: Session.TEAMS
@export var weapon_models: Dictionary[StringName,Node3D]
@export var player_id: int = 1:
	set(id):
		player_id = id
		$PlayerInput.set_multiplayer_authority(id)
		$Camera3D.set_multiplayer_authority(id)

var passived: bool = false

signal health_changed(to: int)
signal died

const MAX_HP = 100

@export var hp: int = 100:
	set(value):
		if value < 0:
			hp = 0
		else:
			hp = value
		health_changed.emit(hp)
		if hp == 0:
			die()
		
	get:
		return hp

func _physics_process(_delta: float) -> void:
	if not multiplayer.is_server():
		return
	
	move_and_slide()

func die() -> void:
	if (not multiplayer.is_server()):
		return
	Session.add_dead(team)
	died.emit()
	passived = true

func passive() -> void:
	passived = true

func depassive() -> void:
	passived = false

func take_damage(damage: int):
	hp -= damage
