from toee import *

def san_dialog( attachee, triggerer ):
	attachee.turn_towards(triggerer)
	if (game.global_flags[144] == 1):
		attachee.attack(triggerer)
	elif (not attachee.has_met(triggerer)):
		triggerer.begin_dialog( attachee, 1 )
	elif (game.global_flags[165] == 1):
		triggerer.begin_dialog( attachee, 150 )
	else:
		triggerer.begin_dialog( attachee, 260 )
	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[728] = 0
	return RUN_DEFAULT

def san_dying( attachee, triggerer ):
	create_item_in_inventory ( 8009, attachee )
	create_item_in_inventory ( 8009, attachee )
	return RUN_DEFAULT

def san_heartbeat( attachee, triggerer ):
	if (attachee.item_find(6020) != OBJ_HANDLE_NULL):
		attachee.item_find(6020).destroy()
		create_item_in_inventory ( 6202, attachee )
		attachee.item_wield_best_all()
	if (attachee.item_find(6019) != OBJ_HANDLE_NULL):
		attachee.item_find(6019).destroy()
		create_item_in_inventory ( 6032, attachee )
		create_item_in_inventory ( 4179, attachee )
		attachee.item_wield_best_all()
	if (attachee.item_find(6074) != OBJ_HANDLE_NULL):
		attachee.item_find(6074).destroy()
		create_item_in_inventory ( 6081, attachee )
		attachee.item_wield_best_all()
	while (attachee.item_find(8009) != OBJ_HANDLE_NULL):
		attachee.item_find(8009).destroy()
#	if (game.global_vars[728] == 0 and attachee.leader_get() == OBJ_HANDLE_NULL and not game.combat_is_active()):
#		attachee.cast_spell(spell_mage_armor, attachee)
#		attachee.spells_pending_to_memorized()
#	if (game.global_vars[728] == 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[728] = game.global_vars[728] + 1
	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 banter( attachee, triggerer, line):
	npc = find_npc_near(attachee,8035)
	if (npc != OBJ_HANDLE_NULL):
		triggerer.begin_dialog(npc,line)
		npc.turn_towards(attachee)
		attachee.turn_towards(npc)
	else:
		triggerer.begin_dialog(attachee,90)
	return SKIP_DEFAULT


def banter2( attachee, triggerer, line):
	npc = find_npc_near(attachee,8035)
	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
