# need change to your coordinates, if you change hunt place
hunt_area = (32719, 32200, 8)

# waypoints
hunt_place = 0
to_doratia = 1
to_buya = 2
from_buya_to_city = 3
to_planima = 4
from_planima_to_city = 5
to_falkon = 6
from_falkon_to_city = 7
forgotten_hunt = 8
zealot_hunt = 9
to_observer = 10
observer_hunt = 11
from_observer_to_city = 12
to_hunt_place = 13

# NPC
buya = (32418, 32034, 10)
planima = (32460, 31987, 8)
falkon = (32434, 31981, 8)

# Waypoint change spots
city = (32433, 32032, 10) # city portal
observer = (32396, 31975, 9) # Observers

# null var for 3 quests
def onScriptActivation():
	# 0 - none, 1 - have, 2 - finished
	script.SetVar('q_buya', 0)
	script.SetVar('q_planima', 0)
	script.SetVar('q_falkon', 0)

def onChangeLocation(x, y, z):
	# time when the quest will be available again
	time = script.GetRegVar(str(script.GetTabId()) + '_falkon_time') # as last taken quest, for 100% 24h end Buya and Planima
	way = script.GetWay() # which waypoint list is currently in use
	# if we hunt and it's time to do the quest
	if x == hunt_area[0] and y == hunt_area[1] and z == hunt_area[2]:
		if way == hunt_place and time <= script.GetCurrentTime():
			return
			script.StatusMessage('Going to Doratia.')
			script.SetWay(to_doratia, 2)
		elif way == to_hunt_place:
			script.StatusMessage('We Come to Hunt Place.')
			script.SetWay(hunt_place, 2)
	# center of Doratia. So many conditions... @(o_O)@
	elif x == city[0] and y == city[1] and z == city[2]:
		# if we come here from hunt place, we need talk with Buya. Or, if we finished kill 50 Observers, we need no talk with Buya too - Rewards.
		if way == to_doratia or way == from_observer_to_city:
			script.StatusMessage('Going to Buya.')
			script.SetWay(to_buya, 2)
		# if we come here from Buya, we need go talk with Planima. For start quest, and for finish too.
		elif way == from_buya_to_city:
			script.StatusMessage('Going to Planima.')
			script.SetWay(to_planima, 2)
		# if we come here from Planima, we need go talk with Fal Kon. For start quest, and for finish too.
		elif way == from_planima_to_city:
			script.StatusMessage('Going to Fal Kon.')
			script.SetWay(to_falkon, 2)
		# if we come here from Fal Kon, we need go kill forgotten. Or to come to hunt place.
		elif way == from_falkon_to_city:
			if script.GetVar('q_buya') == 1:
				script.StatusMessage('Going to hunt Forgotten.')
				script.SetWay(forgotten_hunt, 2)
			else:
				script.StatusMessage('Going to hunt place.')
				script.SetWay(to_hunt_place, 2)
				script.SetVar('q_buya', 0)
				script.SetVar('q_planima', 0)
				script.SetVar('q_falkon', 0)
		# if quest forgotten is done, we need change our waypoints to zealot hunt.
		elif way == forgotten_hunt:
			if script.GetVar('q_buya') == 2 and script.GetVar('q_planima') == 1:
				script.StatusMessage('Going to Zealot.')
				script.SetWay(zealot_hunt, 2)
		# same as forgotten
		elif way == zealot_hunt:
			if script.GetVar('q_planima') == 2 and script.GetVar('q_falkon') == 1:
				script.StatusMessage('Going to Observer.')
				script.SetWay(to_observer, 2)
	elif x == observer[0] and y == observer[1] and z == observer[2]:
		# if we come to observer, start hunt! else if quest finished, come to city
		if way == to_observer:
			script.SetWay(observer_hunt, 2)
		elif script.GetVar('q_falkon') == 2:
			script.SetWay(from_observer_to_city, 2)
	# if we come to Buya
	elif way == to_buya and x == buya[0] and y == buya[1] and z == buya[2]:
		if script.GoToNpc('Buya', 2):
			script.StatusMessage('Going to Buya.')
		else:
			script.StatusMessage('Can\'t find Buya.')
			script.Alarm('Can\'t find Buya.')
	# if we come to Planima
	elif way == to_planima and x == planima[0] and y == planima[1] and z == planima[2]:
		if script.GoToNpc('Planima', 3):
			script.StatusMessage('Going to Planima.')
		else:
			script.StatusMessage('Can\'t find Planima.')
			script.Alarm('Can\'t find Planima.')
	# if we come to Fal Kon
	elif way == to_falkon and x == falkon[0] and y == falkon[1] and z == falkon[2]:
		if script.GoToNpc('Fal Kon', 2):
			script.StatusMessage('Going to Fal Kon.')
		else:
			script.StatusMessage('Can\'t find Fal Kon.')
			script.Alarm('Can\'t find Fal Kon.')

