// .txt

beginzonescript;

variables;

short im_hostile = 0;
short max_crime = 5;
short last_abil;
short counter = 0;
short r1;

body;

beginstate INIT_STATE;
	sf(125,6,1);
	
	last_abil = get_current_tick();

	set_name(13508,"Spiral Guard");
	set_name(13509,"Spiral Guard");
	set_name(13510,"Spiral Sage");
	set_name(13511,"Spiral Sage");
	set_level(13510,15);
	set_level(13511,15);
	
	set_name(13512,"Sage Martella");
	set_level(13512,20);
	set_boss_level(13512,1);


	add_range_to_group(13500,13503,43);

	set_crime_tolerance(max_crime);

	if (gf(125,12) > 0) {
		set_terrain(1,885,556,0);
		set_terrain(1,889,557,0);
		}

	add_range_to_group(13519,13524,44);
	set_name(30044,"Insubstantial Wisp");
	set_level(30044,1);
	set_aggression(30044,25);

	set_name(13525,"Ruby Skeleton");
	set_level(13525,19);
	set_coloradj(13525,256);
	set_name(13526,"Ruby Skeleton");
	set_level(13526,19);
	set_coloradj(13526,256);
	set_name(13527,"Ruby Skeleton");
	set_level(13527,19);
	set_coloradj(13527,256);
	set_name(13528,"Ruby Skeleton");
	set_level(13528,19);
	set_coloradj(13528,256);

	set_strategy(13525,1);
	set_strategy(13526,1);
	set_strategy(13527,1);
	set_strategy(13528,1);

	add_range_to_group(13535,13540,45);
	set_name(30045,"Quickghast");
	set_aggression(30045,30);
	set_new_abil(30045,22);
	set_boss_level(30045,1);
	alter_stat(30045,19,10);
	

	break;

beginstate EXIT_STATE;

break;

beginstate START_STATE;
		
	if ((get_crime_level() >= max_crime) && (im_hostile == 0)) {
		make_zone_hostile();
		im_hostile = 1;
		}

	if (gf(125,1) == 0) {
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(13512,"Beware the spiral.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(13512,"Best to stay above.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(13512,"Watch for the wards.");
		}
	if (gf(125,1) > 0) {
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(13512,"It's a disaster.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(13512,"The spiral is lost.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(13512,"We must flee.");
		}

	if ((gf(125,12) == 0) && (party_dist_to_spot(887,557) <= 5) && ((get_char_status(get_pc_id(0),25) > 0) || (get_char_status(get_pc_id(1),25) > 0) || (get_char_status(get_pc_id(2),25) > 0) || (get_char_status(get_pc_id(3),25) > 0))) {
		sf(125,12,1);
		set_terrain(1,885,556,0);
		set_terrain(1,889,557,0);
		begin_talk_mode(12);
		}
		
	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();
		
		r1 = get_ran(1,0,1);
		if ((gf(125,1) > 0) && (get_ran(1,0,8) == 1) && (char_ok(13513 + r1) == FALSE) && (party_dist_to_spot(863,534) > 8)) {
			spawn_creature(13513 + r1);
			set_summon_level(13513 + r1,1);
			}
		
		if ((gf(125,24) > 0) && (gf(125,24) < 20)) {
			inc_flag(125,24,1);
			
			if (gf(125,24) == 1) {
				print_str_color("Some skeletons rise from the bone piles!",3);
				spawn_creature(13558);
				spawn_creature(13559);
				spawn_creature(13560);
				set_level(13558,18);
				set_level(13559,18);
				set_level(13560,18);
				}
			
			if (gf(125,24) == 3) {
				print_str_color("Some skeletons rise from the bone piles!",3);
				spawn_creature(13561);
				spawn_creature(13562);
				spawn_creature(13563);
				set_level(13561,18);
				set_level(13562,18);
				set_level(13563,18);
				}
			
			if (gf(125,24) == 5) {
				print_str_color("Some skeletons rise from the bone piles!",3);
				spawn_creature(13564);
				spawn_creature(13565);
				spawn_creature(13566);
				set_level(13564,20);
				set_level(13565,20);
				set_level(13566,20);
				
				set_name(13564,"Emerald Bones");
				set_name(13565,"Emerald Bones");
				set_name(13566,"Emerald Bones");
				set_coloradj(13564,512);
				set_coloradj(13565,512);
				set_coloradj(13566,512);
				alert_char(13564);
				alert_char(13565);
				alert_char(13566);
				}
			
			if (gf(125,24) == 7) {
				print_str_color("Some skeletons rise from the bone piles!",3);
				spawn_creature(13567);
				spawn_creature(13568);
				set_level(13567,20);
				set_level(13568,20);
				set_boss_level(13567,1);
				set_boss_level(13568,1);
				}
			
			if (gf(125,24) == 9) {
				print_str_color("A final skeleton rises from the bone piles!",3);
				set_name(13569,"Bony Dervish");
				spawn_creature(13569);
				set_level(13569,22);
				set_boss_level(13569,2);
				set_attack_bonus(13569,12);
				alert_char(13569);
				}
			
			}
			
		counter = counter + 1;
		if (counter == 5) {
			counter = 0;
			sf(125,13,1);
			
			if ((gf(125,1) > 0) && (on_which_layer() == 1)) {
				if (party_dist_to_spot(850,530) > 9) {
					if ((get_ran(1,0,100) < 60) && (char_ok(13552) == FALSE)) {
						spawn_creature(13552);
						set_name(13552,"Bony Hunter");
						set_level(13552,15);
						if (gf(125,23) > 20)
							set_summon_level(13552,1);
						}
					if ((get_ran(1,0,100) < 60) && (char_ok(13553) == FALSE)) {
						spawn_creature(13553);
						set_name(13553,"Bony Hunter");
						set_level(13553,15);
						if (gf(125,23) > 20)
							set_summon_level(13553,1);
						}
					}
				if (party_dist_to_spot(890,516) > 9) {
					if ((get_ran(1,0,100) < 60) && (char_ok(13554) == FALSE)) {
						spawn_creature(13554);
						set_name(13554,"Zombie Hunter");
						set_level(13554,15);
						if (gf(125,23) > 20)
							set_summon_level(13554,1);
						}
					if ((get_ran(1,0,100) < 60) && (char_ok(13555) == FALSE)) {
						spawn_creature(13555);
						set_name(13555,"Zombie Hunter");
						set_level(13555,15);
						if (gf(125,23) > 20)
							set_summon_level(13555,1);
						}
					}
					
				}
			}
		}
break;

beginstate 10;
	set_terrain_string_range("This is where the sages keep their records of happenings in the spiral.",1);
break;

beginstate 11;
break;

beginstate 12;
break;

beginstate 13;
break;

beginstate 20;
	if (is_combat() == FALSE)
		print_str_color("You climb the stairs.",2);
	change_level(856,565,6);
	// direction - 0,1 - north 2,3 - west 4,5 - south 6,7 - east
break;

beginstate 21;
	if (is_combat() == FALSE)
		print_str_color("You climb the stairs.",2);
	change_level(867,552,0);
	// direction - 0,1 - north 2,3 - west 4,5 - south 6,7 - east
break;
//	print_str("");
//	set_terrain_string_range(".",1);
//	set_terrain_string_range("The sign says - .",1);
