##########################
##########################
##########################
##########################
##########################
#                        #
#Spell 138 quest 50 mobów#
#                        #
##########################
##########################
##########################
##########################
##########################
# Start location.
start = (31938, 32293, 12)


# Ignore mobs when quest is finished and character can go to the next quest/npc.
# Default: 1 (enabled)
quest_end_ignore_mobs = 1


# Write the same amount as in "HUNT UNTIL".
stamina_low = '1:00'


# Waypoints sets
to_d_base = 0
to_bernard = 1
to_saurial = 2
saurial = 3
to_bernard_done = 4


# Npcs Caste Mino
bernard = (31959, 32277, 11)


# Saurial
saurial_spot_base = (32101, 32333, 12)
saurial_spot_back = (32104, 32335, 12)
saurial_spot_continue = (31942, 32295, 12)
saurial_spot_exit = (32082, 32328, 12)  //*nie wiadomo czy to jest ważne **\\


# Hours
import datetime
from System import DateTime
stamina_empty = '00:00'
stamina_full = '56:00'


def onScriptActivation():
	script.ShowMessage('Powodzenia ze spellem!')
	script.StatusMessage('Start script spell_139_q50')
	script.IgnoreMonsters(0)
	script.SetVar('day', 0)
	script.SetVar('monster_quest', 0)
	script.SetVar('exit_hunt', 0)
	script.SetVar('message_count', 0)
	script.SetVar('message_back', 0)
	script.SetVar('message_hunt', 0)
	script.SetVar('message_finish', 0)
	script.SetVar('stam_low', 0)
	script.PZChecksForDrop(0)
	script.EnableTickEvent(500)
	script.SetVar('saurial_done', 0)
   	script.SetVar('saurial_back', 0)
	script.SetVar('saurial_continue', 0)
	
	
def onScriptDeactivation():
	script.IgnoreMonsters(0)
	script.StatusMessage('Stop script spell_139_q50')


def onQuestFinish():
	script.SetVar('exit_hunt', 0)
	script.SetVar('message_count', 0)
	script.SetVar('message_back', 0)
	script.SetVar('message_hunt', 0)
	script.SetVar('message_finish', 0)
	script.SetVar('saurial_done', 0)
   	script.SetVar('saurial_back', 0)	
	script.SetVar('saurial_continue', 0)	
	

def onDisconnect(info):
	way = script.GetWay()
	x = script.GetX()
	y = script.GetY()
	z = script.GetZ()
	
	
def onChangeLocation(x, y, z):
	way = script.GetWay()

# 1 Bernard
	elif way == to_bernard and x == bernard[0] and y == bernard[1] and z == bernard[2]:
		if script.GoToNpcEx('Bernard'):
			script.StatusMessage('Hello Bernard')
		else:
			script.StatusMessage('I can\'t find Bernard')
			script.Alarm('I can\'t find Bernard')
	elif way == to_bernard_done and x == bernard[0] and y == bernard[1] and z == bernard[2]:
		if script.GoToNpcEx('Bernard'):
			script.StatusMessage('Hello Bernard')
		else:
			script.StatusMessage('I can\'t find Bernard')
			script.Alarm('I can\'t find Bernard')
			
# 2 Bernard
	elif way == to_bernard and x == bernard[0] and y == bernard[1] and z == bernard[2]:
		if script.GoToNpcEx('Bernard'):
			script.StatusMessage('Hello Bernard')
		else:
			script.StatusMessage('I can\'t find Bernard')
			script.Alarm('I can\'t find Bernard')
	elif way == to_bernard_done and x == bernard[0] and y == bernard[1] and z == bernard[2]:
		if script.GoToNpcEx('Bernard'):
			script.StatusMessage('Hello Bernard')
		else:
			script.StatusMessage('I can\'t find Bernard')
			script.Alarm('I can\'t find Bernard')
			
# 3 Bernard
	elif way == to_bernard and x == bernard[0] and y == bernard[1] and z == bernard[2]:
		if script.GoToNpcEx('Bernard'):
			script.StatusMessage('Hello Bernard')
		else:
			script.StatusMessage('I can\'t find Bernard')
			script.Alarm('I can\'t find Bernard')
	elif way == to_bernard_done and x == bernard[0] and y == bernard[1] and z == bernard[2]:
		if script.GoToNpcEx('Bernard'):
			script.StatusMessage('Hello Bernard')
		else:
			script.StatusMessage('I can\'t find Bernard')
			script.Alarm('I can\'t find Bernard')


