
#ScriptVersion[3]
#Title["YaorochiS2"]
#Text[""]
#Player[DEFAULT]
#System["./system/Default_System.txt"]
#Background["./bg-klong.txt"]
#include"./Functions/Index.txt"
#include"./SetBoss.txt"
#include"./Shot/JINXShot_Const.txt"
#include"./system/Default_Effect.Txt"

let objBoss;
//let objBossIyo;
let GCSD=GetCurrentScriptDirectory~"";
let enemy;
let bSpell=false;
let stgx=GetStgFrameWidth()/2;
let stgy=GetStgFrameHeight()/2;
let idle = true;
let atk = false;
let fog = 0;
let action = false;
let objScene=GetEnemyBossSceneObjectID();
let dir=GetCurrentScriptDirectory();
let obj=ObjEnemyBossScene_Create();
let color = [276,277,278];
let color2 = [51,53,55];
let dcolor = [308,309,310];
@Initialize
{
SetBoss("Doremy",true);
//SetBossIyo("Doremy",true);
SetCommonData("Life",1);
GetCommonData("SPback",0);
SetCommonData("LenenSpellcut",[70,100,70]);
SetCommonData("SpellBarcl",[70,100,70]);
SetCommonData("Boss",0);
SetCommonData("CutChar",GCSD ~ "./Functions/booss/senri_09.png");
mainTask;
}

@MainLoop
{
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),18);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),26);
	yield;

}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(600);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(70);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(500000);
	}
}

//----------------------------------------------------
task mainTask{
	SetCommonData("ForceLifebar",1);
	//SetCommonData("FORCE_HITBOX",true);
	StartCountDown;
	PlaySound("SpellStart",100,0);
	wait( 30 );
	ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2,120,10,20);
	wait( 50 );
	TShot1;
	wait( 420 + 80 );
	Cutin("Mythocidal Sword \"A Serpent's Round Table\"",16,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	wait( 210 );
	SetCommonData("ForceLifebar",0);
	DamageRateAtFrame(5,50,0);
	}
	
