// basicnpc.txt
// A very simple, naive text. Creature attacks anything it hates nearby.
// Once it has won, it returns to its home.
// NPC that doesn't move or do anything
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.

begincreaturescript;

variables;

short i,target;
short r1,r2;


body;

beginstate INIT_STATE;
	set_walk_speed(ME,0);
	set_char_unkillable(ME,1);
	set_level(ME,40);
	set_resistance(ME,0,100);
	set_resistance(ME,1,100);
	set_resistance(ME,2,100);
	set_resistance(ME,3,100);
	set_resistance(ME,4,100);
	set_resistance(ME,5,100);
	set_resistance(ME,6,100);
	set_resistance(ME,7,100);
	
	if (gf(10,19) > 2)
		erase_char(ME);
	break;

beginstate DEAD_STATE;

break;

beginstate START_STATE; 
	if (gf(10,19) == 0) 
		end();
	if (gf(10,19) > 2)
		erase_char(ME);
	if (gf(10,19) == 2) {
		force_char_status(ME,22,10);
		set_char_unkillable(ME,0);
		set_level(ME,10);
		set_resistance(ME,0,0);
		set_resistance(ME,1,0);
		set_resistance(ME,2,0);
		set_resistance(ME,3,0);
		end();
		}
	if ((gf(10,23) >= 3) && (my_id() == 1096 + gf(10,21)) ) { // boom
		sf(10,23,0);
		
		// tabulate damage
		i = (get_max_health(1096 + gf(10,22)) - get_health(1096 + gf(10,22)) ) / 50;
		inc_flag(10,25,i);
		if (gf(10,25) >= 40) { // go to next phase?
			sf(10,19,2);
			
			set_walk_speed(1100,24);
			force_char_status(1100,22,10);
				
			set_resistance(1100,0,0);
			set_resistance(1100,1,0);
			set_resistance(1100,2,0);
			set_resistance(1100,3,0);

		 	set_char_unkillable(1100,0);
		
			begin_talk_mode(17);
			end();
			}
		heal_char(30012,5000);
		
		if (i > 0) {
			print_str_color("The shade shudders slightly. Something seems to have hurt it.",3);
			}
			
		// shoot fire
		print_named_str(ME,"shoots out a cloud of fire.");
		place_particle_num(ME,2,4,8);
		damage_nearby(get_ran(1,400,500),6,2,0);
		pc_heard_sound_delay(178,100);						
		create_missile_spiral(154,40,6,2);
		
		// shift sparks
		r1 = get_ran(1,0,3);
		r2 = get_ran(1,0,3);
		while (r1 == r2) {
			r2 = get_ran(1,0,3);
			}
		sf(10,21,r1);
		sf(10,22,r2);
		clean_off_particles(30012);
		set_resistance(30012,0,100);
		set_resistance(30012,1,100);
		set_resistance(30012,2,100);
		set_resistance(30012,3,100);
		place_particle_num(1096 + gf(10,21),22,12,5);		
		place_particle_num(1096 + gf(10,21),22,13,5);		
		place_particle_num(1096 + gf(10,22),21,12,5);		
		place_particle_num(1096 + gf(10,22),21,13,5);		

		set_resistance(1096 + gf(10,22),0,0);
		set_resistance(1096 + gf(10,22),1,0);
		set_resistance(1096 + gf(10,22),2,0);
		set_resistance(1096 + gf(10,22),3,0);
		
		if (gf(10,24) == 0) {
			sf(10,24,1);
			begin_talk_mode(16);
			}
		}
		
	end_combat_turn();
break;

beginstate TALKING_STATE;
	print_str("Talking: It doesn't respond.");
break;