from toee import *

def san_dialog( attachee, triggerer ):
	if (game.global_flags[144] == 1):
		attachee.attack(triggerer)
	elif (not attachee.has_met(triggerer)):
		if (anyone(triggerer.group_list(),"has_wielded",3010) or anyone(triggerer.group_list(),"has_wielded",3016) or anyone(triggerer.group_list(),"has_wielded",3017) or anyone(triggerer.group_list(),"has_wielded",3020)):
			triggerer.begin_dialog( attachee, 130 )
		else:
			triggerer.begin_dialog( attachee, 1 )
	elif (game.global_flags[163] == 1):
		triggerer.begin_dialog( attachee, 220 )
	elif (game.global_flags[157] == 1):
		if ((game.global_flags[146] == 1) and (game.global_flags[147] == 1) and (game.global_flags[153] == 0) and (game.global_flags[156] == 0)):
			triggerer.begin_dialog( attachee, 140 )
		else:
			triggerer.begin_dialog( attachee, 150 )
	elif (game.global_flags[162] == 1):
		triggerer.begin_dialog( attachee, 160 )
	elif (game.global_flags[158] == 1):
		triggerer.begin_dialog( attachee, 190 )
	elif (anyone(triggerer.group_list(),"has_wielded",3010) or anyone(triggerer.group_list(),"has_wielded",3016) or anyone(triggerer.group_list(),"has_wielded",3017) or anyone(triggerer.group_list(),"has_wielded",3020)):	
		triggerer.begin_dialog( attachee, 130 )	
	else:
		triggerer.begin_dialog( attachee, 210 )	
	return SKIP_DEFAULT

def san_enter_combat( attachee, triggerer ):
	itemA = attachee.item_find(8008)
	if (itemA != OBJ_HANDLE_NULL):
		itemA.destroy()
	itemA = attachee.item_find(8007)
	if (itemA != OBJ_HANDLE_NULL):
		itemA.destroy()
	itemA = attachee.item_find(8007)
	if (itemA != OBJ_HANDLE_NULL):
		itemA.destroy()
	itemA = attachee.item_find(8014)
	if (itemA != OBJ_HANDLE_NULL):
		itemA.destroy()
	return RUN_DEFAULT

def san_dying( attachee, triggerer ):
	create_item_in_inventory( 8007, attachee )
	create_item_in_inventory( 8007, attachee )
	create_item_in_inventory( 8008, attachee )
	create_item_in_inventory( 8014, attachee )
	return RUN_DEFAULT

def san_will_kos( attachee, triggerer ):
	if (triggerer.type == obj_t_pc):
		if (game.global_flags[144] == 1):
			return RUN_DEFAULT
	return SKIP_DEFAULT

def san_first_heartbeat( attachee, triggerer ):
#	if (attachee.leader_get() == OBJ_HANDLE_NULL and not game.combat_is_active()):
#		game.global_vars[725] = 0
	return RUN_DEFAULT

def san_heartbeat( attachee, triggerer ):
	if (not game.combat_is_active()):
		if (game.global_flags[144] == 0):
			for obj in game.obj_list_vicinity(attachee.location,OLC_PC):
				if (not attachee.has_met(obj)):
					if (is_safe_to_talk(attachee,obj)):
						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[725] == 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[725] == 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[725] == 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[725] = game.global_vars[725] + 1
	return RUN_DEFAULT


def banter( attachee, triggerer, line):
	npc = find_npc_near(attachee,8036)
	if (npc != OBJ_HANDLE_NULL):
		triggerer.begin_dialog(npc,line)
		npc.turn_towards(attachee)
		attachee.turn_towards(npc)
	else:
		triggerer.begin_dialog(attachee,70)
	return SKIP_DEFAULT


def banter2( attachee, triggerer, line):
	npc = find_npc_near(attachee,8036)
	if (npc != OBJ_HANDLE_NULL):
		triggerer.begin_dialog(npc,line)
		npc.turn_towards(attachee)
		attachee.turn_towards(npc)
	else:
		triggerer.begin_dialog(attachee,80)
	return SKIP_DEFAULT


