A Godot v4 game about working in an office
extends Node
class_name BattleEnemy

signal died(battler)
signal health_changed(old, new)
signal health_depleted
signal turn_ended

@onready var actions = $Actions

@export var max_health := 50

var health: int
var is_alive: bool:
	get:
		return health > 0

#	{
#		health: 50,
#		max_health: 50,
#	},
func initialize(data):
	max_health = data.max_health
	health = data.health
	$EnemyBars.initialize()

func start_turn():
	await get_tree().create_timer(0.5).timeout
	get_parent().show_dialog(["Enemy stares blankly..."])
	await get_parent().dialog_box.dialog_hidden
	turn_ended.emit()

func reset():
	health = self.max_health

func take_damage(amount: int):
	var old_health = health
	health -= amount
	health = max(0, health)
	health_changed.emit(old_health, health)
	if health == 0:
		health_depleted.emit()

func heal(amount: int):
	var old_health = health
	health = min(health + amount, max_health)
	health_changed.emit(old_health, health)