from toee import *

def san_dialog( attachee, triggerer ):
	if (game.global_flags[132] == 1):
		attachee.attack(triggerer)
	elif (not attachee.has_met( triggerer )):
		triggerer.begin_dialog( attachee, 1 )
	else:
		triggerer.begin_dialog( attachee, 370 )
	return SKIP_DEFAULT

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

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

def san_enter_combat( attachee, triggerer ):
	game.global_flags[345] = 0
	if (not attachee.has_wielded(4071) or not attachee.has_wielded(4124)):
		attachee.item_wield_best_all()
	for statue in game.obj_list_vicinity( attachee.location, OLC_SCENERY ):
		if (statue.name == 1618):
			loc = statue.location
			rot = statue.rotation
			statue.destroy()
			for obj in game.obj_list_vicinity( attachee.location, OLC_NPC ):
				if obj.name == 14244:
					return RUN_DEFAULT					
			juggernaut = game.obj_create( 14244, loc )
			juggernaut.rotation = rot
			game.particles( "ef-MinoCloud", juggernaut )
			return RUN_DEFAULT
	return RUN_DEFAULT

def san_will_kos( attachee, triggerer ):
	if (game.global_flags[132] == 0):
		return SKIP_DEFAULT
	else:
		return RUN_DEFAULT

def san_first_heartbeat( attachee, triggerer ):
	if (attachee.leader_get() == OBJ_HANDLE_NULL):
		game.global_vars[714] = 0
	return RUN_DEFAULT

def san_heartbeat( attachee, triggerer ):
#	if (game.global_vars[714] == 8 and not attachee.has_wielded(4071) or not attachee.has_wielded(4124)):
#		attachee.item_wield_best_all()
#		attachee.item_wield_best_all()
	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[106] == 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, 600 )
					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[714] == 0 and attachee.leader_get() == OBJ_HANDLE_NULL and not game.combat_is_active()):
#		attachee.cast_spell(spell_fog_cloud, attachee)
#		attachee.cast_spell(spell_shield_of_faith, attachee)
#		attachee.spells_pending_to_memorized()
#	if (game.global_vars[714] == 4 and attachee.leader_get() == OBJ_HANDLE_NULL and not game.combat_is_active()):
#		attachee.cast_spell(spell_owls_wisdom, attachee)
#		attachee.spells_pending_to_memorized()
#	game.global_vars[714] = game.global_vars[714] + 1

	return RUN_DEFAULT