# 1 Saurial
	elif x == saurial_spot_base[0] and y == saurial_spot_base[1] and z == saurial_spot_base[2]:
		if script.GetVar('saurial_done') == 1:
			script.SetWay(to_saurial_done, 2)
	elif x == saurial_spot_back[0] and y == saurial_spot_back[1] and z == saurial_spot_back[2]:
		script.SetVar('saurial_back', 1)
		script.SetVar('saurial_continue', 0)
	elif way == saurial and script.GetVar('saurial_back') == 1 and script.GetVar('saurial_continue') == 0 and script.GetVar('saurial_done') == 1:
		script.SetWay(saurial, 1)
		script.SetVar('saurial_back', 0)
		script.SetVar('saurial_continue', 0)
	elif x == saurial_spot_continue[0] and y == saurial_spot_continue[1] and z == saurial_spot_continue[2]:
		script.SetVar('saurial_back', 0)
		script.SetVar('saurial_continue', 1)
	elif way == saurial and script.GetVar('saurial_back') == 0 and script.GetVar('saurial_continue') == 1 and script.GetVar('saurial_done') == 1:
		script.SetWay(saurial, 2)
		script.SetVar('saurial_back', 0)
		script.SetVar('saurial_continue', 0)

# 2 Saurial
	elif x == saurial_spot_base[0] and y == saurial_spot_base[1] and z == saurial_spot_base[2]:
		if script.GetVar('saurial_done') == 1:
			script.SetWay(to_saurial_done, 2)
	elif x == saurial_spot_back[0] and y == saurial_spot_back[1] and z == saurial_spot_back[2]:
		script.SetVar('saurial_back', 1)
		script.SetVar('saurial_continue', 0)
	elif way == saurial and script.GetVar('saurial_back') == 1 and script.GetVar('saurial_continue') == 0 and script.GetVar('saurial_done') == 1:
		script.SetWay(saurial, 1)
		script.SetVar('saurial_back', 0)
		script.SetVar('saurial_continue', 0)
	elif x == saurial_spot_continue[0] and y == saurial_spot_continue[1] and z == saurial_spot_continue[2]:
		script.SetVar('saurial_back', 0)
		script.SetVar('saurial_continue', 1)
	elif way == saurial and script.GetVar('saurial_back') == 0 and script.GetVar('saurial_continue') == 1 and script.GetVar('saurial_done') == 1:
		script.SetWay(saurial, 2)
		script.SetVar('saurial_back', 0)
		script.SetVar('saurial_continue', 0)
			
# 3 Saurial
	elif x == saurial_spot_base[0] and y == saurial_spot_base[1] and z == saurial_spot_base[2]:
		if script.GetVar('saurial_done') == 1:
			script.SetWay(to_saurial_done, 2)
	elif x == saurial_spot_back[0] and y == saurial_spot_back[1] and z == saurial_spot_back[2]:
		script.SetVar('saurial_back', 1)
		script.SetVar('saurial_continue', 0)
	elif way == saurial and script.GetVar('saurial_back') == 1 and script.GetVar('saurial_continue') == 0 and script.GetVar('saurial_done') == 1:
		script.SetWay(saurial, 1)
		script.SetVar('saurial_back', 0)
		script.SetVar('saurial_continue', 0)
	elif x == saurial_spot_continue[0] and y == saurial_spot_continue[1] and z == saurial_spot_continue[2]:
		script.SetVar('saurial_back', 0)
		script.SetVar('saurial_continue', 1)
	elif way == saurial and script.GetVar('saurial_back') == 0 and script.GetVar('saurial_continue') == 1 and script.GetVar('saurial_done') == 1:
		script.SetWay(saurial, 2)
		script.SetVar('saurial_back', 0)
		script.SetVar('saurial_continue', 0)

# Ignore mobs
	elif way == to_d_base or way == to_bernard or way == to_bernard_done:
		script.IgnoreMonsters(1)

def onWaypointsEnded():
	way = script.GetWay()
	x = script.GetX()
	y = script.GetY()
	z = script.GetZ()

# 1 Saurial
	if way == to_saurial and x == saurial_spot_base[0] and y == saurial_spot_base[1] and z == saurial_spot_base[2]:
		script.SetWay(saurial, 2)
		script.StatusMessage('Hunt Saurial')
		
# 2 Saurial
	if way == to_saurial and x == saurial_spot_base[0] and y == saurial_spot_base[1] and z == saurial_spot_base[2]:
		script.SetWay(saurial, 2)
		script.StatusMessage('Hunt Saurial')

# 3 Saurial
	if way == to_saurial and x == saurial_spot_base[0] and y == saurial_spot_base[1] and z == saurial_spot_base[2]:
		script.SetWay(saurial, 2)
		script.StatusMessage('Hunt Saurial')		

# Finish tasks
	elif way == to_d_base and x == to_bernard_done[0] and y == to_bernard_done[1] and z == to_bernard_done[2]:
		if script.GetVar('message_finish') == 0:
			script.StatusMessage('All tasks have been completed')
			script.SetVar('message_finish', 1)
			


def onReceiveNpcText(name, text, page):
	way = script.GetWay()

