class_name AdventurerData extends Node

class StatBlock:
	var STR : int = 1
	var DEX : int = 1
	var INT : int = 1
	var CHA : int = 1
	var FAI : int = 1
	var LUK : int = 1

enum Gender{
	MASC,
	FEMME,
	NONBINARY
}

var given_name : String = "Test"
var surname : String = "Testing"
var gender : Gender = Gender.MASC
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
var job : JobData
var stats : StatBlock
var gold : int = 0
var quest : Quest
var inventory : Dictionary[Vector2, Item] = {}

func _init() -> void:
	stats = StatBlock.new()

func generate() -> void:
	if job == null:
		return
	stats.STR = randi_range(job.min_STR, job.max_STR)
	stats.DEX = randi_range(job.min_DEX, job.max_DEX)
	stats.INT = randi_range(job.min_INT, job.max_INT)
	stats.CHA = randi_range(job.min_CHA, job.max_CHA)
	stats.FAI = randi_range(job.min_FAI, job.max_FAI)
	stats.LUK = randi_range(job.min_LUK, job.max_LUK)
	
	max_life = stats.STR * 10 + stats.CHA * 10
	max_energy = stats.INT * 10 + stats.FAI * 10
	life = max_life
	energy = max_energy

func assign_quest(quest : Quest) -> void:
	self.quest = quest
	quest.initiate(self)

func full_name() -> String:
	return given_name + " " + surname

func gain_level() -> void:
	level += 1
	#TODO: Make stats improve based on job
	Game.notice("%s has reached level %d!" % [full_name(), level])

func gain_exp(amount : int) -> void:
	exp += amount
	while exp >= get_tnl():
		exp -= get_tnl()
		gain_level()

func gain_gold(amount :int) -> void:
	gold += amount

func get_tnl() -> int:
	if job:
		return job.get_tnl(level)
	else:
		return level * 10
