// aenpylon.txt
// A pylon that occasionally beams a beneficial AE to allies

// Memory Cells:
//   Cell 0 - Unused
//   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.
//   Cell 5 - The range of the ae, defaults to 6

// The abilities:
// 0 - AE Bless
// 1 - AE Heal
// 2 - AE Speed

begincreaturescript;

variables;

short i,target;
short last_abil;
short used_abil = 0;
short ae_range = 6;

body;

beginstate INIT_STATE;
	set_walk_speed(ME,0);
	last_abil = get_current_tick();
	if (get_memory_cell(5) != 0)
		ae_range = get_memory_cell(5);
	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))
		inc_flag(get_memory_cell(1),get_memory_cell(2),1);
break;

beginstate START_STATE; 
	get_foe_target(ME,10,0);

	if (target_ok() == FALSE) {
		turret_heal();
		end();
		}
	used_abil = 0;

	if ((get_ran(1,0,100) < 50) && (is_combat()) && (can_see_char(get_target())) &&  (tick_difference(last_abil,get_current_tick()) > 2)) {
		run_char_animation(2,1,35);	
		if (get_memory_cell(4) == 0) { // AE Bless
			print_named_str(ME,"radiates a blessing glow.");
			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(15);
			used_abil = 1;
			}
		if (get_memory_cell(4) == 1) { // AE Heal
			print_named_str(ME,"radiates healing energy.");
			particle_nearby(8,3,1,3,8);
	  		heal_nearby(get_ran(get_level(ME),1,5),8,3);
			run_char_animation(2,1,35);	
			pc_heard_sound_delay(120,100);						
			deduct_ap(15);
			used_abil = 1;
			}
		if (get_memory_cell(4) == 2) { // AE Haste
			print_named_str(ME,"radiates an energetic glow.");
			status_nearby(8,8,1,3);
			particle_nearby(8,3,0,3,8);
			run_char_animation(2,1,35);	
			pc_heard_sound_delay(101,100);	
			deduct_ap(15);
			used_abil = 1;
			}

		last_abil = get_current_tick();
		}
break;

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