// priest.txt
// Like basicnpc.txt, but with a host of magical abilities. The abilities it 
// uses depends on the level of the character.

// 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.
//     3 - All moving handled by custom code for that char type.
//   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 - Which special character code is active?
//     1 - Necromancer Ghalna
//	   2 - Gremesss
//	   3 - ximun
//	   4 - Icy Revenant
//     5 - Breck-Drayssa
//	   6 - Loyalist Gavrahoss
//	   7 - Shaman Thorr'Mra
//	   8 - Cultist Visius
//     9 - Priestess Rrone

// spell_class - The quality of spells this character can cast, is level / 4, 
//    starts at 1
// 1 - can bless, curse heal
// 2 - call shades
// 3 - ae bless, curse
// 4 - ae heal, charm
// 5 - rain fire
// 6 - call a major shade

begincreaturescript;

variables;

short i,target;
short spell_class;
short bless_target;
short did_spell;
short tried_return = 0;
short summoned_char;
short misc_var = 0;
short misc_var2 = 0;
short last_abil;

body;

beginstate INIT_STATE;
	if (get_memory_cell(0) == 2)
		set_walk_speed(ME,0);
	spell_class = get_level(ME) / 4;
	if (spell_class == 0)
		spell_class = 1;
	bless_char(ME,spell_class - 1);

	set_courage(ME,100);
	set_resistance(ME,7,90);

	last_abil = get_current_tick();
	
	if (get_memory_cell(4) == 1) { // Necromancer Ghalna
		set_name(ME,"Necromancer Ghalna");
		set_level(ME,7);
		set_boss_level(ME,1);
		change_max_health(ME,20);
		set_coloradj(ME,272);
		}
	if (get_memory_cell(4) == 2) { // Gremesss
		set_name(ME,"Gremesss");
		set_level(ME,12);
		change_max_health(ME,50);
		}
	if (get_memory_cell(4) == 3) { // Novice Ximun
		set_name(ME,"Novice Ximun");
		set_boss_level(ME,2);
		change_max_health(ME,20);
		}
	if (get_memory_cell(4) == 4) { // Icy Revenant
		set_name(ME,"Icy Revenant");
		set_coloradj(ME,1024);
		set_aggression(ME,60);
		set_level(ME,16);
		set_boss_level(ME,2);
		change_max_health(ME,20);
		place_particle_num(ME,18,12,6);		
		}
	if (get_memory_cell(4) == 6) { // Loyalist Gavrahoss
		set_name(ME,"Loyalist Gavrahoss");
		set_aggression(ME,60);
		set_level(ME,31);
		set_boss_level(ME,2);
		change_max_health(ME,50);
		set_resistance(ME,0,80);
		set_resistance(ME,1,80);
		set_resistance(ME,2,80);
		set_resistance(ME,3,80);
		set_resistance(ME,4,0);
		set_resistance(ME,5,80);
		set_resistance(ME,6,80);
		
		sf(71,20,0);
		sf(71,21,0);
		}
	if (get_memory_cell(4) == 7) { // Shaman Thorr'Mra
		set_name(ME,"Shaman Thorr'Mra");
		set_level(ME,24);
		set_boss_level(ME,2);
		change_max_health(ME,80);
		}
	if (get_memory_cell(4) == 8) { // Cultist Visius
		set_name(ME,"Cultist Visius");
		set_level(ME,20);
		set_boss_level(ME,2);
		set_walk_speed(ME,0);

		place_particle_num(15680,17,12,6);		
		place_particle_num(15680,17,13,6);		

		set_resistance(9749,0,90);
		set_resistance(9749,1,90);
		set_resistance(9749,2,90);
		set_resistance(9749,6,90);
		}

	if (get_memory_cell(4) == 9) { // Priestess Rrone
		set_name(ME,"Priestess Rrone");
		set_level(ME,30);
		set_boss_level(ME,1);
		}

	break;
	