//----------------------------------------------------
let center_a = [];
let center_sw = [];
let grand_angle = rand( 0, 360 );
let grand_way = 12;
task TShot1
{
	ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2,50,50,0.165);
	PlaySound("Boon1",92,0);
	PlaySound("LenenLaserDelayLong",92,0);
	let sht = CreateShotA2( ObjMove_GetX( objBoss ), ObjMove_GetY( objBoss ), 0, 0, 0, 0, 1, 0 );
	warpmove( sht );
	ObjShot_SetSpellResist( sht, true );
	ObjShot_SetAutoDelete( sht, false );
	ObjShot_SetIntersectionEnable( sht, false );
	ObjRender_SetAlpha( sht, 0 );
	let barrier = MakeBarrierEffect_Ring( sht, 60, 255, 140 );
	SetRing( barrier );
	center( grand_angle, grand_way );
	center_s( grand_angle, grand_way );
	wait( 400 );
	let way = 9;
	let angle = rand( 0, 360 );
	//sub_bullet;
	//TrapOperate;
	loop( way ){
		sub_slash( 384/2, 448/2, angle );
		angle += 360/way;
		wait( 3 );
	}
	wait( 330 );
	repeat_stab;
}

	task warpmove( obj ){
		wait( 60 );
		ObjMove_SetDestAtWeight( obj, 384/2, 448/2, 10, 20 );
	}

	task SetRing( obj ){
		let ring = 400;
		let size = 22;
		ObjBarrier_SetOuterRadius( obj, ring );
		ObjBarrier_SetInnerRadius( obj, ring - size );
		wait( 65*4.5 );
		ring -= 25;
		while( ring > 125 ){
			if( GetDistance( GetPlayerX, GetPlayerY, 384/2, 448/2 ) > ring - size ){
				let angle = GetDotAngle( GetPlayerX, GetPlayerY, 384/2, 448/2 );
				ObjMove_SetPosition( GetPlayerObjectID, 384/2 + ( ring - size )*cos( angle ), 448/2 + ( ring - size )*sin( angle ));
			}
			ObjBarrier_SetOuterRadius( obj, ring );
			ObjBarrier_SetInnerRadius( obj, ring - size );
			ring -= 0.75*4;
			yield;
		}
		while( !Obj_IsDeleted( objBoss )){
			while( GetDistance( GetPlayerX, GetPlayerY, 384/2, 448/2 ) <= ring - size ){ wait( 2 ); }
			while( GetDistance( GetPlayerX, GetPlayerY, 384/2, 448/2 ) > ring - size ){
				let angle = GetDotAngle( GetPlayerX, GetPlayerY, 384/2, 448/2 );
				ObjMove_SetPosition( GetPlayerObjectID, 384/2 + ( ring - size )*cos( angle ), 448/2 + ( ring - size )*sin( angle ));
				wait( 2 );
			}
		}
	}

	task TrapOperate{
		let radius = 100;
		PlaySound("LenenLaserDelayLong",92,0);
		let barrier = MakeBarrierEffect_Ring( objBoss, 80, 200, 0 );
		ObjBarrier_SetOuterRadius( barrier, radius );
		ObjBarrier_SetInnerRadius( barrier, 0 );
		wait( 80 );
		Trap( radius );
	}
	
	    task Trap( radius ){ 
              while( !Obj_IsDeleted( objBoss )){
              while( GetDistance( GetPlayerX, GetPlayerY, ObjMove_GetX( objBoss ), ObjMove_GetY( objBoss )) > radius ){ yield; }
              while( GetDistance( GetPlayerX, GetPlayerY, ObjMove_GetX( objBoss ), ObjMove_GetY( objBoss )) < radius ){

			let shote = 49;
	                                	let way = 1;
			let delay = 5;
			let angle = rand( 0, 360 );
			let angle2 = angle + 90 + rand( -60, 60 );

			loop( way ){

				let r = -500;
				let r2 = -150;
              				let sx = GetPlayerX + r*cos( angle );
              				let sy = GetPlayerY + r*sin( angle );
              				let sx2 = GetPlayerX + r2*cos( angle2 );
              				let sy2 = GetPlayerY + r2*sin( angle2 );
				
				ProperLaser( sx, sy, angle, 1000, 20, 20, shote );
				ProperLaser( sx2, sy2, angle2, 300, 15, 20, shote );

				angle += 360 / way;


			}
			PlaySound("trap",92,0);
			wait( 30 );

	}
			yield;

	}
}

	task repeat_stab{
		let t = 160;
		while( !Obj_IsDeleted( objBoss )){
			if( t < 110 ){ t = 110; }
			let a = floor( rand( 0, length( center_sw ) ) );
			//WriteLog( a );
			let select = center_sw[ a ];
			center_sw = erase( center_sw, a );
			s_stab( select, a );
			t -= 8;
			wait( t );
		}
	}
	
	function Array_Insert(base_array, new_array, index){
		index = min(length(base_array) - 1, index);
    
		return (base_array[0..index] ~ new_array ~ base_array[index..length(base_array)-1]);
	}

	task s_stab( obj, a ){
		P_Concentrate( obj, 49 );
		wait( 70 );
		stab_1( obj );
		stab( obj );
	}
	

	task stab_1( obj ){ 
		wait( 19 );
		loop( 2 ){
			let angle = rand( 0, 360 );
			//let angle = ObjStLaser_GetAngle( obj );
			let way = 12;
			let shote = 17;
			let delay = 0;
			let speed = 10;
			let sx = ObjMove_GetX( obj ) + ( ObjLaser_GetLength( obj ) - 20 )*cos( ObjStLaser_GetAngle( obj ) );
			let sy = ObjMove_GetY( obj ) + ( ObjLaser_GetLength( obj ) - 20 )*sin( ObjStLaser_GetAngle( obj ) );
			//let sx = 384/2;
			//let sy = 448/2;

			loop( way ){
				
				let sht = TShotA2( sx, sy, 0, angle, 0.005, speed, shote, delay );
				eff_scale02( sht );
				eff_alpha02( sht );
				//ObjShot_SetSpellResist( sht, true );
				//ObjShot_SetAutoDelete( sht, false );

				angle += 360 / way;
			}
			PlaySound("LenenShot1",92,0);
			PlaySound("BulletWave",92,0);
			wait( 30 );
		}
	}	
	
	task stab( obj ){ //normal length 160
		let a = 0;
		while( a < 90 ){
			ObjLaser_SetLength( obj, 160 + sin( a )*290 );
			a += 2;
			yield;
		}
		wait( 60 );
		while( a > 0 ){
			ObjLaser_SetLength( obj, 160 + sin( a )*290 );
			a -= 2;
			yield;
		}
		center_sw = center_sw ~ [ obj ];
		ObjLaser_SetLength( obj, 160 );
	}

	task P_Concentrate( obj, shot ){
		let way = 16;
		let angle = rand( 0, 360 );
		PlaySound("Eff2",92,0);
		loop(way){
			let a = round(rand(0,1));
			SetConcentrateEffect_Track(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),obj,rand( 130, 200 ),shot,2,[angle, angle + 180],rand( 4, 8 ),80,70,1);
			angle += 360/way;
		}
	}
		
