// .txt

beginzonescript;

variables;

short im_hostile = 0;
short max_crime = 3;
short last_abil;
short counter = 0;

body;

beginstate INIT_STATE;
	last_abil = get_current_tick();

	set_combat_activity(15777,1);
	set_combat_activity(15778,1);
	set_combat_activity(15779,1);
	set_summon_level(15777,1);
	set_summon_level(15778,1);
	set_summon_level(15779,1);
	
	set_name(15780,"Sergeant K'Naan");
	set_name(15781,"Avernite Soldier");
	set_name(15782,"Avernite Soldier");
	set_name(15783,"Avernite Soldier");
	set_name(15784,"Depot Guard");
	set_name(15785,"Depot Guard");
	set_name(15786,"Depot Guard");
	set_name(15787,"Depot Guard");
	set_name(15788,"Lieutenant Katlyn");
	set_name(15789,"Depot Scribe");

	add_range_to_group(15790,15797,19);
	set_name(30019,"Petitioner");
	set_combat_activity(30019,1);
	
	set_name(15798,"Penn");
	set_name(15799,"Belyna");
	set_name(15800,"Nephil Guard");
	if (gf(146,10) > 4) {
		erase_char(15798);
		erase_char(15799);
		}
		else erase_char(15800);

	add_range_to_group(15805,15809,20);
	set_aggression(30020,60);

	add_range_to_group(15810,15814,21);
	set_aggression(30021,75);

	add_range_to_group(15815,15819,22);
	set_aggression(30022,75);
	set_boss_level(15819,1);
	set_name(15819,"Goblin Raider");
	set_level(15817,1);
	set_level(15818,1);
	
	add_range_to_group(15835,15838,23);
	set_aggression(30023,25);
	
	set_name(15839,"Dominica");
	set_name(15840,"Or'Vysss");
	set_name(15841,"Caravan Guard");
	set_name(15842,"Caravan Guard");

	add_range_to_group(15843,15844,24);
		
	//add_range_to_group(15805,,groupn);

	sf(146,22,1);
	
	set_crime_tolerance(max_crime);

	set_obj_act_at_dist(26442,1);
	set_obj_act_at_dist(26316,1);

	if (gf(146,7) > 0) { // reset beggars
		sf(146,16,4);
		sf(146,17,3);
		}
	break;

beginstate EXIT_STATE;

break;

