class_name QuestSprite extends Control

var life : int = 1
var max_life : int = 1
var energy : int = 1
var max_energy : int = 1
var level : int = 1
var exp : int = 0

@export var stats : StatBlock
var gold : int = 0


@onready var anim_player : AnimationPlayer = $AnimationPlayer
signal died(killer :QuestSprite)
signal action_complete(requeue : bool)
signal busy()


func attack(target : QuestSprite) -> void:
	print("Attack by %s to %s" % [name, target.name])
	target.take_damage(self, 10)
	action_complete.emit(true)

func take_damage(source : QuestSprite, amount : int) -> void:
	busy.emit()
	life = clampi(life - amount, 0, max_life)
	if life == 0:
		print("%s killed %s!" % [source.name, name])
		die(source)
	else:
		print("%s hit %s for %d damage!" % [source.name, name, amount])
		action_complete.emit(false)
		

func die(killer : QuestSprite) -> void:
	died.emit(killer)
	queue_free()