beginstate DEAD_STATE;
	// Set the appropriate stuff done flag for this character being dead
	if ((get_memory_cell(1) != 0) || (get_memory_cell(2) != 0))
		set_flag(get_memory_cell(1),get_memory_cell(2),1);
		
	if (get_memory_cell(4) == 1) { // Necromancer Ghalna
		sf(141,4,0);
		sf(141,1,1);
		begin_talk_mode(36);
		}
	if (get_memory_cell(4) == 2) { // Gremesss
		begin_talk_mode(5);
		}
	if (get_memory_cell(4) == 3) { // Novice Ximun
		sf(164,2,2);
		}
	if (get_memory_cell(4) == 5) { // Breck-Drayssa	
		sf(170,11,1);
		if (has_spec_item(3) == 0) {
			sf(29,6,1);
			begin_talk_mode(54);
			}
		}
	if (get_memory_cell(4) == 6) { // Loyalist Gavrahoss
		sf(70,9,1);
		begin_talk_mode(15);
		}
	if (get_memory_cell(4) == 7) { // Shaman Thorr'Mra
			set_resistance(9749,0,40);
			set_resistance(9749,1,40);
			set_resistance(9749,2,40);
			set_resistance(9749,6,40);
			set_resistance(9750,0,40);
			set_resistance(9750,1,40);
			set_resistance(9750,2,40);
			set_resistance(9750,6,40);
		
		clean_off_particles(9749);
		clean_off_particles(9750);
		if (char_ok(9750) || char_ok(9749))
			begin_talk_mode(13);
		}	
break;