def onReceiveNpcText(name, text, page):
	if name == 'Buya':
		# if quest is not taken
		if text.find('Are you ready to kill') != -1:
			script.StatusMessage('Starting Quest Buya.')
			# Yes
			script.ChooseNpcOption(1)
		# if taken now or early
		elif text.find('Then go down there and do') != -1 or text.find('didn\'t kill enough forgotten') != -1:
			script.StatusMessage('Taken.')
			script.SetVar('q_buya', 1)
			next_t = script.GetCurrentTime() + 86400
			script.SetRegVar(str(script.GetTabId()) + '+_buya_time', next_t) # next quest after 24h
			# and fast run to Planima XD
			script.SetWay(from_buya_to_city, 2)
			script.ForgetNpc()
		# if 24h
		elif text.find('Come back later') != -1:
			script.StatusMessage('Come back after 24h.')
			script.SetVar('q_buya', 0) # quest = none
			next_t = script.GetCurrentTime() + 86400
			script.SetRegVar(str(script.GetTabId()) + '_buya_time', next_t) # return after 24h
			script.SetWay(from_buya_to_city, 2)
			script.ForgetNpc()
		elif text.find('Here, take your reward') != -1:
			script.SetWay(from_buya_to_city, 2)
			script.ForgetNpc()
	elif name == 'Planima':
		# if quest is not taken
		if text.find('Are you ready to kill') != -1:
			script.StatusMessage('Starting Quest Planima.')
			# Yes
			script.ChooseNpcOption(1)
		elif text.find('Then go out there and do') != -1 or text.find('didn\'t kill enough zealots') != -1:
			script.StatusMessage('Taken.')
			script.SetVar('q_planima', 1)
			next_t = script.GetCurrentTime() + 86400
			script.SetRegVar(str(script.GetTabId()) + '_planima_time', next_t) # next quest after 24h
			# fast run to Fal Kon
			script.SetWay(from_planima_to_city, 2)
			script.ForgetNpc()
		elif text.find('Come back later') != -1:
			script.StatusMessage('Come back after 24h.')
			script.SetVar('q_planima', 0) # quest = none
			next_t = script.GetCurrentTime() + 86400
			script.SetRegVar(str(script.GetTabId()) + '_planima_time', next_t) # next quest after 24h
			script.SetWay(from_planima_to_city, 2)
			script.ForgetNpc()
		elif text.find('Here, take your reward') != -1:
			script.SetWay(from_planima_to_city, 2)
			script.ForgetNpc()
	elif name == 'Fal Kon':
		# if quest is not taken
		if text.find('Are you ready to kill') != -1:
			script.StatusMessage('Starting Quest Fal Kon.')
			# Yes
			script.ChooseNpcOption(1)
		elif text.find('you to roam the surface and the tunnels') != -1 or text.find('didn\'t kill enough observers') != -1:
			script.StatusMessage('Taken.')
			script.SetVar('q_falkon', 1)
			next_t = script.GetCurrentTime() + 86400
			script.SetRegVar(str(script.GetTabId()) + '_falkon_time', next_t) # next quest after 24h
			# run to forgotten
			script.SetWay(from_falkon_to_city, 2)
			script.ForgetNpc()
		elif text.find('Come back later') != -1:
			script.StatusMessage('Come back after 24h.')
			script.SetVar('q_falkon', 0) # none
			next_t = script.GetCurrentTime() + 86400
			script.SetRegVar(str(script.GetTabId()) + '_falkon_time', next_t) # next quest after 24h
			script.SetWay(from_falkon_to_city, 2)
			script.ForgetNpc()
		elif text.find('Here, take your reward') != -1:
			script.SetWay(from_falkon_to_city, 2)
			script.ForgetNpc()
	# Done

def onReceiveQuestLogUpdate(text):
	if text.find('I killed 50 forgotten spirits.') != -1:
		script.SetVar('q_buya', 2) # finished
	if text.find('I disposed of 50 zealots.') != -1:
		script.SetVar('q_planima', 2) # finished
	if text.find('I killed the promised 50 Observers.') != -1:
		script.SetVar('q_falkon', 2) # finished

def onKilledEnemy(name, templateId):
	varname = 'killed_' + name
	mobs = script.GetVar(varname) + 1
	script.SetVar(varname, mobs)
	txt = str(mobs)
	script.StatusMessage('Killed: ' + name + ' \nTotal: ' + txt)