beginstate START_STATE;
	// item hint stage
	if ((gf(146,1) > 0) && (gf(146,4) == 0))
		assert_hint(0);
	if ((gf(146,4) == 0) && ( (party_has_item_equip(62)) || (party_has_item_equip(90))) )
		begin_talk_mode(11);
	
	// rats done
	if ((gf(146,11) >= 8) && (gf(146,11) < 30)) {
		sf(146,11,30);
		//assert_hint(1);
		begin_talk_mode(49);
		}
	//if (gf(146,11) == 30)
	//	assert_hint(1);
	
	// goblin agte
	if ((on_which_layer() == 1) && (gf(146,9) == 0) && (gf(146,22) > 0) && ((party_within_dist(398,677,9)) || (party_within_dist(389,696,23)))) {
		sf(146,22,0);
		sf(146,9,1);
		begin_talk_mode(15);
		}
	
	
	// erase losers upstairs
	if ((on_which_layer() == 1) && (char_ok(15801)))
		erase_char(15801);
	if ((on_which_layer() == 1) && (char_ok(15802)))
		erase_char(15802);
	if ((on_which_layer() == 1) && (char_ok(15803)))
		erase_char(15803);

	if ((get_crime_level() >= max_crime) && (im_hostile == 0)) {
		make_zone_hostile(); 
		im_hostile = 1;
		//erase_char(30000);
		begin_talk_mode(299);
		}

	if (gf(146,10) < 7) {
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(15768,"You have orders.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(15768,"You have work to do.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(15768,"Always so slow!");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(15768,"Get moving!");
		}
		else {
			if (get_ran(1,0,100) < 10)
				give_char_text_bubble(15768,"You'd best be going.");
			if (get_ran(1,0,100) < 10)
				give_char_text_bubble(15768,"Sigh.");
			if (get_ran(1,0,100) < 10)
				give_char_text_bubble(15768,"I tried to protect you.");
			}
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15777 + get_ran(1,0,2),"Tik. Tik.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15777 + get_ran(1,0,2),"Bzzzzt.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15777 + get_ran(1,0,2),"Grind. Grind.");

	if (gf(170,0) == 0) {
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(15780,"Hmrrr.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(15780,"What is it, private?");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(15780,"Back to your basement.");
		}
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15784 + get_ran(1,0,3),"Stay back.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15784 + get_ran(1,0,3),"Wait your turn.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15784 + get_ran(1,0,3),"Be patient.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15788,"I'm listening.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15788,"Speak quickly.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15788,"Denied. Next!");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15788,"Supplies are limited.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15788,"Who is next?");
	if (get_ran(1,0,100) < 7)
		give_char_text_bubble(15789,"Skritch.");
	if (get_ran(1,0,100) < 7)
		give_char_text_bubble(15789,"Skritch. Skritch.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15790 + get_ran(1,0,7),"Help us!");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15790 + get_ran(1,0,7),"What takes so long?");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15790 + get_ran(1,0,7),"We need bread!");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15790 + get_ran(1,0,7),"Quit shoving.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15790 + get_ran(1,0,7),"We will be heard!");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15790 + get_ran(1,0,7),"Is it my turn?");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15839,"Will you hurry?");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15839,"Better get the lizards.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15839,"We're all loaded.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15840,"Hssss.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15840,"Come and buy.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15840,"Discountsss for you.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15843 + get_ran(1,0,1),"Hssss.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(15843 + get_ran(1,0,1),"Ssssss!");

		
	if (((is_combat()) && (tick_difference(last_abil,get_current_tick()) > 0)) || ((is_group()) && (tick_difference(last_abil,get_current_tick()) > 5))) {
		last_abil = get_current_tick();

		if ((gf(146,14) > 0) && (gf(146,14) < 30)) {
			inc_flag(146,14,1);
			if (gf(146,14) == 3) {
				print_str_color("You hear more rats emerge from the shadows.",2);
				spawn_creature(15773);
				spawn_creature(15774);
				spawn_creature(15775);
				set_name(15773,"Huge Rat");
				change_max_health(15773,10);
				set_name(15774,"Huge Rat");
				change_max_health(15774,10);
				set_name(15775,"Huge Rat");
				change_max_health(15775,10);
				}
			if (gf(146,14) == 5) {
				spawn_creature(15776);
				set_name(15776,"Diseased Rat");
				set_level(15776,2);
				change_max_health(15776,30);
				set_coloradj(15776,512);
				begin_talk_mode(48);
				}
			}
		
		if (char_ok(15768)) {
			if ((dist_to_nav_point(15768,0) <= 6) && (get_ran(1,0,6) == 0) && (char_ok(15804) == FALSE)) {
				spawn_creature(15804);
				set_summon_level(15804,1);
				if (party_dist_to_spot(413,662) <= 6)
					print_str_color("A rat climbs up out of the chasm.",2);
				}
			}
		}
break;

beginstate 10;
	set_terrain_string_range("The sign says - Private's Quarters.",1);
break;

beginstate 11;
	set_terrain_string_range("The sign says - Deep Storage. Keep Out!",1);
break;

beginstate 12;
	set_terrain_string_range("The sign says - PETITION HALL. Stay in line. Do not speak until called upon! Disobedience will be dealt with harshly.",1);
break;

beginstate 13;
break;

beginstate 20;
	if (is_combat() == FALSE)
		print_str_color("You climb the stairs.",2);
	change_level(427,660,2);
break;

beginstate 21;
	if (is_combat() == FALSE)
		print_str_color("You climb the stairs.",2);
	change_level(428,661,6);
break;

beginstate 22;
		if (revive_party()) {
			print_str_color("Entering or leaving the depot heals your wounds",2);
			print_str_color("  and restores your spell energy.",2);
			}
break;

//	print_str("");
//	set_terrain_string_range(".",1);
//	set_terrain_string_range("The sign says - .",1);
