from toee import *


def san_dialog( attachee, triggerer ):
	game.new_sid = 0
	return SKIP_DEFAULT


def san_enter_combat( attachee, triggerer ):
	return RUN_DEFAULT


def san_start_combat( attachee, triggerer ):
	## THIS IS USED FOR BREAK FREE
	for obj in game.party[0].group_list():
		if (obj.distance_to(attachee) <= 3 and obj.stat_level_get(stat_hp_current) >= -9):
			return RUN_DEFAULT		
	while(attachee.item_find(8903) != OBJ_HANDLE_NULL):
		attachee.item_find(8903).destroy()
	if (attachee.d20_query(Q_Is_BreakFree_Possible)):
		create_item_in_inventory( 8903, attachee )
##		attachee.d20_send_signal(S_BreakFree)

	return RUN_DEFAULT


def san_heartbeat( attachee, triggerer ):
	return RUN_DEFAULT


def san_will_kos( attachee, triggerer ):
	if (game.global_flags[840] == 1 and attachee.map == 5065):
		return SKIP_DEFAULT
	if attachee.map == 5091:
		return SKIP_DEFAULT
	return RUN_DEFAULT


def buff_npc( attachee, triggerer ):
	for obj in game.obj_list_vicinity(attachee.location,OLC_NPC):
		if (obj.name == 14424 and obj.leader_get() == OBJ_HANDLE_NULL):
			obj.turn_towards(attachee)
			obj.cast_spell(spell_mage_armor, obj)
		if (obj.name == 14425 and obj.leader_get() == OBJ_HANDLE_NULL):
			obj.turn_towards(attachee)
			obj.cast_spell(spell_shield_of_faith, obj)
	return RUN_DEFAULT

def buff_npc_two( attachee, triggerer ):
	for obj in game.obj_list_vicinity(attachee.location,OLC_NPC):
		if (obj.name == 14424 and obj.leader_get() == OBJ_HANDLE_NULL):
			obj.cast_spell(spell_mirror_image, obj)
		if (obj.name == 14425 and obj.leader_get() == OBJ_HANDLE_NULL):
			obj.cast_spell(spell_owls_wisdom, obj)
	return RUN_DEFAULT

def buff_npc_three( attachee, triggerer ):
	for obj in game.obj_list_vicinity(attachee.location,OLC_NPC):
		if (obj.name == 14424 and obj.leader_get() == OBJ_HANDLE_NULL):
			obj.cast_spell(spell_protection_from_arrows, obj)
		if (obj.name == 14425 and obj.leader_get() == OBJ_HANDLE_NULL):
			obj.cast_spell(spell_endure_elements, obj)
	return RUN_DEFAULT





