from toee import *

def san_dialog( attachee, triggerer ):
	if (not attachee.has_met( triggerer )):
		triggerer.begin_dialog( attachee, 1 )
	else:
		triggerer.begin_dialog( attachee, 280 )
	return SKIP_DEFAULT

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

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

def san_enter_combat( attachee, triggerer ):
	game.global_flags[346] = 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[715] = 0
	return RUN_DEFAULT

def san_heartbeat( attachee, triggerer ):
	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[104] == 1) or (game.global_flags[105] == 1) or (game.global_flags[107] == 1) ):
						obj.turn_towards(attachee)	## added by Livonya
						attachee.turn_towards(obj)	## added by Livonya
						obj.begin_dialog( attachee, 460 )
					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[715] == 0 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[715] == 4 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[715] = game.global_vars[715] + 1
	return RUN_DEFAULT

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