// .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_name(6267,"Mayor Annatolia");
	set_level(6267,20);
	if ((gf(58,1) > 0) && (gf(58,9) == 0))
		sf(58,2,1);
	if (gf(58,2) > 0) {
		erase_char(6267);
		erase_char(6306);
		}
		
	if ((gf(58,8) > 0) && (gf(58,13) == 0))
		spawn_creature(6268);
	set_name(6268,"Herwin");
	set_name(6272,"Pitmaster Ghrum");
	set_name(6273,"Gall");
	set_name(6274,"McGoff");
	set_name(6275,"Mother Twymon");
	set_name(6276,"Commander Diver");
	set_name(6277,"Tizane");
	set_name(6278,"Bysss-Tss");

	set_name(6281,"Ogre Honor Guard");
	set_name(6282,"Ogre Honor Guard");
	set_name(6283,"Ogre Honor Guard");
	set_level(6281,30);
	set_level(6282,30);
	set_level(6283,30);
	set_boss_level(6281,2);
	set_boss_level(6282,2);
	set_boss_level(6283,2);

	set_level(6283,30);

	set_name(6306,"Spire Honor Guard");
	
	set_name(6285,"Spire Guard");
	set_name(6286,"Spire Guard");
	set_name(6287,"Spire Guard");
	set_name(6288,"Spire Guard");
	
	set_name(6303,"Conscripted Worker");
	set_name(6302,"Conscripted Worker");
	set_name(6304,"Conscripted Worker");

	add_range_to_group(6279,6280,31);
	add_range_to_group(6284,6289,31);
	set_level(30031,25);
	set_boss_level(30031,1);
	
	set_crime_tolerance(max_crime);

	sf(58,28,0);
	break;

beginstate EXIT_STATE;

break;

