
#ScriptVersion[3]
#Title["TsubakuraS9"]
#Text["TsubakuraS9"]
#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",2);
}

@MainLoop
{
	yield;

}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(1);
	}
                	case(EV_REQUEST_IS_DURABLE_SPELL)
	{
		SetScriptResult(true);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(75);
	}
	case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(90000000);
	}
}

//----------------------------------------------------
task mainTask{
	SetCommonData("Scroll",1);
	SetCommonData("ForceLifebar",1);
	StartCountDown;
	PlaySound("SpellStart",100,0);
	wait( 120 );
	ObjRender_SetAlpha( objBoss, 0 );
	ObjEnemyBossScene_StartSpell(objScene);
	ObjMove_SetDestAtWeight(objBoss,stgx,stgy - 20,10,7);
	Cutin("The Best Nightmare From Your Best Friend",13,"SHINKI");
	wait( 175 );
	TShot1;
	}
//----------------------------------------------------

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;
	PatternSuzumi1;
	wait( 1200 );
	PlaySound("SpellStart",92,0);
	DeleteShotAll( TYPE_ALL, TYPE_ITEM );
	ObjMove_SetPosition( objBoss, stgx, stgy - 90 );
	wait( 30 );
	PatternSuzumi21;
	wait( 70 );
	PatternSuzumi22;
	wait( 1100 );
	PlaySound("SpellStart",92,0);
	DeleteShotAll( TYPE_ALL, TYPE_ITEM );
	wait( 30 );
	Warning1;
	Warning2;
	wait( 80 );
	PatternSuzumi31;
	PatternSuzumi32;
	wait( 1090 );
	PlaySound("SpellStart",92,0);
	DeleteShotAll( TYPE_ALL, TYPE_ITEM );
	ObjMove_SetPosition( objBoss, stgx, stgy );
	PatternSuzumi4;
}

task Warning1{
loop( 40 ){
loop( 2 ){
Warn1( rand( 0, GetStgFrameWidth ), rand( GetStgFrameHeight - 50, GetStgFrameHeight + 10 ) );
PlaySound("LenenBulletWave",100,0);
}
wait( 2 );
}
}

task Warning2{
loop( 40 ){
loop( 2 ){
Warn1( rand( 0, GetStgFrameWidth ), rand( -10, 50 ) );
PlaySound("LenenBulletWave",100,0);
}
wait( 2 );
}
}

let warn = GCSD~"img/warning.png";

