from toee import *

def san_dialog( attachee, triggerer ):
	triggerer.turn_towards(attachee)			## added by Livonya
	attachee.turn_towards(triggerer)			## added by Livonya
	if ( anyone(triggerer.group_list(),"has_follower",8031) ):
			triggerer.begin_dialog( attachee, 700 )
	elif ( (game.global_flags[115] == 1) and (game.global_flags[116] == 1) and (game.global_flags[125] == 0) ):
			triggerer.begin_dialog( attachee, 400 )
	elif (not attachee.has_met(triggerer)):
		if (game.global_flags[92] == 1):
			triggerer.begin_dialog( attachee, 200 )
		else:
			triggerer.begin_dialog( attachee, 1 )
	else:
		triggerer.begin_dialog( attachee, 300 )

def san_dying( attachee, triggerer ):
	game.global_flags[107] = 1
	return RUN_DEFAULT

def san_resurrect( attachee, triggerer ):
	game.global_flags[107] = 0
	return RUN_DEFAULT

def san_enter_combat( attachee, triggerer ):
	game.global_flags[344] = 0
	return RUN_DEFAULT

def san_first_heartbeat( attachee, triggerer ):
#	if (attachee.leader_get() == OBJ_HANDLE_NULL and not game.combat_is_active()):
#		game.global_vars[713] = 0
	if (game.global_flags[312] == 1):
		attachee.object_flag_set(OF_OFF)
		game.global_flags[107] = 1
	return RUN_DEFAULT

def san_heartbeat( attachee, triggerer ):
#	if (attachee.map == 5067 and game.global_flags[872] == 0):
#		chest = game.obj_create( 1012, location_from_axis (409L, 498L))
#		chest.rotation = 4
#		create_item_in_inventory( 6311, chest )
#		create_item_in_inventory( 6197, chest )
#		create_item_in_inventory( 6186, chest )
#		create_item_in_inventory( 12037, chest )
#		game.global_flags[872] = 1
	if (not game.combat_is_active()):
		for obj in game.obj_list_vicinity(attachee.location,OLC_PC):
			if (not attachee.has_met(obj)):
				if (is_safe_to_talk(attachee,obj)):
					if (game.global_flags[92] == 1):
						obj.turn_towards(attachee)	## added by Livonya
						attachee.turn_towards(obj)	## added by Livonya
						obj.begin_dialog( attachee, 200 )
					elif ( (game.global_flags[104] == 1) or (game.global_flags[105] == 1) or (game.global_flags[106] == 1) ):
						obj.turn_towards(attachee)	## added by Livonya
						attachee.turn_towards(obj)	## added by Livonya
						obj.begin_dialog( attachee, 730 )
					else:
						obj.turn_towards(attachee)	## added by Livonya
						attachee.turn_towards(obj)	## added by Livonya
						obj.begin_dialog(attachee,1)
#						game.new_sid = 0			## removed by Livonya
#	if (game.global_vars[713] == 0 and attachee.leader_get() == OBJ_HANDLE_NULL and not game.combat_is_active()):
#		attachee.cast_spell(spell_resist_elements, attachee)
#		attachee.spells_pending_to_memorized()
#	if (game.global_vars[713] == 4 and attachee.leader_get() == OBJ_HANDLE_NULL and not game.combat_is_active()):
#		attachee.cast_spell(spell_protection_from_elements, attachee)
#		attachee.spells_pending_to_memorized()
#	if (game.global_vars[713] == 8 and attachee.leader_get() == OBJ_HANDLE_NULL and not game.combat_is_active()):
#		attachee.cast_spell(spell_shield_of_faith, attachee)
#		attachee.spells_pending_to_memorized()
#	game.global_vars[713] = game.global_vars[713] + 1
	return RUN_DEFAULT

def escort_below( attachee, triggerer ):
	# game.global_flags[144] = 1
	game.global_vars[691] = 3
	game.fade_and_teleport(0,0,0,5080,478,451)
	return RUN_DEFAULT
