// spawner.txt - Only exists to create creatures. Never moves or attacks. 
// If it sees a foe, it summons a creature. Does so at most once every 3 rounds.
// Cells 0 - 3 - Numbers of creatures to spawn. if 0, no use.
// Cell 4,5 - Stuff done flag to set when spawner is killed. If both are 0, no 
// flag set.
// Cell 6 - talking cell

begincreaturescript;

variables;

short r1;
short last_spawn;
short mess1 = 0;
short last_abil;

body;

beginstate INIT_STATE;
	set_name(ME,"Shade Construct");
	set_boss_level(ME,2);
	
	set_walk_speed(ME,0);
	last_spawn = get_current_tick();
	last_abil = get_current_tick();
	break;

beginstate DEAD_STATE;
	sf(23,15,8);
	force_char_status(30000,26,-20);
	force_char_status(30024,26,-20);
	erase_char(2494);
	erase_char(2495);
	erase_char(2496);
	erase_char(2497);
	if (gf(23,16) == 0) {
		sf(22,20,1);
		begin_talk_mode(24);
		}
break;

beginstate START_STATE; 
	// see if target is visible
	get_foe_target(ME,12,0);
	
	if ((target_ok()) && (dist_to_party() <= 12)) {
		if (tick_difference(last_spawn,get_current_tick()) > 1) {
			r1 = 2494 + get_ran(1,0,3);
			if (char_ok(r1) == FALSE) {
				if (summon_creature(r1)) {
					print_named_str(ME,"breaks off a small, dark part of itself!");
					set_summon_level(r1,1);
					place_particle_num(r1,1,1,8);
					run_char_animation(2,1,50);	
					pc_heard_sound_delay(161,100);						
					
					last_spawn = get_current_tick();
					
					if (mess1 == 0) {
						mess1 = 1;
						begin_talk_mode(23);
						}
					end();
					

					}
				}

			}


		if ((get_ran(1,0,100) < 50) && (is_combat()) && (get_nearest_hate_char(7) >= 0) && (tick_difference(last_abil,get_current_tick()) > 0)) {
			run_char_animation(2,1,35);	
			last_abil = get_current_tick();
	
			place_particle_num(ME,1,4,8);
			print_named_str(ME,"radiates a cloud of icy particles.");
			damage_nearby(get_ran(1,100,150),7,6,0);
			pc_heard_sound_delay(144,100);						
			create_missile_spiral(151,40,7,2);
			end();
			
			}

		}
break;

beginstate TALKING_STATE;
	if (get_memory_cell(6) == 0) {
		print_str("Talking: It doesn't respond. It can't talk.");
		end();
		}
	begin_talk_mode(get_memory_cell(6));
break;