
#ScriptVersion[3]
#Title["TsurubamiS2"]
#Text["TsurubamiS2"]
#Player[DEFAULT]
#System["./system/Default_System.txt"]
#Background["./BG.txt"]
#include"./Functions/Index.txt"
#include"./SetBoss.txt"
#include"./Shot/AllStarShot_Const.dnh"
#include"./system/Default_Effect.Txt"


let objBoss;
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 color = [276,277,278];
let color2 = [51,53,55];
let dcolor = [308,309,310];
@Initialize
{
SetBoss("Doremy",true);
SetCommonData("Life",1);
SetCommonData("Bomb",1);
}

@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(1250);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(90);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(20000000);
	}
}

//----------------------------------------------------
task mainTask{
	StartCountDown;
	PlaySound("SpellStart",100,0);
	ObjMove_SetDestAtWeight(objBoss,stgx,stgy-80,10,7);
	Cutin("Splash Card 'Ink Rig'",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	wait( 175 );
	TShot1;
	DamageRateAtFrame(13,0,0);
	}
//----------------------------------------------------

task TShot1
{
	if( ObjEnemy_GetInfo( objBoss, INFO_LIFE ) == 1 ){ DeleteShotAll( TYPE_ALL, TYPE_IMMEDIATE ); }
	PatternLoop;

}
	task PatternLoop{
	while( !Obj_IsDeleted( objBoss )){
	PatternRig1;
	wait( 120 );
	PatternRig2;
	wait( 120 );
	PatternRig3;
	wait( 240 );
	PatternClear;
	wait( 330 );
	PatternRig4;
	wait( 140 );
	PatternRig5;
	wait( 70 );
	PatternRig55;
	wait( 120 );
	PatternRig6;
	wait( 170 );
	PatternClear;
	wait( 320 );
	}
	}

              task PatternClear{ 
              loop( 5 ){
              let angle = rand( 0, 360 );
              loop( 5 ){

	                                	let way = 22;
                                                	let shote = 97;
			let delay = 0;
			let speed = 1.2;

			loop( way ){

                      	                	let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, speed+6, angle, -1, speed, shote, delay );

				angle += 360/way;
			}
			angle += 2;
			PlaySound("LenenShot1",92,0);
                       		wait( 0 );

	}
			TMovement( 50, 10, 2 );
                       		wait( 45 );

	}

   }

             task PatternRig1{ 
             let angle = rand( 110, 120 );
             loop( 20 ){

                                                    let speed = 40;
	                                let way = 1;
                                                    let shote = 1016;
		            let delay = 0;

			loop( way ){

                      	                    let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				PatternRealRig( sx, sy, angle, 400, 40, shote, 7, 480 );

				angle += 360 / way;

			}
			angle += 10;
			wait( 2 );
	}
	}


             task PatternRig2{ 
             let angle = rand( 60, 70 );
             loop( 20 ){

                                                    let speed = 40;
	                                let way = 1;
                                                    let shote = 1016;
		            let delay = 0;

			loop( way ){

                      	                    let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				PatternRealRig( sx, sy, angle, 400, 40, shote, 7, 360 );

				angle += 360 / way;

			}
			angle -= 10;
			wait( 2 );
	}
	}


             task PatternRig3{ 
             let angle = GetAngleToPlayer( objBoss );
             loop( 4 ){

                                                    let speed = 40;
	                                let way = 1;
                                                    let shote = 1016;
		            let delay = 0;
		            let n = 7;
		            let t = 240;

			loop( way ){

                      	                    let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				PatternRealRig( sx, sy, angle + 10, 400, 60, shote, n, t );
				PatternRealRig( sx, sy, angle + 5, 400, 60, shote, n, t );
				PatternRealRig( sx, sy, angle, 400, 60, shote, n, t );
				PatternRealRig( sx, sy, angle - 5, 400, 60, shote, n, t );
				PatternRealRig( sx, sy, angle - 10, 400, 60, shote, n, t );

				angle += 360 / way;

			}
			wait( 10 );
	}
	}

             task PatternRig4{ 
             let angle = GetAngleToPlayer( objBoss ) + 360 / 2 / 2;
             loop( 30 ){

                                                    let speed = 40;
	                                let way = 2;
                                                    let shote = 1016;
		            let delay = 0;

			loop( way ){

                      	                    let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				PatternRealRig( sx, sy, angle, 400, 40, shote, rand( 1, 2 ), 500 );

				angle += 360 / way;

			}
			angle -= 8;
			wait( 2 );
	}
	}

             task PatternRig5{ 
             TMovement( 160, 10, 6 );
             loop( 6 ){

             		            let angle = GetAngleToPlayer( objBoss );
                                                    let speed = 40;
	                                let way = 4;
                                                    let shote = 1016;
		            let delay = 0;

			loop( way ){

                      	                    let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				PatternRealRig( sx, sy, angle, 400, 60, shote, rand( 1, 2 ), 360 );

				angle += 360 / way;

			}
			wait( 8 );
	}
	}

            task PatternRig55{ 
             ObjMove_SetDestAtWeight( objBoss, stgx + rand( -20, 20 ), stgy - 80, 6, 5 );
             loop( 6 ){

             		            let angle = GetAngleToPlayer( objBoss );
                                                    let speed = 40;
	                                let way = 4;
                                                    let shote = 1016;
		            let delay = 0;

			loop( way ){

                      	                    let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				PatternRealRig( sx, sy, angle, 400, 60, shote, rand( 1, 2 ), 290 );

				angle += 360 / way;

			}
			wait( 8 );
	}
	}

             task PatternRig6{ 
             let angle1 = 0;
             let angle2 = 180;
             loop( 20 ){

                                                    let speed = 40;
	                                let way = 2;
                                                    let shote = 1016;
		            let delay = 0;

			loop( way ){

                      	                    let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				PatternRealRig( sx, sy, angle1, 400, 60, shote, 2, 170 );
				PatternRealRig( sx, sy, angle2, 400, 60, shote, 2, 170 );

				angle1 += 360 / way;
				angle2 += 360 / way;

			}
			angle1 -= 16;
			angle2 += 16;
			wait( 4 );
	}
	}

	

             task PatternRealRig( sx, sy, angle, length, delay, shote, n, t ){ 
	WarningRig( sx, sy, angle, length, delay, shote );
	wait( delay );
	PatternDelayRig( sx, sy, angle, n, t );
	}


             task PatternDelayRig( sx, sy, angle, n, t ){ 
             loop( 1 ){

                                                    let speed = 40;
	                                let way = 1;
                                                    let shote = 129;
		            let delay = 0;

			loop( way ){
				
				let sht1 = CreateLooseLaserA1( sx, sy, speed, angle, 150, 18, shote, delay );
				ObjRender_SetBlendType( sht1, BLEND_ALPHA );
				ObjRender_SetColor( sht1, 0, 0, 0 );
				Rig( sht1, n, t );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle += 360 / way;

			}
	}
	}

	task WarningRig( sx, sy, angle, length, delay, shote ){
	let sht0 = CreateStraightLaserA1( sx, sy, angle, length, 4, delay, shote, 0 );
	ObjShot_SetIntersectionEnable( sht0, false );
	wait( delay );
	ObjShot_SetIntersectionEnable( sht0, false );
	descent( i in 0..4 ){
	ObjLaser_SetRenderWidth( sht0, i );
	wait( 2 );
	}
	Obj_Delete( sht0 );
	}

              task PatternInk( obj, n ){ 
              loop( n ){

	                                	let way = 1;
                                                	let shote = 48;
			let delay = 0;

			loop( way ){

			let speed = rand( 0.5, 1.6 );
			let angle = rand( 0, 360 );
                      	                	let sx = ObjMove_GetX( obj );
                        		let sy = ObjMove_GetY( obj );
				
				let sht1 = TShotA2( sx, sy, speed+6, angle, -1, speed, shote, delay );
	
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle += 360/way;
			}
			PlaySound("LenenShot1",92,0);
                       		wait( 0 );

	}

   }

	task Rig(obj, n,t)
{
	while( !Obj_IsDeleted( obj ) && ObjMove_GetX( obj ) > 0 && ObjMove_GetX( obj ) < GetStgFrameWidth && ObjMove_GetY( obj ) > 0 && ObjMove_GetY( obj ) <  GetStgFrameHeight ){ yield; }

   	if(ObjMove_GetX( obj ) < 0 )
   	{ ObjMove_AddPatternA2( obj, 0, 0, NO_CHANGE, 0, 0, 0 ); 
	   PatternInk( obj, n );
	   ObjMove_AddPatternA2( obj, t, 0, NO_CHANGE, 0.06, 0, 5 ); }

   	if(ObjMove_GetX( obj ) > GetStgFrameWidth  )
   	{ ObjMove_AddPatternA2( obj, 0, 0, NO_CHANGE, 0, 0, 0 );
	   PatternInk( obj, n );
	   ObjMove_AddPatternA2( obj, t, 0, NO_CHANGE, 0.06, 0, 5 ); }

   	if( ObjMove_GetY( obj ) < 0 )
   	{ ObjMove_AddPatternA2( obj, 0, 0, NO_CHANGE, 0, 0, 0 );
                       PatternInk( obj, n );
	   ObjMove_AddPatternA2( obj, t, 0, NO_CHANGE, 0.06, 0, 5 ); }

   	if(ObjMove_GetY( obj ) > GetStgFrameHeight  )
   	{ ObjMove_AddPatternA2( obj, 0, 0, NO_CHANGE, 0, 0, 0 );
                       PatternInk( obj, n );
	   ObjMove_AddPatternA2( obj, t, 0, NO_CHANGE, 0.06, 0, 5 ); }


}

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

	}

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

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