begincreaturescript;

variables;

short i,target;
short last_abil_time,atarget,type,whom,a,b,c,d;
short buddy, healthgap;

body;

beginstate INIT_STATE;
	if (get_memory_cell(0) == 2)
		set_mobility(ME,0);
	if (get_attitude(ME) >= 10)
		alert_char(ME);
break;

beginstate DEAD_STATE;
	
	message_dialog("The Vampiress collapses. She lies still for a minute and the fades away. She leaves a ring behind on the floor.","");
	erase_char(ME);
	set_flag(3,1,1);
	award_party_xp(50,100);
	change_spec_item(2,1);
break;

beginstate START_STATE; 
	if (get_attitude(ME) >= 10)
		alert_char(ME);
	
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 17)
			set_state(3);
		else set_target(ME,-1);
		}
	
	// Look for a target, attack it if visible
	if (select_target(ME,8,0)) {
		do_attack();
		set_state(3);
	}
	
	// Have I been hit? Strike back!
	if (who_hit_me() >= 0) {
		set_target(ME,who_hit_me());
		do_attack();
		set_state(3);
	}
	
	// Otherwise, just peacefully move around. Go back to start, if I'm too far
	// from where I started.
	if (my_dist_from_start() >= 6) {
		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
	
healthgap = get_max_health(ME) - get_health(ME);
buddy = random_group_member(1);

if(get_health(ME) == get_max_health(ME)){
	end();
	}
	else{
		if(num_chars_in_group(1) > 1){
			damage_char(buddy,healthgap,4);
			print_big_str("Vampiress healed for ", healthgap, " hitpoints");
			heal_char(ME,healthgap);
			put_sparkles_on_char(ME,24,5);
			run_animation();
			}
		}
	
	if(enemies_nearby(10) >= 1){
		if(tick_difference(last_abil_time,get_current_tick()) >= 1){
			atarget = 0;
			whom = get_ran(1,1,2);
			type = get_ran(1,1,3);
			while(atarget <= 120 && whom == 1){
				if(char_ok(atarget) == TRUE){
					if(can_see_loc(char_loc_x(atarget),char_loc_y(atarget)) == TRUE){
						if((get_attitude(ME) < 4 && get_attitude(atarget) < 4) || (get_attitude(ME) >= 8 && get_attitude(atarget) >= 10)){
							if(type == 1){
								put_effect_on_char(atarget,8,1,2);
								set_char_status(atarget,1,50,1,0);
								deduct_ap(1);
							}
							if(type == 2){
								put_effect_on_char(atarget,9,1,2);
								set_char_status(atarget,2,50,1,0);
								deduct_ap(1);	
							}
							if(type == 3){
								put_effect_on_char(atarget,10,1,2);
								set_char_status(atarget,3,50,1,0);
								deduct_ap(1);
							}
						}
					}
				}
				atarget = atarget + 1;
			}
		}
	}
	if(whom == 1){
		if(type == 1){
			run_animation_sound(4);
			print_str_color("The Vampiress blesses her minions!",5);
		}
		if(type == 2){
			run_animation_sound(28);
			print_str_color("The Vampiress shields her minions!",4);
		}
		
	}
	if(whom == 2){
		if(type == 1){
			run_animation_sound(46);
			print_str_color("The Vampiress blasts you!",5);
			put_jagged_zap(my_loc_x(),my_loc_y(),char_loc_x(i),char_loc_y(i),0);
			pause(2);
			put_jagged_zap(my_loc_x(),my_loc_y(),char_loc_x(i),char_loc_y(i),0);
			pause(2);
			put_jagged_zap(my_loc_x(),my_loc_y(),char_loc_x(i),char_loc_y(i),0);
			set_character_pose(ME,1);
			run_animation();
			force_instant_terrain_redraw();
			pause(2);
			set_character_pose(ME,2);
			force_instant_terrain_redraw();
			damage_char(i,10,0);
			deduct_ap(2);
			activate_hidden_group(1);
			
			
			
			last_abil_time = get_current_tick();
		}
	}
	
	
break;


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