
#ScriptVersion[3]
#Title["TsubakuraS4"]
#Text["TsubakuraS4"]
#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(40000000);
	}
}

//----------------------------------------------------
task mainTask{
	StartCountDown;
	PlaySound("SpellStart",100,0);
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,7);
	Cutin("Hot & Cold 'Dim Room'",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	wait( 160 );
	TShot1;
	DamageRateAtFrame(14,0,0);
	}
//----------------------------------------------------

task TShot1
{
	if( ObjEnemy_GetInfo( objBoss, INFO_LIFE ) == 1 ){ DeleteShotAll( TYPE_ALL, TYPE_IMMEDIATE ); }
	let r = 70;
	let angle = rand(0,80);
	let dir = 0;
	let s = 1;
	PatternLoop;
}

	task PatternLoop{
	while( !Obj_IsDeleted( objBoss )){
	Pattern1;
	wait( 380 );
	Pattern2;
	wait( 380 );
	Pattern3;
	wait( 370 );
	Pattern4;
	wait( 630 );
	}
	}

              task Pattern1{ 
              let angle = 0;
              let a = 0;
              let t = 200;
              loop( 150 ){

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

			loop( way ){

                      	                	let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				ObjShot_SetSpellResist( sht1, true );
				ReflectPlayerAim( sht1, t, 2.2, 33 );

				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle += 360 / way;

			}
			t -= 1;
			angle += a;
			a += rand( 0.5, 1 );
			PlaySound("LenenShot1",92,0);
                        		if( wait( 1 ) ){ return; }
	}
   }

              task Pattern2{ 
              let angle = 0;
              let a = 0;
              let t = 100;
              loop( 1 ){

	                                	let way = 160;
                                                	let shote = 112;
			let delay = 0;

			loop( way ){

              			let speed = rand( 1.6, 4 );
                      	                	let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				ObjShot_SetSpellResist( sht1, true );
				ReflectPlayerAim( sht1, t, 2, 97 );

				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle += 360 / way;

			}
			t -= 1.3;
			angle -= a;
			a += rand( 0.5, 1 );
			PlaySound("LenenShot1",92,0);
                        		if( wait( 1 ) ){ return; }
	}
   }

              task Pattern3{ 
              let angle = 0;
              let a = 0;
              let t = 120;
              loop( 150 ){

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

			loop( way ){

                      	                	let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				ObjShot_SetSpellResist( sht1, true );
				ReflectPlayerAim( sht1, t, 2, 33 );

				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle += 360 / way;

			}
			t -= 0.4;
			angle -= a;
			a += rand( 0.5, 1 );
			PlaySound("LenenShot1",92,0);
                        		if( wait( 1 ) ){ return; }
	}
   }

              task Pattern4{ 
              let t = 180;
              loop( 4 ){
              let speed = 3.5;
              let way = 25;
              loop( 2 ){

                                                	let shote = 112;
			let delay = 0;
              			let angle = rand( 0, 360 ) ;

			loop( way ){
                      	                	let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				ObjShot_SetSpellResist( sht1, true );
				ReflectPlayerAim( sht1, t, speed - 1.2, 97 );
				ObjMove_AddPatternA2( sht1, 490, speed - 1.2, NO_CHANGE, 0.02, 0, speed + 8 );

				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle += 360 / way;

			}
			way += 18;
			speed -= 1.6;
			}
			t -= 20;
			PlaySound("LenenShot1",92,0);
                        		if( wait( 30 ) ){ return; }
	}
   }

	task ReflectPlayerAim( obj, t, speed, shot ){
	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_GetX(obj)>GetStgFrameWidth)
   	{ ObjMove_AddPatternA2( obj, 0, 0, NO_CHANGE, 0, 0, 0 ); 
	   PlaySound("LenenBulletWave",70,0);
	   wait( t );
	   ObjMove_AddPatternA3( obj, 0, speed, GetAngleToPlayer( obj ), 0, 0, speed, shot ); 
	   PlaySound("LenenShot1",70,0);}

   	if( ObjMove_GetY( obj ) < 0 || ObjMove_GetY( obj )>GetStgFrameHeight)
   	{ ObjMove_AddPatternA2( obj, 0, 0, NO_CHANGE, 0, 0, 0 ); 
	   PlaySound("LenenBulletWave",70,0);
	   wait( t );
	   ObjMove_AddPatternA3( obj, 0, speed, GetAngleToPlayer( obj ), 0, 0, speed, shot ); 
	   PlaySound("LenenShot1",70,0);}

}
	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());
	}