// goblinpunch.txt
//
// by Jeremy "Terror's Martyr" LeVeque
//
// This script is a totally random attack!
// It does random damage from 1 to 250
// of a random type to a random target.
// 
// Cell 0 - How Many Punches Plus 1, TIMES TWO
// (Meaning, if you set cell 0 to be 1, then
// there will be four punches.  Setting it to
// 2 results in 6, etc.)

begincreaturescript;

variables;

short poink,px,py,mx,my,ok,gc,last_abil_time;

body;

beginstate INIT_STATE;
	break;

beginstate DEAD_STATE;
	if ((get_memory_cell(1) != 0) || (get_memory_cell(2) != 0))
		set_flag(get_memory_cell(1),get_memory_cell(2),1);
	break;

beginstate START_STATE; 

if(tick_difference(last_abil_time,get_current_tick()) >= 1){

gc = get_memory_cell(0) + 1;

ok = 0;

if(enemies_nearby(10) == 0)
	end();

while(ok < gc){

	poink = get_ran(1,0,120);
	if (char_ok(poink)) {
		px = char_loc_x(poink);
		py = char_loc_y(poink);

		if(can_see_loc(px,py) == 1 && get_attitude(poink) != get_attitude(ME)){
			text_bubble_on_char(ME,"Goblin Punch!");
			force_instant_terrain_redraw();
			pause(5);
			
			text_bubble_on_char(ME,"");
			mx = my_loc_x();
			my = my_loc_y();
			put_straight_zap(mx,my,px,py,get_ran(1,0,6));
			put_boom_on_char(poink,get_ran(1,0,7),0);
			set_character_pose(ME,1);
			force_instant_terrain_redraw();
			run_animation_sound(152);
			damage_char(poink,get_ran(1,1,200),get_ran(1,0,6));
			pause(5);

			set_character_pose(ME,2);
			force_instant_terrain_redraw();
			pause(3);
			ok = ok + 1;
		}
	}
}

		last_abil_time = get_current_tick();

}

break;
