local D = {}

function D.show (index)

	DialogManager.CurrentDialogIndex = index

	if DialogManager.CurrentDialogIndex == 0 then
		DialogManager.showDialog({key = "ask_travel_1", options = {{key = "travel_reply_1"}}})

	elseif DialogManager.CurrentDialogIndex == 1 then
		DialogManager.showDialog({key = "ask_travel_2", options = {{key = "continue", id = ConstEndDialog}}})

	elseif DialogManager.CurrentDialogIndex == 2 then
		DialogManager.showDialog({key = "ask_travel_3", options = {{key = "continue", id = ConstEndDialog}}})
	end
end

-- Called when choosing an reply option from the list
function D.dismiss (index, identifier)

	-- Reply that indicates to end the dialog tree
	if identifier == ConstEndDialog then
		if DialogManager.CurrentDialogIndex == 2 then
			gVarStore.setBool("travel_available", true)
		end
		DialogManager.endCurrentDialogTree()
		return
	end

	D.show(DialogManager.CurrentDialogIndex + 1)

end

-- Called when dialog tree is initialized
function D.started ()

	if gVarStore.getInt("ales_bought") == 2 then
		D.show(2)
	else
		D.show(0)
	end
end

-- Called when dialog tree is terminated
function D.ended()

end

-- Register globally
DialogManager.Dialogs["harbormaster2"].DialogTrees["ask_travel"] = D