task SetConcentrateEffect(sx,sy,ex,ey,move_range,graphic,iniScale,iniAngle,angle_add,max_alpha,timer,eff_count){
	let tmp_obj = ObjText_Create();
	ObjRender_SetPosition(tmp_obj,ex,ey,1);
	loop(eff_count){
		ChargeEffect_concentrate(sx,sy,tmp_obj,move_range,graphic,iniScale,rand(iniAngle[0],iniAngle[1]),angle_add,max_alpha,timer);
	}
	Obj_Delete(tmp_obj);
}
task SetConcentrateEffect_Track(sx,sy,objTarget,move_range,graphic,iniScale,iniAngle,angle_add,max_alpha,timer,eff_count){
	loop(eff_count){
		ChargeEffect_concentrate(sx,sy,objTarget,move_range,graphic,iniScale,rand(iniAngle[0],iniAngle[1]),angle_add,max_alpha,timer);
	}
}

task ChargeEffect_concentrate(sx,sy,objTarget,move_range,graphic,iniScale,iniAngle,angle_add,max_alpha,timer){
	let ID = CreateShotA1(sx,sy,0,0,graphic,0);
	ObjRender_SetBlendType(ID,BLEND_ADD_ARGB);
	ObjShot_SetDeleteFrame(ID,timer+30);
	ObjShot_SetSpellResist(ID,1);
	ObjShot_SetIntersectionEnable(ID,0);
	ObjShot_SetAutoDelete(ID,0);
	ObjRender_SetScaleXYZ(ID,iniScale,iniScale,1);
	
	let muki = (-1)^(rand(0,1)>0.5);
	ObjRender_SetAlpha(ID,max_alpha);
	let tmp_al = 1;
	
	let before_x = sx;
	let before_y = sy;
	
	let dir_angle = iniAngle;
	
	let add_angle = angle_add;
	
	let ex = ObjRender_GetX(objTarget);
	let ey = ObjRender_GetY(objTarget);
	
	ascent(i in 0..timer){
		if(Obj_IsDeleted(ID)){break;}
		
		let tmp_a = iniAngle + i * add_angle * muki;
		let tmp = (1-cos((i+1)/timer*180))/2;
		
		if(!Obj_IsDeleted(objTarget)){
			ex = ObjRender_GetX(objTarget);
			ey = ObjRender_GetY(objTarget);
		}
		
		let cx = sx*(1-tmp)+ex*tmp;
		let cy = sy*(1-tmp)+ey*tmp;
		
		let tmp_r = (1-cos((i+1)/timer*360))/2;
		let tmp_x = cx + (tmp_r * move_range) * cos(tmp_a);
		let tmp_y = cy + (tmp_r * move_range) * sin(tmp_a);
		
		dir_angle = atan2(tmp_y-before_y,tmp_x-before_x);
		
		before_x = tmp_x;
		before_y = tmp_y;
		
		ObjMove_SetPosition(ID,tmp_x,tmp_y);
		ObjRender_SetAngleZ(ID,dir_angle);
		
		if(i>timer-10){
			tmp_al = 1-((i-(timer-10)+1)/10);
			//ObjRender_SetAlpha(ID,0);
			ObjRender_SetAlpha(ID,tmp_al*(max_alpha));
		}
		
		if(1){
			Charge_ShotEffect(tmp_x,tmp_y,tmp_al,10);
		}
		yield;
	}
	Obj_Delete(ID);
	
	task Charge_ShotEffect(x,y,iniAlpha,iniTimer){
		let ID_E = CreateShotA1(x,y,0,0,graphic,0);
		ObjRender_SetBlendType(ID_E,BLEND_ADD_ARGB);
		ObjShot_SetDeleteFrame(ID_E,iniTimer);
		ObjShot_SetSpellResist(ID_E,1);
		ObjShot_SetIntersectionEnable(ID_E,0);
		ObjShot_SetAutoDelete(ID_E,0);
		ObjRender_SetScaleXYZ(ID_E,iniScale,iniScale,1);
		ObjRender_SetAngleZ(ID_E,dir_angle);
		descent(i in 0..iniTimer){
			let tmp = (i+1)/iniTimer;
			ObjRender_SetAlpha(ID_E,tmp*iniAlpha*max_alpha);
			yield;
		}
		Obj_Delete(ID_E);
	}
}

        task sub_slash( x, y, angle ){ 
	        let way = 2;
            let shote = 145;
			let delay = 60;

			loop( way ){
				let r = -60;
				let sx = x + r*cos( angle );
				let sy = y + r*sin( angle );
				
				HLaser( sx, sy, angle, 900, 20, 210, shote, delay );

				angle += 360 / way;
			}
			PlaySound("LenenShot1",92,0);
		}
		
	task sub_bullet{ 
		wait( 300 );
		while( !Obj_IsDeleted( objBoss )){
			let angle = rand( 0, 360 );
			let way = 22;
			let shote = 33;
			let delay = 20;
			let speed = 0.8;

			loop( way ){

				let sx = 384/2;
				let sy = 448/2;
				
				let sht = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				ObjShot_SetSpellResist( sht, true );
				ObjShot_SetAutoDelete( sht, false );

				angle += 360 / way;
			}
			PlaySound("LenenShot1",92,0);
			wait( 90 );
		}
	}	
	
	task center( grand_angle, grand_way ){ 
		let way = 1;
		let shote = 1;
		let delay = 0;
		let angle = rand( 0, 360 );

		loop( way ){

			let sx = 384/2;
			let sy = -200;
				
			let sht = TShotA2( sx, sy, 0, angle, 0, 0, shote, delay );
			Pwait( sht );
			dummy( sht, grand_angle, grand_way );
			ObjShot_SetSpellResist( sht, true );
			ObjShot_SetAutoDelete( sht, false );
			ObjShot_SetIntersectionEnable( sht, false );
			ObjRender_SetAlpha( sht, 0 );

			angle += 360 / way;
		}
		//PlaySound("LenenShot1",92,0);
	}
	
	task Pwait( sht ){
		wait( 190 + 100 );
		ObjMove_SetDestAtWeight( sht, 384/2, 448/2, 20, 10 );
	}
	
	task dummy( obj, angle, way ){ 
		let shote = 1;
		let delay = 0;

		loop( way ){

			let sx = ObjMove_GetX( obj );
			let sy = ObjMove_GetY( obj );
				
			let sht = TShotA2( sx, sy, 0, angle, 0, 0, shote, delay );
			center_a = center_a ~ [ sht ];
			c_dummy( obj, sht, angle );
			ObjShot_SetSpellResist( sht, true );
			ObjShot_SetAutoDelete( sht, false );
			ObjShot_SetIntersectionEnable( sht, false );
			ObjRender_SetAlpha( sht, 0 );

			angle += 360 / way;
		}
		//PlaySound("LenenShot1",92,0);
	}
	
	task c_dummy_s( objt, obj, angle ){
		let R = 330;
		let r = 0;
		let a = 0.3;
		while( r < 90 ){
			ObjMove_SetPosition( obj, ObjMove_GetX( objt ) + sin( r )*R*cos( angle ), ObjMove_GetY( objt ) + sin( r )*R*sin( angle ));
			r += a;
			angle += 0.5;
			yield;
		}
		a = 1;
		while( a > 0 ){ 
			ObjMove_SetPosition( obj, ObjMove_GetX( objt ) + R*cos( angle ), ObjMove_GetY( objt ) + R*sin( angle ));
			angle += a;
			a -= 0.01;
			yield;
		}
		wait( 20 );
		wait( 210 );
		wait( 80 );
		a = 0;
		while( a < 0.48 ){ 
			ObjMove_SetPosition( obj, ObjMove_GetX( objt ) + R*cos( angle ), ObjMove_GetY( objt ) + R*sin( angle ));
			angle += a;
			a += 0.0005;
			yield;
		}
		while( !Obj_IsDeleted( objBoss ) ){ 
			ObjMove_SetPosition( obj, ObjMove_GetX( objt ) + R*cos( angle ), ObjMove_GetY( objt ) + R*sin( angle ));
			angle += 0.48;
			yield;
		}
	}
	
	task center_s( grand_angle, grand_way ){ 
		let way = 1;
		let shote = 1;
		let delay = 0;
		let angle = rand( 0, 360 );

		loop( way ){

			let sx = ObjMove_GetX( objBoss );
			let sy = ObjMove_GetY( objBoss );
				
			let sht = TShotA2( sx, sy, 0, angle, 0, 0, shote, delay );
			ObjMove_SetDestAtWeight( sht, 384/2, 448/2, 70, 4 );
			dummy_s( sht, grand_angle, grand_way );
			ObjShot_SetSpellResist( sht, true );
			ObjShot_SetAutoDelete( sht, false );
			ObjShot_SetIntersectionEnable( sht, false );
			ObjRender_SetAlpha( sht, 0 );

			angle += 360 / way;
		}
		//PlaySound("LenenShot1",92,0);
	}
	
	task dummy_s( obj, angle, way ){ 
		let shote = 89;
		let delay = 0;

		ascent( i in 0..way ){

			let sx = ObjMove_GetX( obj );
			let sy = ObjMove_GetY( obj );
				
			let sht = CreateStraightLaserA1( sx, sy, angle, 160, 70, 100000, shote, 0 );
			open_s( sht, 70 );
			ObjLaser_SetIntersectionWidth( sht, 20 );
			//CreateSlash_S( sht, sx, sy, 160, 70 );
			center_sw = center_sw ~ [ sht ];
			control_angle( sht, i );
			c_dummy_s( obj, sht, angle );
			ObjShot_SetSpellResist( sht, true );
			ObjShot_SetAutoDelete( sht, false );
			//ObjRender_SetAlpha( sht, 0 );

			angle += 360 / way;
		}
		//PlaySound("LenenShot1",92,0);
	}
	
	task open_s( obj, width ){
		let scale = 1;
		ascent( i in 0*scale..width*scale ){
			ObjLaser_SetRenderWidth( obj, i/scale );
			yield;
		}
		ObjLaser_SetRenderWidth( obj, width );
	}
	
	task CreateSlash_S( objLaser, s_x, s_y, s_len, s_wid ){
	
	let s_angle = 270;
	
	ObjStLaser_SetSource(objLaser, false);
	
	let s_timer = 190;	//Starting phase duration (adjustable)
	
	let c = cos(s_angle);
	let s = sin(s_angle);
	
	ascent(i in 0..s_timer){
		let tmp = sin((i+1)/s_timer*90);
		
		Update(2.5 - tmp * 1.5, tmp);
	}
	
	function Update(rl, rw){
		let tmp_l = rl * s_len;
		let tmp_w = rw * s_wid;
		
		let inv_l = max(0, rl - 1) * 50 + 10;
		
		ObjLaser_SetInvalidLength(objLaser, inv_l, inv_l);
		
		ObjMove_SetPosition(objLaser, s_x - c * tmp_l / 2, s_y - s * tmp_l / 2);
		
		ObjLaser_SetLength(objLaser, tmp_l);
		ObjLaser_SetRenderWidth(objLaser, tmp_w);
		ObjLaser_SetIntersectionWidth(objLaser, tmp_w * 0.8);
	
		yield;
	}
}
	
	task c_dummy( objt, obj, angle ){
		let R = 330;
		let r = 0;
		let a = 0.3;
		while( r < 90 ){
			ObjMove_SetPosition( obj, ObjMove_GetX( objt ) + sin( r )*R*cos( angle ), ObjMove_GetY( objt ) + sin( r )*R*sin( angle ));
			r += a;
			angle += 0.5;
			yield;
		}
		a = 1;
		while( a > 0 ){ 
			ObjMove_SetPosition( obj, ObjMove_GetX( objt ) + sin( r )*R*cos( angle ), ObjMove_GetY( objt ) + sin( r )*R*sin( angle ));
			r -= 0.9;
			angle += a;
			a -= 0.01;
			yield;
		}
		r = 0;
		wait( 20 );
		wait( 210 );
		wait( 80 );
		let G = sin( r )*R;
		a = 0;
		while( a < 0.48 ){ 
			ObjMove_SetPosition( obj, ObjMove_GetX( objt ) + G*cos( angle ), ObjMove_GetY( objt ) + G*sin( angle ));
			angle += a;
			a += 0.0005;
			yield;
		}
		while( !Obj_IsDeleted( objBoss ) ){ 
			ObjMove_SetPosition( obj, ObjMove_GetX( objt ) + G*cos( angle ), ObjMove_GetY( objt ) + G*sin( angle ));
			angle += 0.48;
			yield;
		}
	}

	task control_angle( obj, i ){
		while( !Obj_IsDeleted( objBoss )){
			ObjStLaser_SetAngle( obj, GetDotAngle( ObjMove_GetX( center_a[ i ] ), ObjMove_GetY( center_a[ i ] ), ObjMove_GetX( obj ), ObjMove_GetY( obj ) ) );
			yield;
		}
	}

