from toee import *
from utilities import *
import _include
from co8Util.TimedEvent import *


def san_new_map( attachee, triggerer ):
	if ((attachee.area == 1) or (attachee.area == 3)):
		obj = attachee.leader_get()
		if (obj != OBJ_HANDLE_NULL):
			obj.begin_dialog(attachee, 140)
	return RUN_DEFAULT

def san_dialog( attachee, triggerer ):
	if (attachee.leader_get() != OBJ_HANDLE_NULL):
		triggerer.begin_dialog( attachee, 100 )
	elif (not attachee.has_met(triggerer)):
		triggerer.begin_dialog( attachee, 1 )
	else:
		triggerer.begin_dialog( attachee, 90 )
	return SKIP_DEFAULT

def san_dying( attachee, triggerer ):
	if (attachee.leader_get() != OBJ_HANDLE_NULL):
		game.global_vars[29] = game.global_vars[29] + 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[731] = 0
	return RUN_DEFAULT


def run_off( attachee, triggerer ):
	attachee.runoff(attachee.location-3)
	timedEventAdd(give_reward, (), 336)
	return RUN_DEFAULT
	

def give_reward():
	game.encounter_queue.append(3003)
	return RUN_DEFAULT


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