beginstate START_STATE; 
	if ((get_memory_cell(4) == 4) && (misc_var == 0)) { // Icy Revenant
		if (get_nearest_party_char(6) >= 0) {
			misc_var = 1;
			alert_char(18103);
			alert_char(18104);
			talk_no_exit(9);
			}
		}

	if ((get_memory_cell(4) == 6) && (misc_var == 0)) { // Loyalist Gavrahoss
		if ((get_nearest_party_char(7) >= 0) || (who_shot_me() >= 0)) {
			misc_var = 1;
			last_abil = get_current_tick();
			set_aggression(ME,100);
			alert_char(ME);

			set_act_at_dist(7605,1);
			set_act_at_dist(7606,1);
			set_act_at_dist(7607,1);
			set_act_at_dist(7608,1);
			set_act_at_dist(7609,1);
			set_act_at_dist(7610,1);
			set_act_at_dist(7611,1);
			set_act_at_dist(7612,1);
			set_act_at_dist(7613,1);
			set_act_at_dist(7614,1);
			alert_char(7605);
			alert_char(7606);
			alert_char(7607);
			alert_char(7608);
			alert_char(7609);
			alert_char(7610);
			alert_char(7611);
			alert_char(7612);
			alert_char(7613);
			alert_char(7614);

			set_aggression(7616,100);
			set_aggression(7617,100);
			alert_char(7616);
			alert_char(7617);
		
			talk_no_exit(50);
			}
		end();
		}
	if ((get_memory_cell(4) == 7) && (misc_var == 0)) { // Shaman Thorr'Mra
		if ((get_nearest_party_char(6) >= 0) || (who_shot_me() >= 0)) {
			set_attitude(ME,10);
			
			misc_var = 1;
			spawn_creature(9749);
			spawn_creature(9750);
			set_name(9749,"Fang Clan Defender");
			set_level(9749,24);
			set_resistance(9749,0,97);
			set_resistance(9749,1,97);
			set_resistance(9749,2,97);
			set_resistance(9749,6,97);
			set_name(9750,"Fang Clan Defender");
			set_level(9750,24);
			set_resistance(9750,0,97);
			set_resistance(9750,1,97);
			set_resistance(9750,2,97);
			set_resistance(9750,6,97);
			
			force_char_status(9749,1,30);
			force_char_status(9750,1,30);

			place_particle_num(9749,18,12,6);		
			place_particle_num(9750,18,12,6);		

			alert_char(9749);
			alert_char(9750);
			talk_no_exit(12);
			}
		end();
		}
		
	// REGULAR CODE

	// 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_attitude(30047,10);
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
		
	if (get_memory_cell(4) == 1) { // Necromancer Ghalna
		if (misc_var2 == 0) {
			if (dist_to_nav_point(ME,0) <= 3)
				misc_var2 = 1;
				else approach_nav_point(ME,0,2);
			}
			else if (dist_to_nav_point(ME,1) > 3)
				approach_nav_point(ME,1,2);
		}
		
	if (get_memory_cell(4) == 3) { // Novice Ximun
		if ((char_ok(17758) == FALSE) || (get_attitude(17758) >= 10))
			set_attitude(30047,10);
		if ((char_ok(17759) == FALSE) || (get_attitude(17759) >= 10))
			set_attitude(30047,10);
		if ((char_ok(17760) == FALSE) || (get_attitude(17760) >= 10))
			set_attitude(30047,10);
		
		if ((misc_var == 0) && (get_nearest_party_char(6) >= 0)) {
			misc_var = 1;
			talk_no_exit(10);
			}
		}

	if ((get_memory_cell(4) == 5) && (gf(29,6) > 0)) { // Breck-Drayssa	
		if (dist_to_nav_point(ME,0) <= 2) {
			print_str_color("Breck-Drayssa escapes!",3);
			award_party_xp(200,20);
			erase_char(ME);
			end();
			}
		approach_nav_point(ME,0,1);
		}

	if (get_memory_cell(4) == 9) { // Priestess Rrone
		if (gf(6,13) == 3) {
			if (dist_to_nav_point(ME,1) <= 3)
				fidget(ME,25);
				else approach_nav_point(ME,1,2);
			}
			else if (my_dist_from_start() >= 6) {
				if (get_ran(1,1,100) < 40) 
					return_to_start(ME,1);
				}
		}

		
	// Otherwise, just peacefully move around. Go back to start, if I'm too far
	// from where I started.
	if (get_memory_cell(0) != 3) {
		if ((my_dist_from_start() >= 6) || ((my_dist_from_start() > 0) && (get_memory_cell(0) > 0))) {
			if (get_ran(1,1,100) < 40) 
				return_to_start(ME,1);
			}
			else if (get_memory_cell(0) == 0) {
				fidget(ME,25);
				}
		}
		
	// 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 ((get_memory_cell(4) == 4) && (misc_var == 0)) { // Icy Revenant
			misc_var = 1;
			alert_char(18103);
			alert_char(18104);
			talk_no_exit(9);
		}

	spell_class = get_level(ME) / 4;
	if (spell_class == 0)
		spell_class = 1;

	if (am_i_doing_action())
		end();
		
	if (target_ok() == FALSE)
		set_state(START_STATE);

	// SPECIAL ABILIIES
	if (get_memory_cell(4) == 3) { // Novice Ximun
		if ((misc_var < 2) && (get_health(ME) < get_max_health(ME) / 2)) {
			misc_var = 2;
			begin_talk_mode(30);
			}
		}
	if (get_memory_cell(4) == 4) { // Icy Revenant
		if ( (can_see_char(get_target())) && (is_combat()) && (tick_difference(last_abil,get_current_tick()) > 1)) {
			last_abil = get_current_tick();
			run_char_animation(2,1,35);	
			print_named_str(ME,"points at you. You grow very cold.");
			set_char_status(get_target(),19,25);
			//place_particle_num(get_target(),8,2,8);
			pc_heard_sound_delay(165,100);						
			end();
			}			
		}
		
	if (get_memory_cell(4) == 6) { // Loyalist Gavrahoss
		if ((is_combat()) && (tick_difference(last_abil,get_current_tick()) > 4)) {
			misc_var2 = 1;
			
			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);
			place_particle_num(ME,18,12,6);
			
			summon_creature(7618);
			summon_creature(7619);
			summon_creature(7620);
			summon_creature(7621);
			add_range_to_group(7618,7621,39);
			set_name(30039,"Spirit Shard");
			place_particle_num(30039,1,1,8);
			change_max_health(30039,500);
			set_boss_level(30039,1);
			set_char_unkillable(30039,1);
			set_resistance(30039,0,100);
			set_resistance(30039,1,100);
			set_resistance(30039,2,100);
			set_resistance(30039,3,100);
			set_resistance(30039,4,100);
			set_resistance(30039,5,100);
			set_resistance(30039,6,100);
			set_resistance(7618,6,0);
			set_resistance(7619,2,0);
			set_resistance(7620,0,0);
			set_resistance(7621,3,0);
			
			last_abil = get_current_tick();
			
			print_str_color("Loyalist Gavrahoss surrounds himself with a shield.",3);
			print_str_color("  His spirit splits into several fragments, which emerge.",3);
			print_str_color("  from his body to attack you.",3);
			
			set_state(5);
			}
		}



	if ((get_memory_cell(4) == 8) && (misc_var == 0) && (num_chars_in_group(31) < 2)) { 
		// Cultist Visius
		print_str_color("Cultist Visius steps away from the altar to avenge his servants.",3);
		misc_var = 1;
		set_walk_speed(ME,24);
		clean_off_particles(ME);
		set_resistance(9749,0,10);
		set_resistance(9749,1,10);
		set_resistance(9749,2,10);
		set_resistance(9749,6,10);
		}
		
	// SPECIAL ABILIIES, ONCE PER TURN
	if ((get_memory_cell(4) == 7) || (get_memory_cell(4) == 8)) {
		if (tick_difference(last_abil,get_current_tick()) > 0) {
			last_abil = get_current_tick();
	
			if (get_memory_cell(4) == 7) { // Shaman Thorr'Mra
				if ((is_combat()) && (get_nearest_hate_char(7) >= 0)) {
					last_abil = get_current_tick();
					alert_char(9749);
					alert_char(9750);
					
					if (dist_to_loc(ME,401,390) > 12) {
						print_str_color("The shaman tries to draw power from the altar, but he",2);
						print_str_color("  is too far away.",2);
						}
						else {
							run_char_animation(2,1,35);	
							print_str_color("The shaman draws power from the altar.",2);
							
							if (misc_var2 == 0) {
								place_particle_num(ME,3,1,8);
								print_named_str(ME,"casts a spell. It clouds your mind.");
								status_nearby(70,7,17,4);
								status_nearby(-8,7,1,4);
								pc_heard_sound_delay(195,100);			
								misc_var2 = 1;
								
								}
								else {
									place_particle_num(ME,1,4,8);
									print_named_str(ME,"summons from above a pillar of lightning.");
									damage_nearby(get_ran(1,200,300),7,1,0);
									status_nearby(-8,7,0,4);
									status_nearby(-8,7,8,4);
									pc_heard_sound_delay(179,100);						
									create_missile_spiral(155,40,7,2);
									misc_var2 = 0;
									}
							end();
							}
					}
				}	
	
			if ((get_memory_cell(4) == 8) && (misc_var == 0) && (get_ran(1,0,100) < 50)) { // Cultist Visius
				run_char_animation(2,1,35);	
				pc_heard_sound_delay(195,100);			
				print_named_str(ME,"refreshes his warriors.");
				force_char_status(30031,27,-10);
				set_char_status(30031,0,4);
				}
	
			}
		}
		
	// BACK TO START?
	
	if ((my_dist_from_start() >= 25) && (tried_return == 0) && (get_memory_cell(0) != 3)) {
		tried_return = 1;
		set_foe_target(ME,-1);
		return_to_start(ME,2);
		set_state(4);
		}

	// SPELL STUFF
	
	// if our target is terrified or charmed or dazed, get new target
	if ((get_char_status(get_target(),7) > 0) || (get_char_status(get_target(),5) > 0) || (get_char_status(get_target(),17) > 0)) {
		get_foe_target(ME,12,0);
		if (target_ok() == FALSE)
			set_state(START_STATE);	
		}
		 
	// if party ducks out of combat mode, force it to restart
	if ((is_combat() == FALSE) && (can_see_char(get_target()))) {
		do_attack();
		end();
		}
	
	if (can_see_char(get_target()) == FALSE) {
		do_attack();
		end();
		}

	// now we are seeing if we want to cast a spell. the answer is probably yes.
	did_spell = 0;

	
	// first, bless and shield
	// all casters now always ae bless and shield
	bless_target = -3;
	if (((get_char_status(ME,0) < 0) && (get_ran(1,0,100) < 80)) ||
	  ((get_char_status(ME,0) == 0) && (get_ran(1,0,100) < 20) && (friends_nearby(6) > 2))) {
	  	if (spell_class > 0)
	  		bless_target = -2;
	  		else bless_target = -1;
	  	}
	if ((bless_target == -3) && (friends_nearby(6) > 2) &&
	  (get_friendly_target(ME,8,0) > 0) && (get_ran(1,0,100) < 20)) {
	  	if (spell_class > 0)
	  		bless_target = -2;
	  		else bless_target = get_friend_target();
	  	}

	if (bless_target == -2) { // AE bless
		if (get_char_status(ME,0) <= 0) { // don't rebless myself
			print_named_str(ME,"blesses allies.");
			status_nearby(8,8,0,3);
			status_nearby(8,8,8,3);
			//particle_nearby(8,1,0,3,8);
			run_char_animation(2,1,35);	
			pc_heard_sound_delay(100,100);						
			deduct_ap(9);
			did_spell = 1;
			}
		}
			
	if (bless_target >= -1) { // 1 target bless
		if (bless_target == -1)
			bless_target = my_id();
		if (get_char_status(bless_target,0) <= 0) { // don't rebless
			if (bless_target == my_id())
				print_named_str(ME,"gives a blessing.");
				else print_named_str(ME,"blesses an ally.");
		  	//place_particle_num(bless_target,1,0,8);
			set_char_status(bless_target,0,8);
			set_char_status(bless_target,8,8);
			run_char_animation(2,1,35);	
			pc_heard_sound_delay(100,100);						
			deduct_ap(9);
			did_spell = 1;
			}
		}		
	
	// curse or AE curse?
	if ((did_spell == 0) && (spell_class >= 3) && (friends_nearby(6) > 2) &&
	  ((get_ran(1,0,100) < 15) || ((get_char_status(get_target(),0) >= 0) && (get_ran(1,0,100) < 30)))) {
		print_named_str(ME,"casts a powerful curse.");
		status_nearby(-12,8,0,4);
		status_nearby(-12,8,8,4);
		//particle_nearby(8,3,2,4,8);
		run_char_animation(2,1,35);	
		pc_heard_sound_delay(128,100);						
		deduct_ap(9);
		did_spell = 1;
		}
	if ((did_spell == 0) && (spell_class < 3) && (friends_nearby(6) > 2) &&
	  ((get_ran(1,0,100) < 15) || ((get_char_status(get_target(),0) >= 0) && (get_ran(1,0,100) < 30)))) {
		print_named_str(ME,"casts a curse.");
		set_char_status(get_target(),0,-8);
		set_char_status(get_target(),8,-8);
	  	//place_particle_num(get_target(),3,6,8);
		run_char_animation(2,1,35);	
		pc_heard_sound_delay(128,100);						
		deduct_ap(9);
		did_spell = 1;
		}	

		
	// heal?
	if ((did_spell == 0) && ((get_friendly_target(ME,8,2) > 0) || (get_health(ME) < get_max_health(ME) / 2)) && (get_ran(1,0,100) < 50)) {
		// do ae or single target?
	  	if (spell_class >= 4) {
			print_named_str(ME,"radiates healing energy.");
			//particle_nearby(8,3,1,3,8);
	  		heal_nearby(get_ran(3 + spell_class,1,10),8,3);
			run_char_animation(2,1,35);	
			pc_heard_sound_delay(120,100);						
			deduct_ap(9);
			did_spell = 1;
	  		}
			else {
				if (get_health(ME) < get_max_health(ME) / 2)
					bless_target = my_id();
					else bless_target = get_friend_target();
				if (bless_target == my_id())
					print_named_str(ME,"casts a healing spell.");
					else print_named_str(ME,"heals an ally.");
		 	 	//place_particle_num(bless_target,3,1,8);

				heal_char(bless_target,get_ran(3 + spell_class,1,10));
				run_char_animation(2,1,35);	
				pc_heard_sound_delay(120,100);						
				deduct_ap(9);
				did_spell = 1;
				}
		}

	// if alone, summon aid
	if ((did_spell == 0) && (((friends_nearby(6) < enemies_nearby(6)) && 
		(get_ran(1,0,100) < 40)) || (get_ran(1,0,100) < 25))) {
			if (spell_class >= 6)
				i = return_summon_char(5);
				else i = return_summon_char(4);
			summon_char(i,12);
			summoned_char = get_summoned_char_id();
			if (summoned_char >= 0) {
				print_named_str(ME,"summons aid.");
				run_char_animation(2,1,35);	
				pc_heard_sound_delay(136,100);						
				deduct_ap(9);
				did_spell = 1;
				
				if (get_level(ME) >= 10)
					change_max_health(summoned_char,1 * get_level(ME));

				if ((get_level(ME) * 3) / 4 > get_level(summoned_char))
					set_level(summoned_char,(get_level(ME) * 3) / 4);
				}
			}
			
	// cast charm on a foe
	if ((did_spell == 0) && (spell_class >= 3) && (num_party_uncharmed() > 1) && 
	  (get_char_status(get_target(),5) <= 0) && (get_ran(1,0,100) < 25)) {
		print_named_str(ME,"casts a charm spell.");
	  	//place_particle_num(get_target(),10,6_num);
		set_char_status(get_target(),5,10 * spell_class);
		run_char_animation(2,1,35);	
		pc_heard_sound_delay(123,100);						
		deduct_ap(9);
		did_spell = 1;
	  	}
			
	// AE lightning?
	if ((did_spell == 0) && (spell_class >= 5) && (get_attitude(ME) >= 10) && 
	  (enemies_nearby(8) > 1) && (get_ran(1,0,100) < 35)) {
		print_named_str(ME,"summons a cloud of divine energy.");
	  	damage_nearby(get_ran(get_level(ME) + get_attack_bonus(ME),1,5),7,1,4);
		status_nearby(get_level(ME) / 4,7,22,4);
	  		create_missile_spiral(155,40,7,2);
		run_char_animation(2,1,35);	
		pc_heard_sound_delay(179,100);						
		deduct_ap(9);
		did_spell = 1;
	  	}
	
	if (did_spell > 0)
		end();
	
	//if (my_ap() < 5)
	//	end_combat_turn();
		
	if (am_i_doing_action() == FALSE)
		do_attack();