task CreateSlash(s_x, s_y, s_angle, s_len, s_wid, s_graphic){
	let objLaser = CreateStraightLaserA1(0, 0, s_angle, 0, 0, 99999, s_graphic, 0);
	
	ObjShot_SetAutoDelete(objLaser, false);
	ObjShot_SetSpellResist(objLaser, true);
	
	ObjStLaser_SetSource(objLaser, false);
	
	let s_timer = 30;	//Starting phase duration (adjustable)
	let e_timer = 20;	//Ending phase duration (adjustable)
	
	let c = cos(s_angle);
	let s = sin(s_angle);
	
	ascent(i in 0..s_timer){
		let tmp = sin((i+1)/s_timer*90);
		
		Update(2.5 - tmp * 1.5, tmp);
	}
	descent(i in 0..e_timer){
		let tmp = (i + 1) / e_timer;
		
		Update(1, tmp);
	}
	
	Obj_Delete(objLaser);
	
	function Update(rl, rw){
		let tmp_l = rl * s_len;
		let tmp_w = rw * s_wid;
		
		let inv_l = max(0, rl - 1) * 50 + 10;
		
		ObjLaser_SetInvalidLength(objLaser, inv_l, inv_l);
		
		ObjMove_SetPosition(objLaser, s_x - c * tmp_l / 2, s_y - s * tmp_l / 2);
		
		ObjLaser_SetLength(objLaser, tmp_l);
		ObjLaser_SetRenderWidth(objLaser, tmp_w);
		ObjLaser_SetIntersectionWidth(objLaser, tmp_w * 0.8);
	
		yield;
	}
}


	task OrbSnake{ 
		while( !Obj_IsDeleted( objBoss )){
			let way = 1;
			let shote = 129;
			let delay = 0;
			let angle = rand( 180, 360 );

			loop( way ){
		
				let ux = rand( 1, 2 )*cos( angle );
				let uy = -rand( 1, 2 )*sin( angle );

				let sx = ObjMove_GetX( objBoss ) + 100*cos( angle );
				let sy = ObjMove_GetY( objBoss ) + 100*sin( angle );
				
				let sht = TShotA2( sx, sy, rand( 6, 10 ), angle, -0.5, 1, shote, delay );
				//ObjRender_SetColor( sht, 0, 0, 0 );
				eff_scale02( sht );
				eff_alpha02( sht );
				ObjShot_SetSpellResist( sht, true );
				ObjMove_AddPatternB2( sht, 0 , ux, uy, 0, rand( -0.01, -0.015 ), 9, -9 );

				angle += rand( -360, 360 ) / way;
			}
			PlaySound("LenenShot3",92,0);
			wait( 4 );
		}
	}
	
	task Snake{
		while( !Obj_IsDeleted( objBoss )){
			PatternSnake;
			wait( rand( 150, 200 ) );
		}
	}

    task PatternSnake{ 
        let sx = rand( 10, GetStgFrameWidth - 10 );
        let sy = -5;
        let angle = GetDotAngle( GetPlayerX, GetPlayerY, sx, sy );
		let a = round( rand( 0, 1 ));
		let select = [ 55, -55 ];
        loop( 15 ){
		
            let speed = 3.5;
	        let way = 1;
            let shote = 113;
			let delay = 10;

			loop( way ){
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				SpeedUn( sht1 );
				ObjShot_SetSpellResist( sht1, true );
				SnakeWave( sht1, angle, select[ a ], 10 );

				angle += 360 / way;
			
			}
			PlaySound("LenenShot1",92,0);
			wait( 6 );
	}
   }
   
	task SpeedUn( obj ){
		let a = 0;
		while( !Obj_IsDeleted( obj )){
			ObjMove_SetSpeed( obj, 3.5 + sin( a ) );
			a += 6;
			yield;
		}
	}