beginstate START_STATE;
	if (gf(57,22) > 0)
		sf(58,13,2); // herwin
	
	// attackers

	if ((on_which_layer() == 0) && (gf(57,28) < 50) && (gf(58,9) > 0)) {
		if (party_within_dist(159,280,25)) {
			if (party_dist_to_spot(131,279) > 12) {
				if (char_ok(6331) == FALSE) {
					spawn_creature(6331);
					set_name(6331,"Spire Defender");
					set_boss_level(6331,1);
					inc_flag(57,28,1);
					}
					else alert_char(6331);
				if (char_ok(6332) == FALSE) {
					spawn_creature(6332);
					set_name(6332,"Spire Defender");
					set_boss_level(6332,1);
					inc_flag(57,28,1);
					}
					else alert_char(6332);
				
				if (char_ok(6333) == FALSE) {
					spawn_creature(6333);
					set_name(6333,"Spire Defender");
					set_boss_level(6333,1);
					inc_flag(57,28,1);
					}
					else alert_char(6333);
				
				if (char_ok(6334) == FALSE) {
					spawn_creature(6334);
					set_name(6334,"Spire Defender");
					set_boss_level(6334,1);
					inc_flag(57,28,1);
					}
					else alert_char(6334);
				}
			if (party_dist_to_spot(175,261) > 12) {
				if (char_ok(6335) == FALSE) {
					spawn_creature(6335);
					set_name(6335,"Spire Defender");
					set_boss_level(6335,1);
					inc_flag(57,28,1);
					}
					else alert_char(6335);
				if (char_ok(6336) == FALSE) {
					spawn_creature(6336);
					set_name(6336,"Spire Defender");
					set_boss_level(6336,1);
					inc_flag(57,28,1);
					}
					else alert_char(6336);
				
				if (char_ok(6337) == FALSE) {
					spawn_creature(6337);
					set_name(6337,"Spire Defender");
					set_boss_level(6337,1);
					inc_flag(57,28,1);
					}
					else alert_char(6337);
				
				}
			if (party_dist_to_spot(153,309) > 12) {
				if (char_ok(6338) == FALSE) {
					spawn_creature(6338);
					set_name(6338,"Spire Defender");
					set_boss_level(6338,1);
					inc_flag(57,28,1);
					}
					else alert_char(6338);
				if (char_ok(6339) == FALSE) {
					spawn_creature(6339);
					set_name(6339,"Spire Defender");
					set_boss_level(6339,1);
					inc_flag(57,28,1);
					}
					else alert_char(6339);
				
				if (char_ok(6340) == FALSE) {
					spawn_creature(6340);
					set_name(6340,"Spire Defender");
					set_boss_level(6340,1);
					inc_flag(57,28,1);
					}
					else alert_char(6340);
				
				}
			}
		}
		
	// crime
	
	if (((gf(58,9) > 0) || (get_crime_level() >= max_crime)) && (im_hostile == 0)) {
		sf(58,9,1);
		make_zone_hostile();
		im_hostile = 1;
		}

	if (gf(58,9) == 0) {
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6267,"You may remain here.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6267,"You are an outsider.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6267,"Avernites are not welcomed.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6272,"I am Pitmaster!");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6272,"Arena is good!");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6272,"We need good fights.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6274,"Goods for sale.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6274,"I pay good prices.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6274,"I don't ask questions.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6275,"Anarchy will be prevented.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6275,"We support the mayor.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6275,"We fight for freedom.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6275,"Bargha is mad.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6275,"I welcome you.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6276,"Mrrrr.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6276,"You are not welcome.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6276,"Be moving on.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6277,"I miss my farm.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6277,"Curse the Barghans!");
		if ((get_ran(1,0,100) < 10) && (get_quest_status(189) < 3))
			give_char_text_bubble(6277,"Will nobody help me?");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6278,"Isss ten coins.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6278,"Isss good fights.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6278,"Yesss! Come see!");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6297 + get_ran(1,0,4),"Yes!");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6297 + get_ran(1,0,4),"No!");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6297 + get_ran(1,0,4),"Get him!");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6297 + get_ran(1,0,4),"Tough luck.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6297 + get_ran(1,0,4),"The head came right off.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6297 + get_ran(1,0,4),"Look! A soldier!");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6302 + get_ran(1,0,2),"Ooof!");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6302 + get_ran(1,0,2),"Ugh.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(6302 + get_ran(1,0,2),"Curse this work.");

		}

	if ((gf(58,11) > 0) && (on_which_layer() == 1) && (party_within_dist(164,282,5))) {
		sf(58,11,0);
		sf(58,18,1);
		sf(58,19,0);
		sf(58,27,0);
		sf(58,28,0);
		
		if (gf(58,10) == 1) {
			spawn_creature(6307);
			spawn_creature(6308);
			spawn_creature(6309);
			spawn_creature(6310);
			set_name(6307,"Goblin Pitfighter");
			set_name(6308,"Goblin Pitfighter");
			set_name(6309,"Goblin Pitfighter");
			set_name(6310,"Pitfighter Shaman");
			set_level(6307,20);
			set_level(6308,20);
			set_level(6309,20);
			set_level(6310,20);
			set_boss_level(6307,1);
			set_boss_level(6308,1);
			set_boss_level(6309,1);
			set_boss_level(6310,1);
			
			begin_talk_mode(210);
			}
		if (gf(58,10) == 3) {
			spawn_creature(6311);
			spawn_creature(6312);
			spawn_creature(6313);
			spawn_creature(6314);
			set_name(6311,"Pit Salamander");
			set_name(6312,"Pit Salamander");
			set_name(6313,"Pit Salamander");
			set_name(6314,"Pit Basilisk");
			set_coloradj(6311,4);
			set_coloradj(6312,4);
			set_coloradj(6313,4);
			set_coloradj(6314,2);
			set_boss_level(6311,1);
			set_boss_level(6312,1);
			set_boss_level(6313,1);
			set_boss_level(6314,1);
			
			begin_talk_mode(211);
			}
		if (gf(58,10) == 5) {
			spawn_creature(6315);
			spawn_creature(6316);
			spawn_creature(6317);
			set_name(6315,"Pitfighter Kremen");
			set_name(6316,"Pitfighter Faiga");
			set_name(6317,"Pitfighter Geert");
			set_level(6315,33);
			set_level(6316,33);
			set_level(6317,33);
			set_boss_level(6315,2);
			set_boss_level(6316,2);
			set_boss_level(6317,2);
			
			set_new_abil(6315,16);
			set_new_abil(6316,20);
			set_new_abil(6317,8);

			force_char_status(6315,24,10);
			force_char_status(6316,24,10);
			force_char_status(6317,24,10);
			
			begin_talk_mode(212);
			}
		if (gf(58,10) == 7) {
			spawn_creature(6318);
			spawn_creature(6319);
			set_name(6318,"Ayi of Many Eyes");
			set_name(6319,"Gazer Elu");
			set_level(6318,38);
			set_boss_level(6318,2);
			set_boss_level(6319,2);
			set_new_abil(6318,9);
			set_new_abil(6319,2);
			
			set_resistance(6318,0,80);
			set_resistance(6319,1,80);
			set_resistance(6319,2,80);
			set_resistance(6319,6,80);
			
			force_char_status(6318,24,10);
			force_char_status(6319,24,10);
			
			begin_talk_mode(213);
			}
		if (gf(58,10) == 9) {
			spawn_creature(6320);
			
			begin_talk_mode(214);
			}
		}
	
	if ((gf(57,23) > 3) && (gf(58,10) == 1) && (gf(58,12) == 0)) {
		sf(58,12,1);
		sf(58,19,1);
		begin_talk_mode(215);
		}
	if ((gf(57,24) > 3) && (gf(58,10) == 3) && (gf(58,12) == 0)) {
		sf(58,12,1);
		sf(58,19,1);
		begin_talk_mode(215);
		}
	if ((gf(57,25) > 2) && (gf(58,10) == 5) && (gf(58,12) == 0)) {
		sf(58,12,1);
		sf(58,19,1);
		begin_talk_mode(215);
		}
	if ((gf(57,26) > 1) && (gf(58,10) == 7) && (gf(58,12) == 0)) {
		sf(58,12,1);
		sf(58,19,1);
		begin_talk_mode(215);
		}
	if ((gf(57,27) > 0) && (gf(58,10) == 9) && (gf(58,12) == 0)) {
		sf(58,12,1);
		sf(58,19,1);
		begin_talk_mode(216);
		}
		
	//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();
	//	}
	