task Warn1( x, y ){ 
	let value = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,25);
	ObjPrim_SetTexture(obj,warn);
	ObjSprite2D_SetSourceRect(obj,0,0,50,51);
	ObjSprite2D_SetDestRect(obj,-50,-51,50,51);
	ObjSprite2D_SetDestCenter( obj );
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj,x,y,0);
	Sizing( obj );
	dDelete( obj, 75 );
	ObjRender_SetAlpha( obj, 255 );
	while( !Obj_IsDeleted(objBoss) && bSpell == false){
	yield;
	}
}
	task Sizing( obj ){
	descent( i in 5..10 ){
	ObjRender_SetScaleXYZ(obj,i/5,i/5,0);	
	yield;
	}
	}

	task dDelete( obj, t ){
	wait( t );
	descent( i in 0..255/25 ){
	ObjRender_SetAlpha( obj, i*25 );
	yield;
	}
	Obj_Delete( obj );
	}

	task SuzumiImmediateBounceBack( obj, t, speed, angle, shote ){
		wait( t );
		ObjMove_AddPatternA3( obj, 0, -speed, angle, 0, 0, -speed, shote );
		PlaySound("LenenBulletWave",92,0);
	}

	task SuzumiCopyFadeAppearGo( obj, t, speed, angle ){
		ObjShot_SetIntersectionEnable( obj, false );
		descent( i in 0..255/3 ){
			ObjRender_SetAlpha( obj, i*3 );
			yield;
			}
		wait( t );
		ascent( i in 0..255/3 ){
			ObjRender_SetAlpha( obj, i*3 );
			yield;
			}
		ObjShot_SetIntersectionEnable( obj, true );
		ObjMove_AddPatternA2( obj, 0, speed, angle, 0, 0, speed );
	}

	task SuzumiStopFadeAppearGo( obj, t1, t2, speed, angle, acc, shote ){
		wait( t1 );
		let a = ObjMove_GetSpeed( obj );
		PlaySound("LenenBulletWave",92,0);
		ObjMove_AddPatternA2( obj, 0, 0, NO_CHANGE, 0, 0, 0 );		
		ObjShot_SetIntersectionEnable( obj, false );
		descent( i in 0..255/4 ){
			ObjRender_SetAlpha( obj, i*4 );
			yield;
			}
		wait( t2 );
		ObjMove_AddPatternA3( obj, 0, 0, NO_CHANGE, 0, 0, 0, shote );
		ascent( i in 0..255/4 ){
			ObjRender_SetAlpha( obj, i*4 );
			yield;
			}
		ObjShot_SetIntersectionEnable( obj, true );
		ObjMove_AddPatternA2( obj, 0, a, angle, acc, 0, speed );
	}

	task SuzumiFadeOnly( obj, t ){
		wait( t );	
		ObjShot_SetIntersectionEnable( obj, false );
		descent( i in 0..255/5 ){
			ObjRender_SetAlpha( obj, i*5 );
			yield;
			}
		Obj_Delete( obj );
	}

	task PatternSuzumi1{ 
	let W = 120;
	loop( 24 ){

	                                	let way = 80;
                                                	let shote = 299;				
			let angle = rand( 0, 360 );
			let speed = 2.4;

			if( W < 10 ){ W = 10; }

			loop( way ){

			let Wait = rand( 30, 90 );
                        		let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, 10 );
				ObjShot_SetSpellResist( sht1, true );
				SuzumiImmediateBounceBack( sht1, Wait, speed, angle, 299 );

				angle += 360 / way;

			}
			W -= 6;
			PlaySound("LenenShot1",92,0);
                        		wait( W );
		}
   }

	task PatternSuzumi21{ 
	loop( 98 ){

	                                	let way = 1;
                                                	let shote = 299;				
			let angle = [ 0, 180 ];
			let speed = 3.5;
			let Rand = round( rand( 0, 1 ));
			loop( way ){

                        		let sx = [ rand( -12, -8 ), GetStgFrameWidth + rand( 8, 12 ) ];
                        		let sy = rand( 0, GetStgFrameHeight );
				
				let sht1 = TShotA2( sx[ Rand ], sy, speed, angle[ Rand ], 0, speed, shote, 0 );
				ObjShot_SetSpellResist( sht1, true );
				PatternSuzumi211( sht1, angle[ Rand ], speed );

			}
			PlaySound("LenenShot1",92,0);
                        		wait( 12 );
		}
   }


	task PatternSuzumi211( obj, aangle, sspeed ){ 
	while( !Obj_IsDeleted( obj )){

	                                	let way = 1;
                                                	let shote = 299;				
			let angle = ObjMove_GetAngle( obj );

			loop( way ){

                        		let sx = ObjMove_GetX( obj );
                        		let sy = ObjMove_GetY( obj );
				
				let sht1 = TShotA2( sx, sy, 0, angle, 0, 0, shote, 0 );
				ObjShot_SetSpellResist( sht1, true );
				SuzumiCopyFadeAppearGo( sht1, 0, sspeed, aangle );

				angle += 360 / way;

			}
                        		wait( 15 );
			PlaySound("LenenBulletWave",92,0);
		}
   }

	task PatternSuzumi22{ 
	loop( 16 ){

	                                	let way = 20;
                                                	let shote = 299;				
			let angle = rand( 0, 360 );
			let speed = 2.8;
			loop( way ){

                        		let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, 10 );
				let sht2 = TShotA2( sx, sy, speed, angle, 0, speed, shote, 10 );

				ObjShot_SetSpellResist( sht1, true );
				ObjShot_SetSpellResist( sht2, true );

				AngularTime( sht1, 1.8, 120 );
				AngularTime( sht2, -1.8, 120 );

				angle += 360 / way;

			}
			PlaySound("LenenShot1",92,0);
                        		wait( 70 );
		}
   }

	task PatternSuzumi31{ 
	let W = 80;
	let T = 70;
	loop( 31 ){
                    let sx = rand( -10, 1 );
	let gap = 12;
	loop( GetStgFrameWidth / gap  + 1 ){

                                                	let shote = 299;				
			let angle = 90;
			let speed = 8;
			let way = 1;
			if( W < 10 ){ W = 10; }

			loop( way ){

			let Wait = rand( 30, 90 );
                        		let sy = 0;
				
				let sht1 = TShotA2( sx, sy, 0, angle, 0.07, speed, shote, 10 );
				ObjShot_SetSpellResist( sht1, true );
				SuzumiFadeOnly( sht1, T );

				angle += 360 / way;

			}
			sx += gap;
			}
			T += 1;
			W -= 3;
			PlaySound("LenenLaserDelayShort",92,0);
                        		wait( W );
		}
   }

	task PatternSuzumi32{ 
	let W = 10;
	loop( 170 ){
	loop( 2 ){

                                                	let shote = 299;				
			let angle = 270;
			let speed = 8;
			let way = 1;
			if( W < 1 ){ W = 1; }

			loop( way ){

                    		let sx = rand( 0, GetStgFrameWidth );
                        		let sy = GetStgFrameHeight + 10;
			let Wait = rand( 20, 180 );
				
				let sht1 = TShotA2( sx, sy, 0, angle, 0.04, speed, shote, 10 );
				ObjShot_SetSpellResist( sht1, true );
				SuzumiStopFadeAppearGo( sht1, Wait, 10, speed, angle, 0.04, 299 );

				angle += 360 / way;

			}
			}
			W -= 0.05;
			PlaySound("LenenShot1",92,0);
                        		wait( W );
		}
   }
	task PatternSuzumi4{ 
	let W = 10;
	while( !Obj_IsDeleted( objBoss )){
	loop( 3 ){

                                                	let shote = 97;				
			let angle = rand( 0, 360 );
			let speed = rand( 1.8, 3.5 );
			let way = 1;

			loop( way ){

                    		let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
			let Wait = rand( 20, 90 );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, 10 );
				ObjShot_SetSpellResist( sht1, true );
				SuzumiStopFadeAppearGo( sht1, Wait, 10, speed, angle, 0, 299 );

				angle += 360 / way;

			}
			}
			PlaySound("LenenShot1",92,0);
			wait( 2 );
		}
   }

	task AngularTime( obj, ang, t ){
	ObjMove_SetAngularVelocity( obj, ang );
	wait( t );
	ObjMove_SetAngularVelocity( obj, 0 );
	}


	task StartCountDown
	{
		wait((75*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());
	}