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

//----------------------------------------------------
task mainTask{
	StartCountDown;
	PlaySound("SpellStart",100,0);
//ObjPlayer_ClearIntersection(GetPlayerObjectID);
	ObjMove_SetDestAtWeight(objBoss,stgx,100,10,7);
	Cutin("Dragon Eyes 'Mizukagami-no-Ryuu'",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	wait( 170 );
	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;
	PatternDragonEyes;
	wait( 180 );
	DamageRateAtFrame(11,0,0);
	PatternLeftEye;
	PatternRightEye;
	wait( 100 );
	PatternSub;
}

              task PatternDragonEyes{ 
              let angle1 = 0;
              let angle2 = 180;
              while( !Obj_IsDeleted( objBoss )){

	                                	let way = 9;
                                                	let shote = 1016;
			let delay = 90;

			loop( way ){

                      	                	let sx1 = ObjMove_GetX( objBoss ) + 100;
                      	                	let sx2 = ObjMove_GetX( objBoss ) - 100;
                        		let sy = ObjMove_GetY( objBoss ) + 20;
				
				HLaser( sx1, sy, angle1, 500, 10, 100, shote, delay );
				HLaser( sx2, sy, angle2, 500, 10, 100, shote, delay );

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

			}
			angle1 += 8.1;
			angle2 -= 8.1;
			PlaySound("LenenLaserDelayLong",92,0);
                        		if( wait( 58 ) ){ return; }
	}
   }

	task HLaser( sx, sy, angle, length, width, duration, shote, delay ){
	ProperLaserDelay( sx, sy, angle, length, delay, shote );
	wait( delay );
	PlaySound("LenenLaserLong",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 );
	//ObjRender_SetBlendType( sht0, BLEND_ALPHA );
	//ObjRender_SetColor( sht0, 0, 0, 0 );
	ObjShot_SetIntersectionEnable( sht0, false );
	wait( delay );
	Obj_Delete( sht0 );
	}

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

	ObjShot_SetIntersectionEnable( sht1, false );
	descent( i in 0..width ){
	ObjLaser_SetRenderWidth( sht1, i );
	wait( 2 );
	}

	Obj_Delete( sht1 );
	}
 
	task PatternLeftEye{ 
	let anglerotate = 90;
	let anglebullet = rand( 0, 360 );
	while( !Obj_IsDeleted( objBoss )){

              			let speed = 1.2;
	                                	let way = round(rand( 1, 3 ));
                                                	let shote = 266;
			let delay = 20;			
			let r = 68;
                        		let sx = ObjMove_GetX( objBoss ) - 100  + r*cos( anglerotate );
                        		let sy = ObjMove_GetY( objBoss ) + 20 + r*sin( anglerotate );

			loop( way ){
				
				let sht1 = TShotA2( sx, sy, 10, anglebullet, -0.8, speed, shote, delay );

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

				anglebullet += rand( 330, 360 ) / way;

			}
			anglerotate -= 9;
			anglebullet -= 23;
			PlaySound("LenenShot1",92,0);
                        		if( wait( 3 ) ){ return; }
		}
   }

	task PatternRightEye{ 
	let anglerotate = 270;
	let anglebullet = rand( 0, 360 );
	while( !Obj_IsDeleted( objBoss )){

              			let speed = 1.2;
	                                	let way = round(rand( 1, 3 ));
                                                	let shote = 266;
			let delay = 20;			
			let r = 68;
                        		let sx = ObjMove_GetX( objBoss ) + 100  + r*cos( anglerotate );
                        		let sy = ObjMove_GetY( objBoss ) + 20 + r*sin( anglerotate );

			loop( way ){
				
				let sht1 = TShotA2( sx, sy, 10, anglebullet, -0.8, speed, shote, delay );

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

				anglebullet += rand( 330, 360 ) / way;

			}
			anglerotate += 9;
			anglebullet -= 23;
			PlaySound("LenenShot1",92,0);
                        		if( wait( 3 ) ){ return; }
		}
   }

              task PatternSub{ 
              while( !Obj_IsDeleted( objBoss )){

              			let speed = 1;
	                                	let way = 14;
                                                	let shote = 830;
			let delay = 0;
			let angle = GetAngleToPlayer( objBoss ) + 360 / way / 2;

			loop( way ){

                      	                	let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				let sht2 = TShotA2( sx, sy, speed - 0.1, angle + 2, 0, speed, shote, delay );
				let sht3 = TShotA2( sx, sy, speed - 0.1, angle - 2, 0, speed, shote, delay );


				angle += 360 / way;

			}
			PlaySound("LenenShot1",92,0);
                        		if( wait( 400 ) ){ 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 ObjShot_FadeDeleteSetTime( obj, time ){
	wait( time );
	ObjShot_FadeDelete( obj );
	}

              task PatternSparkle( obj ){ 
              while( !Obj_IsDeleted( obj )){

			let angle = GetAngleToPlayer( obj ) + rand( -20, 20 );
                                                	let speed = 2.5;
	                                	let way = 1;
                                                	let shote = 64;
			let delay = 5;

			loop( way ){
                      	                	let sx = ObjMove_GetX( obj );
                        		let sy = ObjMove_GetY( obj );
				
				let sht1 = TShotA2( sx, sy, 0.5, angle, 0, 0.5, shote, delay );
				ObjMove_AddPatternA2( sht1, 200, 0.5, NO_CHANGE, 0.01, 0, speed );

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

				angle += 360 / way;

			}
			PlaySound("LenenShot1",92,0);
                        		if( wait( rand( 30, 60 ) ) ){ return; }

	}

   }

	task FlashyOrb( core, shot ){
	while( !Obj_IsDeleted( core )){
	FlashyOrb1( core, shot );
	wait( 10 );
	}
	}

	task FlashyOrb1(core, shot)
	{
		let obj = CreateShotOA1(core,0,0,shot,0);
		ObjShot_SetSpellResist(obj,true);
		ObjShot_SetIntersectionEnable(obj,false);
		ascent(i in 0..50)
		{
			ObjRender_SetScaleXYZ(obj,1-i/50,1-i/50,1-i/50);
			ObjRender_SetColor(obj,0,0,0);
			wait( 1 );
		}
		Obj_Delete(obj);
	}


task ScreenShake( time, s ){
        let size = s;
        loop( time/2 ){

                Set2DCameraFocusX( Get2DCameraX + rand( -size, size ));
                Set2DCameraFocusY( Get2DCameraY + rand( -size, size ));

                yield;
                Reset2DCamera;
                yield;
                size += 0.15;

        }
        Reset2DCamera;
}

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