// beamnpc.txt
// A monster with a special ability scripted in. The ability is an beam, used 
// 50% of the time.

// Memory Cells:
//   Cell 0 - How creature moves.
//     0 - If 0, wander randomly. 
//     1 - Stands still until a target appears.
//     2 - Completely immobile, even if target appears.
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this 
//     is killed, set to 1. (Example: If cell 1 is 3 and cell 2 is 5, when
//     creature is killed, sets SDF(3,5) to 1.)
//   Cell 3 - Dialogue node to start with if talked to. if left at 0, this
//     character doesn't talk.
//   Cell 4 - The ability.

// The abilities:
// 0 - Beam Slow
// 1 - Beam Curse
// 2 - Beam Fire (1-6 dam per level)
// 3 - Beam Acid
// 4 - Beam Terror
// 5 - Beam Daze
// 6 - Beam Debuff
// 7 - Beam Cold (1-8 dam per level)
// 8 - Beam Energy (1-10 dam per level)
// 9 - Beam Charm
// 10 - Beam Freeze
// 11 - lightning
// 12 poison

begincreaturescript;

variables;

short i,target;
short last_abil;
short used_abil = 0;
short r1;
short weak_targ;
short talked = 0;
body;

beginstate INIT_STATE;
		set_name(ME,"Gssch of the Circle");
		set_level(ME,35);
		set_boss_level(ME,2);
	set_new_abil(ME,24);

		alter_stat(ME,19,6);
		alter_stat(ME,28,6);
		
	last_abil = get_current_tick();
	break;

beginstate DEAD_STATE;
	sf(13,13,1);
	force_char_status(30000,26,0);
	begin_talk_mode(26);
break;

beginstate START_STATE; 
	if (talked == 0) {
		if ((get_nearest_party_char(5) >= 0) || (who_shot_me() >= 0)) {
			set_attitude(ME,10);
			talked = 1;
			talk_no_exit(25);
			}
		end();
		}
		
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	// Look for a target, attack it if visible
	if (get_foe_target(ME,12,0)) {
		if (dist_to_party() > 8)
			approach_char(ME,30000,7);
			else {
				do_attack();
				set_state(3);
				}
		}
		
	// Have I been hit? Strike back!
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
		
	// if we're hostile, hunt party down
	if (get_attitude(ME) >= 10) {
		set_foe_target(ME,random_group_member(0));
		set_state(3);
		}

	// if we're in combat and the above didn't give me anything to do, just
	// stop now. Otherwise, game will keep running script, and that eats up CPU time.
	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);
	used_abil = 0;

	r1 = random_group_member(0);
	if (can_see_char(r1) == FALSE) 
		r1 = random_group_member(0);
	if (can_see_char(r1) == FALSE) 
		r1 = random_group_member(0);
	if (can_see_char(r1) == FALSE) 
		r1 = random_group_member(0);
	if (can_see_char(r1) == FALSE) 
		r1 = random_group_member(0);
		
	
	if ((can_see_char(r1)) && (is_combat()) && (tick_difference(last_abil,get_current_tick()) > 0)) {
		run_char_animation(2,1,35);	
		last_abil = get_current_tick();

		  	//place_particle_num(get_target(),1,4,8);
			print_named_str(ME,"flings a spray of icy particles.");
			damage_char(r1,get_ran(1,400,500),6);
			set_char_status(r1,0,-12);
			set_char_status(r1,8,-12);
			set_char_status(r1,22,4);
			run_sparkles_on_char(get_target(),172,1,4);
			pc_heard_sound_delay(144,100);						
			shoot_projectile(ME,char_loc_x(get_target()),char_loc_y(get_target()),71);
			used_abil = 1;
		force_char_status(ME,20,3);
		end();
		}


	weak_targ = most_frail_pc();


	if ((can_see_char(get_pc_id(weak_targ))) && (dist_to_char(get_pc_id(weak_targ)) <= 5))
		set_foe_target(ME,get_pc_id(weak_targ));


	if (used_abil == 0)
		do_attack();
break;

beginstate TALKING_STATE;
	if (get_memory_cell(3) == 0) {
		print_str("Talking: The slith doesn't respond.");
		end();
		}
	begin_talk_mode(get_memory_cell(3));
break;