task SnakeWave2(obj,angle,amplitude,omega)
{
   let count = 0;
   while(!Obj_IsDeleted(obj))
   {
         ObjMove_SetAngle(obj,angle+amplitude*sin(count*omega));
         count += 1;
         wait( 2 );
   }
}
	
	task eff_scale02( obj ){
		descent( i in 4..3*4 ){ 
			ObjRender_SetScaleXYZ( obj, i/4, i/4, 0 );
			yield;
		}
	}
	
	task eff_alpha02( obj ){
		ascent( i in 0..255/25 ){
			ObjRender_SetAlpha( obj, i*25 );
			yield;
			}
		//Obj_Delete( obj );
	}
	
	task eff_scale01( obj ){
	ascent( i in 10..3*10 ){
		if( Obj_IsDeleted( obj )){ break; }
		ObjRender_SetScaleXYZ( obj, i/10, i/10, 0 );
		yield;
		}
	}
	
	task eff_alpha01( obj ){
	descent( i in 0..255/25 ){
		ObjRender_SetAlpha( obj, i*25 );
		yield;
		}
	Obj_Delete( obj );
	}
	
	task HLaser( sx, sy, angle, length, width, duration, shote, delay ){
		ProperLaserDelay( sx, sy, angle, length, delay, shote );
		wait( delay );
		PlaySound("LenenLaserShort",92,0);
		ProperLaser( sx, sy, angle, length, width, duration, shote );
	}

	task ProperLaserDelay( sx, sy, angle, length, delay, shote ){
		let sht0 = CreateStraightLaserA1( sx, sy, angle, length, 4, delay, shote, 0 );
		Opening2( sht0, length );
		ObjShot_SetIntersectionEnable( sht0, false );
		wait( delay );
		Obj_Delete( sht0 );
	}

	task Opening2( obj, length ){
		ascent( i in 0..length/20 ){
			ObjLaser_SetLength( obj, i*20 );
			yield;
		}
	}

	task ProperLaser( sx, sy, angle, length, width, duration, shote ){
		let sht1 = CreateStraightLaserA1( sx, sy, angle, length, width, duration + 120, shote, 0 );
		//ObjRender_SetBlendType( sht1, BLEND_INV_DESTRGB );
		ObjLaser_SetGrazeInvalidFrame( sht1, 5 );
		wait( duration );

		ObjShot_SetIntersectionEnable( sht1, false );
		descent( i in 0..width/3 ){
			ObjLaser_SetRenderWidth( sht1, i*3 );
			wait( 2 );
		}
		Obj_Delete( sht1 );
	}
	   
   	function GetDotAngle( x1, y1, x2, y2 ){
		let angle=atan2( y1 - y2, x1 - x2 );
		return angle;
	}

	task StartCountDown
	{
		wait((70*60) - (10*60));
		loop(10)
		{
			PlaySound("time",100,0);
			wait(60);
		}

	}

task SnakeWave(obj,angle,amplitude,omega)
{
   let count = 0;
   while(!Obj_IsDeleted(obj))
   {
         ObjMove_SetAngle(obj,angle+amplitude*sin(count*omega));
         count += 1;
         wait( 2 );
   }
}

	
//----------------------------------------------------

task TEnd{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
		EndBoss(1);
		DeleteShotAll(TYPE_ALL,TYPE_FADE);
		yield;
		CloseScript(GetOwnScriptID());
	}