extends Node

var xp: float = 0:
	set(value):
		xp = value
		xp_changed.emit(xp)

var money: float = 500:
	set(value):
		money = value
		money_changed.emit(money)

var level: int = 0:
	set(value):
		level = value
		level_changed.emit(level)

var max_order_amount: int = 5:
	set(value):
		max_order_amount = value
		max_order_amount_changed.emit(max_order_amount)

var sell_multiplier: float = 0.5

var jobs: Array[JobData]

# Signal - player stats
signal xp_changed(new_xp)
signal money_changed(new_money)
signal level_changed(new_level)
signal max_order_amount_changed(new_max_order_amount)

# Signal - functions
signal give_experience(xp_amount)
signal give_money(money_amount)

func _ready() -> void:
	give_experience.connect(_on_give_experience)
	give_money.connect(_on_give_money)

func _on_give_experience(amount: float) -> void:
	print('Gave: %.0f xp' % amount)
	xp += amount
	if xp >= 100:
		while xp >= 100:
			level += 1
			xp -= 100

func _on_give_money(amount: float) -> void:
	money += amount

func try_purchase(amount) -> bool:
	if amount <= money:
		money -= amount
		return true
	else:
		return false
