from toee import *
from utilities import *

def san_dialog( attachee, triggerer ):
	if ( game.global_vars[2] >= 100 and triggerer.reputation_has( 3 ) == 0 ):
		triggerer.reputation_add( 3 )
	triggerer.begin_dialog( attachee, 1 )
	return SKIP_DEFAULT



def san_enter_combat( attachee, triggerer ):
	if (not attachee.has_wielded(4047) or not attachee.has_wielded(4111)):
		attachee.item_wield_best_all()
	return RUN_DEFAULT

def san_start_combat( attachee, triggerer ):
	if (not attachee.has_wielded(4047) or not attachee.has_wielded(4111)):
		attachee.item_wield_best_all()
	return RUN_DEFAULT

def san_dying( attachee, triggerer ):
	game.global_flags[337] = 1
	game.global_vars[23] = game.global_vars[23] + 1
	if (game.global_vars[23] >= 2):
		game.party[0].reputation_add( 1 )
	return RUN_DEFAULT

def san_first_heartbeat( attachee, triggerer ):
#	if (attachee.leader_get() == OBJ_HANDLE_NULL and not game.combat_is_active()):
#		game.global_vars[722] = 0
#	if (game.quests[101].state == qs_accepted and find_npc_near(attachee, 14501) == OBJ_HANDLE_NULL):
#		amii = game.obj_create( 14501, location_from_axis (490L, 471L) )
#	if (game.quests[101].state == qs_botched and find_npc_near(attachee, 14501) != OBJ_HANDLE_NULL):
#		amii = find_npc_near(attachee, 14501)
#		amii.destroy()
	return RUN_DEFAULT

def san_heartbeat( attachee, triggerer ):
#	if (game.global_flags[875] == 1 and game.global_flags[876] == 0 and game.quests[101].state != qs_completed and not anyone( triggerer.group_list(), "has_item", 12900 )):
#		game.global_flags[876] = 1
#		game.timevent_add( amii_dies, (), 140000000 )
#	game.global_vars[722] = game.global_vars[722] + 1
	if (game.combat_is_active()):
		return RUN_DEFAULT
#	if (game.global_vars[722] == 1):
#		attachee.cast_spell(spell_stoneskin, attachee)
#		attachee.spells_pending_to_memorized()	
#	if (game.global_vars[722] >= 5 and (not attachee.has_wielded(4047) or not attachee.has_wielded(4111))):
#		attachee.item_wield_best_all()
#		attachee.item_wield_best_all()
#	if (not attachee.has_spell_effects()):
#		game.global_vars[722] = 0

	return RUN_DEFAULT

def amii_dies():
#	game.quests[101].state = qs_botched
	return RUN_DEFAULT

# Function: should_clear_spell_on( obj )
# Author  : Livonya
# Returns : 0 if obj is dead, else 1
# Purpose : to fix only characters that need it

def should_clear_spell_on( obj ):
	if (obj.stat_level_get(stat_hp_current) <= -10):
		return 0
	return 1

def kill_picked( obj ):
	damage_dice = dice_new( '100d20' )
	obj.damage( OBJ_HANDLE_NULL, 0, damage_dice )
	return RUN_DEFAULT

def run_off(npc, pc):
	game.quests[101].state = qs_completed
	for obj in game.obj_list_vicinity(npc.location,OLC_NPC):
		if (obj.name == 14501):
			obj.runoff(obj.location+3)
	return RUN_DEFAULT


