class_name Quest extends Object


enum Status{
	OPEN,
	TAKEN,
	IN_PROGRESS,
	COMPLETED,
	FAILED,
	CLOSED
}

class Event:
	enum Type{
		WAIT,
		COMBAT,
		CHOICE
	}
	var type : Type = Type.WAIT
	var enemies : Array[String] = []
	var time : float = 1
	var time_elapsed
	signal completed()
	
	func process(delta : float) -> void:
		#TODO: Make quest combat work
		time_elapsed += delta
		if time_elapsed >= time:
			completed.emit()

var name : String = "A Basic Quest"
var desc : String = "The default quest, with no special anything."
var difficulty : int = 1
var location : String
var steps : int = 1
var rewards : Dictionary
var length : float = 10
var events : Array[Event] = []


var progress : float = 0
var current_step : int = 0
var taken : bool = false
var status : Status = Status.OPEN

var questor : AdventurerData = null
signal status_changed(status : Status)

func _init() -> void:
	pass

func initiate(member : AdventurerData) -> void:
	questor = member
	status = Status.TAKEN
	status_changed.emit(Status.TAKEN)

func fail() -> void:
	status = Status.FAILED
	status_changed.emit(Status.FAILED)

func complete() -> void:
	status = Status.COMPLETED
	status_changed.emit(Status.COMPLETED)
	for reward in rewards.keys():
		if reward == "gold":
			questor.gain_gold(rewards[reward])
		elif reward == "exp":
			questor.gain_exp(rewards[reward])
		#TODO: Implement other reward types
		#elif rewards[reward] is Item:
		#	questor.gain_item()
		#else it's a guild item they'll bring back for us
	Game.notice("%s completed the quest '%s'!" % [questor.full_name(), name])

func num_events() -> int:
	return len(events)
#TODO: Put in quest requirements
func is_eligible(member : AdventurerData) -> bool:
	return !taken

func is_taken() -> bool:
	return status == Status.TAKEN



func difficulty_name() -> String:
	match(difficulty):
		0: return "None"
		1: return "Trivial"
		2: return "Moderate"
		3: return "Severe"
		4: return "Extreme"
		5: return "Legendary"
		_: return "Unknown"
