class_name HealthComponent extends Node

signal defeat()
signal health_changed()

@export var body: PhysicsBody3D

var max_health: float
var current_health: float:
	set(value):
		current_health = max(value, 0.0)
		if current_health == 0.0:
			defeat.emit()
		health_changed.emit()

func update_max_health(max_hp_in: float) -> void:
	max_health = max_hp_in
	current_health = max_health

func take_damage(damage_in: float, is_critical: bool) -> void:
	var damage = damage_in
	if is_critical:
		damage *= 2.0
	current_health -= damage
	VFXManager.spawn_damage_number(damage, body.global_position, is_critical)

func get_health_string() -> String:
	return "%s/%s" % [current_health, max_health]
