from toee import *

def san_first_heartbeat(attachee, triggerer):
	if (attachee.map == 5114):
		if (game.quests[53].state > 0):
			attachee.object_flag_set(OF_OFF)
	
	return RUN_DEFAULT

def san_heartbeat(attachee, triggerer):
	if (attachee.map == 5114):
		if (attachee.name == 14746):
			melay = 0
			for obj in game.party[0].group_list():
				if (obj.distance_to(attachee) <= 15):
					melay = melay + 1
			if (melay >= 1):
				remove_long_bow(attachee)
			else:
				restore_long_bow(attachee)
		if (attachee.name == 14750):
			melay = 0
			for obj in game.party[0].group_list():
				if (obj.distance_to(attachee) <= 15):
					melay = melay + 1
			if (melay >= 1):
				remove_long_bow(attachee)
			else:
				restore_long_bow(attachee)
	
	else:
		if (attachee.map == 5138) and (attachee.name == 14467):
			melay = 0
			for obj in game.party[0].group_list():
				if (obj.distance_to(attachee) <= 9):
					melay = melay + 1
			if (melay >= 1):
				remove_short_bow(attachee)
			else:
				restore_short_bow(attachee)
	return RUN_DEFAULT

def san_dying(attachee, triggerer):
	if (attachee.map == 5114):
		if (attachee.name == 14743):#Orc Shaman
			game.global_vars[56] = game.global_vars[56] + 1
		if (attachee.name == 14748):#Orc Shaman
			game.global_vars[56] = game.global_vars[56] + 1
		if (attachee.name == 14744):#Orc Leader
			game.global_vars[56] = game.global_vars[56] + 1
		if (attachee.name == 14747):#Half-Orc Assassin
			game.global_vars[56] = game.global_vars[56] + 1
		if (attachee.name == 14751):#Half-Orc Assassin
			game.global_vars[56] = game.global_vars[56] + 1
		if (attachee.name == 14746):#Orc Archer
			restore_long_bow(attachee)
		if (attachee.name == 14750):#Orc Archer
			restore_long_bow(attachee)

	else:
		if (attachee.map == 5138) and (attachee.name == 14467):
			restore_short_bow(attachee)
	
	return RUN_DEFAULT

def remove_long_bow(attachee):
	long_bow = attachee.item_find_by_proto(4087)
	while long_bow != OBJ_HANDLE_NULL:
		long_bow.destroy()
		attachee.item_wield_best_all()
		long_bow = attachee.item_find_by_proto(4087)
	return

def restore_long_bow(attachee):
	long_bow = attachee.item_find_by_proto(4087)
	while long_bow == OBJ_HANDLE_NULL:
		create_item_in_inventory( 4087, attachee )
		attachee.item_wield_best_all()
		long_bow = attachee.item_find_by_proto(4087)
	return

def remove_short_bow(attachee):
	short_bow = attachee.item_find_by_proto(4201)
	while short_bow != OBJ_HANDLE_NULL:
		short_bow.destroy()
		attachee.item_wield_best_all()
		short_bow = attachee.item_find_by_proto(4201)
	
	return

def restore_short_bow(attachee):
	short_bow = attachee.item_find_by_proto(4201)
	while short_bow == OBJ_HANDLE_NULL:
		create_item_in_inventory( 4201, attachee )
		attachee.item_wield_best_all()
		short_bow = attachee.item_find_by_proto(4201)
	
	return
