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


def san_dialog( attachee, triggerer ):
	if (attachee.leader_get() != OBJ_HANDLE_NULL):
		triggerer.begin_dialog( attachee, 120 )
	else:
		triggerer.begin_dialog( attachee, 1 )
	return SKIP_DEFAULT


def san_dying( attachee, triggerer ):
	game.global_flags[150] = 1
	if (attachee.leader_get() != OBJ_HANDLE_NULL):
		game.global_vars[29] = game.global_vars[29] + 1
	return RUN_DEFAULT

def san_resurrect( attachee, triggerer ):
	game.global_flags[150] = 0
	return RUN_DEFAULT

def san_new_map( attachee, triggerer ):
	if ((attachee.map == 5062) or (attachee.map == 5093) or (attachee.map == 5113) or (attachee.map == 5001)):
		leader = attachee.leader_get()
		if (leader != OBJ_HANDLE_NULL):
			leader.begin_dialog( attachee, 130 )
	return RUN_DEFAULT

def run_off( attachee, triggerer ):
	game.global_flags[151] = 1
	attachee.runoff(attachee.location-3)
	return RUN_DEFAULT

def check_follower_thrommel_comments( attachee, triggerer ):
	npc = find_npc_near( attachee, 8014)
	if (npc != OBJ_HANDLE_NULL):
		triggerer.begin_dialog( npc, 490 )
	else:
		npc = find_npc_near( attachee, 8000)
		if (npc != OBJ_HANDLE_NULL):
			triggerer.begin_dialog( npc, 550 )
		else:
			triggerer.begin_dialog( attachee, 10 )
	return RUN_DEFAULT

def schedule_reward( attachee, triggerer ):
	game.global_flags[152] = 1
	attachee.object_flag_set(OF_OFF)
	timedEventAdd(give_reward, (), 336)
	return RUN_DEFAULT
	

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