break;

beginstate 4; // returning to start
	if (my_dist_from_start() < 10)
		set_state(START_STATE);

	// Have I been hit? Strike back!
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
	
	return_to_start(ME,2);
break;

beginstate 5; // // Loyalist Gavrahoss frozen
	if (misc_var2 == 0)
		set_state(START_STATE);
	
	if (gf(71,20) == 0) {
		sf(71,20,1);
		begin_talk_mode(13);
		}
	if (tick_difference(last_abil,get_current_tick()) > 3) {
		misc_var2 = 0;
		last_abil = get_current_tick();
		set_resistance(ME,0,80);
		set_resistance(ME,1,80);
		set_resistance(ME,2,80);
		set_resistance(ME,3,80);
		set_resistance(ME,4,0);
		set_resistance(ME,5,80);
		set_resistance(ME,6,80);
		clean_off_particles(ME);
		
		i = 0;
		i = i + get_max_health(7618) - get_health(7618);
		i = i + get_max_health(7619) - get_health(7619);
		i = i + get_max_health(7620) - get_health(7620);
		i = i + get_max_health(7621) - get_health(7621);

		damage_char(ME,i * 2,4);
		print_str_color("Loyalist Gavrahoss emerges from his shield.",3);
		print_str_color("  His spirit fragments are absorbed into his body.",3);
		
		if (i > 0)
			print_str_color("  He flinches. The damage the fragments took transfers to him.",3);
		
		erase_char(7618);
		erase_char(7619);
		erase_char(7620);
		erase_char(7621);
		
		summon_creature(7622);
		summon_creature(7623);
		place_particle_num(7622,1,1,8);
		place_particle_num(7623,1,1,8);
		set_name(7622,"Fanged Imp");
		set_name(7623,"Clawed Imp");
		set_level(7622,30);
		set_level(7623,30);
		set_coloradj(7622,1);
		force_char_status(7622,1,25);
		force_char_status(7623,1,25);
		set_attack_bonus(7622,15);
		set_attack_bonus(7623,15);
		set_resistance(7622,0,90);
		set_resistance(7623,1,90);
		set_resistance(7623,2,90);
		set_resistance(7623,6,90);
		
		if (gf(71,21) == 0) {
			sf(71,20,1);
			begin_talk_mode(14);
			}
			else set_state(START_STATE);
		}

break;

beginstate TALKING_STATE;
	if ((get_memory_cell(4) == 5) && (gf(29,6) > 0)) { // Breck-Drayssa	
		print_str_color("Talking: Breck-Drayssa's attention is occupied by",3);
		print_str_color("  trying to escape.",3);
		end();
		}

	if (get_memory_cell(4) == 9) { // Priestess Rrone
		if (gf(6,13) == 3)
			begin_talk_mode(17);
		if (my_dist_from_start() > 7) {
			print_str_color("This priestess quickly runs past you.",2);
			end();
			}
		}


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