break;

beginstate 10;
	set_terrain_string_range("The sign says - SPIRE STORES. KEEP OUT.",1);
break;

beginstate 11;
set_terrain_string_range("The sign says - CITY HALL",1);
break;

beginstate 12;
set_terrain_string_range("The sign says - Gladiator's Entrance",1);
break;

beginstate 13;
	set_terrain_string_range("There are two whipping posts here. Spire practices harsh justice.",1);
break;

beginstate 14;
	set_terrain_string_range("These cages are for public humiliation of miscreants. Spire practices harsh justice.",1);
break;


beginstate 15;
set_terrain_string_range("The sign says - MAYOR'S MANSION. KEEP OUT!",1);
break;


beginstate 16;
set_terrain_string_range("The sign says - MAYOR'S GARDEN. KEEP OUT!",1);
break;

beginstate 18;
	if (char_ok(6306) == FALSE)
		end();

	if ((gf(58,9) == 0) && (dist_to_nav_point(6306,4) <= 2)) {
		sf(58,9,1);
		make_zone_hostile();
		begin_talk_mode(207);
		
		}
		
break;

beginstate 19;
	sf(58,18,0);
	if ((gf(58,11) > 0) || (gf(58,10) >= 10)) 
		sf(58,27,1);
break;

beginstate 20;
	sf(58,26,1);
break;

beginstate 30;
	if ((gf(58,9) == 0) && (revive_party())) {
			print_str_color("Entering or leaving Spire 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);
