local D = {}

function D.show (index)

	DialogManager.CurrentDialogIndex = index

	if index == 1 then
		if gVarStore.getBool("provisioner_extra_reward") == false then
			DialogManager.showDialog({key = "greet_text_1", options = {{key = "continue", id = ConstEndDialog}}})
		else
			DialogManager.showDialog({key = "greet_text_2", options = {{key = "continue", id = ConstEndDialog}}})
		end
	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 == 1 then
			if gVarStore.getBool("provisioner_extra_reward") == false then
				gParty.increaseTreasure(500)
				gGUI.showInfoMessage({text = DialogManager.translate("gift_text"), middle = true})
				gVarStore.setBool("provisioner_extra_reward", true)
			end
		end

		DialogManager.endCurrentDialogTree()
		return
	end

	D.show(DialogManager.CurrentDialogIndex + 1)
end

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

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

end

-- Register globally
DialogManager.Dialogs["provisioner"].DialogTrees["greet"] = D