# 1 Bernard
	elif name == 'Bernard':
		if 'Welcome back. So much of these' in text:
			if way == to_bernard:
				script.StatusMessage('Bernard task taken')
				script.ChooseNpcOption(1)
				script.IgnoreMonsters(0)
		elif 'Then comb the caves' in text or 'You are not finished yet' in text:
			if way == to_bernard:
				script.SetWay(to_saurial, 2)
				script.ForgetNpc()
		elif 'Welcome back. I still have some stuff to prepare. Please come back later' in text:
			if way == to_bernard:
				script.SetWay(to_bernard, 2)
				script.StatusMessage('You must wait a bit to do the task again')
				script.ForgetNpc()
				script.LogoutFor(20)				
			elif way == to_bernard_done:
				script.StatusMessage('Bernard task completed')
				script.SetWay(to_bernard, 2)
				script.SetVar('monster_quest', 0)
				script.ForgetNpc()				
		elif 'Great, you did it' in text:
			if way == to_bernard_done:
				script.StatusMessage('Bernard task completed')
				script.SetWay(to_bernard, 2)
				script.SetVar('monster_quest', 0)
				script.ForgetNpc()
			elif way == to_bernard:
				script.GoToNpcEx('Bernard')			


# 2 Bernard
	elif name == 'Bernard':
		if 'Welcome back. So much of these' in text:
			if way == to_bernard:
				script.StatusMessage('Bernard task taken')
				script.ChooseNpcOption(1)
				script.IgnoreMonsters(0)
		elif 'Then comb the caves' in text or 'You are not finished yet' in text:
			if way == to_bernard:
				script.SetWay(to_saurial, 2)
				script.ForgetNpc()
		elif 'Welcome back. I still have some stuff to prepare. Please come back later' in text:
			if way == to_bernard:
				script.SetWay(to_bernard, 2)
				script.StatusMessage('You must wait a bit to do the task again')
				script.ForgetNpc()
				script.LogoutFor(20)				
			elif way == to_bernard_done:
				script.StatusMessage('Bernard task completed')
				script.SetWay(to_bernard, 2)
				script.SetVar('monster_quest', 0)
				script.ForgetNpc()				
		elif 'Great, you did it' in text:
			if way == to_bernard_done:
				script.StatusMessage('Bernard task completed')
				script.SetWay(to_bernard, 2)
				script.SetVar('monster_quest', 0)
				script.ForgetNpc()
			elif way == to_bernard:
				script.GoToNpcEx('Bernard')
				

# 3 Bernard
	elif name == 'Bernard':
		if 'Welcome back. So much of these' in text:
			if way == to_bernard:
				script.StatusMessage('Bernard task taken')
				script.ChooseNpcOption(1)
				script.IgnoreMonsters(0)
		elif 'Then comb the caves' in text or 'You are not finished yet' in text:
			if way == to_bernard:
				script.SetWay(to_saurial, 2)
				script.ForgetNpc()
		elif 'Welcome back. I still have some stuff to prepare. Please come back later' in text:
			if way == to_bernard:
				script.SetWay(to_bernard, 2)
				script.StatusMessage('You must wait a bit to do the task again')
				script.ForgetNpc()
				script.LogoutFor(20)				
			elif way == to_bernard_done:
				script.StatusMessage('Bernard task completed')
				script.SetWay(to_bernard, 2)
				script.SetVar('monster_quest', 0)
				script.ForgetNpc()				
		elif 'Great, you did it' in text:
			if way == to_bernard_done:
				script.StatusMessage('Bernard task completed')
				script.SetWay(to_bernard, 2)
				script.SetVar('monster_quest', 0)
				script.ForgetNpc()
			elif way == to_bernard:
				script.GoToNpcEx('Bernard')				



def onReachedNpc(uid, name):
	if not script.TalkToNpc(uid):
		script.StatusMessage('Can\'t talk to ' + name + '!')

def onTalkedWithNpc(uid, result):
	if not result:
		if not script.TalkToNpc(uid):
			script.StatusMessage('Can\'t talk to ' + name + '!')

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



# Saurials killed
	if name == 'Saurial' and mobs == 1:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 2:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)	
	elif name == 'Saurial' and mobs == 3:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 4:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)	
	elif name == 'Saurial' and mobs == 5:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 6:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)	
	elif name == 'Saurial' and mobs == 7:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 8:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)	
	elif name == 'Saurial' and mobs == 9:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 10:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)	
	elif name == 'Saurial' and mobs == 11:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 12:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)	
	elif name == 'Saurial' and mobs == 13:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 14:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 15:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 16:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)	
	elif name == 'Saurial' and mobs == 17:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 18:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)	
	elif name == 'Saurial' and mobs == 19:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 20:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 21:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 22:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 23:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 24:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 25:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 26:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 27:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 28:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 29:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 30:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 31:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 32:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 33:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 34:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 35:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 36:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 37:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 38:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 39:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 40:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 41:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 42:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 43:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 44:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 45:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 46:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 47:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 48:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 49:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Saurial' and mobs == 50:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)




def onReceiveQuestLogUpdate(text):
# Spell Mino Castle
	if 'Saurial population at bay. I agreed to kill 50 of these' in text:
		script.SetVar('saurial_done', 0)	

	elif 'I killed the 500 Gorogns for Crimson' in text:
		script.SetVar('saurial_done', 1)
		script.IgnoreMonsters(1)
		if script.GetVar('monster_quest') == 0:
			script.SetVar('monster_quest', 1)
			script.StatusMessage('I killed 50 gorgons. I'll go take the reward')		