// turret.txt - Only exists to create creatures. Never moves or attacks. 
// Cell 4,5 - Stuff done flag to set when spawner is killed. If both are 0, no flag set.
// Cell 6 - what phase

begincreaturescript;

variables;

short i,target;
short talk1 = 0;
short health_level;
short phase = 0;

body;

beginstate INIT_STATE;
	set_walk_speed(ME,0);
	
	set_name(ME,"Veress'Yss");
	set_level(ME,24);
	set_boss_level(ME,2);
	set_courage(ME,100);
	set_resistance(ME,7,90);
	change_max_health(ME,100);
	
	set_new_abil(ME,20);
	set_attack_bonus(ME,10);
	
	set_char_unkillable(ME,1);
	
	health_level = get_max_health(ME);
	
	if (gf(64,1) > 0)
		erase_char(ME);

	break;

beginstate DEAD_STATE;

break;

beginstate START_STATE; 
	if ((phase == 0) && (talk1 == 0) && ((get_nearest_party_char(7) >= 0) || (who_shot_me() >= 0))) {
		talk1 = 1;
		begin_talk_mode(10);
		}
	if ((phase == 0) && (talk1 == 0))
		end();
		
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}

		
	if (get_foe_target(ME,10,0)) {
		do_attack();
		set_state(3);
		}
	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking


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

	if ((phase == 0) && (get_health(ME) < health_level - 200)) {
		phase = 1;
		
		heal_char(ME,400);
		health_level = get_health(ME) - 200;
		
		pc_heard_sound_delay(136,100);						
		summon_creature(6932);
		place_particle_num(6932,1,1,8);
		summon_creature(6933);
		place_particle_num(6933,1,1,8);
		
		begin_talk_mode(11);
		}
	if ((phase == 1) && (get_health(ME) < health_level)) {
		phase = 2;
		
		heal_char(ME,400);
		health_level = get_health(ME) - 200;

		relocate_char(ME,539,272,1);
		
		pc_heard_sound_delay(136,100);						
		summon_creature(6933);
		place_particle_num(6933,1,1,8);
		summon_creature(6934);
		place_particle_num(6934,1,1,8);
		
		set_name(6933,"Basilisk");
		set_coloradj(6933,2);
		set_name(6934,"Basilisk");
		set_coloradj(6934,2);
		
		
		set_char_status(30000,0,-12);
		set_char_status(30000,1,-12);
		set_char_status(30000,8,-12);
		
		begin_talk_mode(12);
		}
	if ((phase == 2) && (get_health(ME) < health_level)) {
		phase = 3;
		
		heal_char(ME,400);
		health_level = get_health(ME) - 200;

		relocate_char(ME,539,262,1);
		
		pc_heard_sound_delay(136,100);						
		summon_creature(6936);
		place_particle_num(6936,1,1,8);
		summon_creature(6937);
		place_particle_num(6937,1,1,8);
		
		set_name(6936,"Mutant Fire Lizard");
		set_level(6936,24);
		set_name(6937,"Mutant Fire Lizard");
		set_level(6937,24);
		

		begin_talk_mode(13);
		}
	if ((phase == 3) && (get_health(ME) < health_level)) {
		phase = 4;
		
		erase_char(ME);
		
		sf(64,2,1);
		sf(64,3,1);
		
		//spawn_creature(6938);
		//spawn_creature(6939);
		//spawn_creature(6940);

		//set_name(6939,"Horde Warbeast");
		//set_name(6940,"Horde Warbeast");
		//set_resistance(6939,7,70);
		//set_resistance(6940,7,70);
	
		begin_talk_mode(14);
		}

	if (dist_to_char(get_target()) > 8) {
			set_foe_target(ME,-1);
			set_state(START_STATE);
		}
		
	do_attack();

	turret_heal();
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;