#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["SeiranS4"]
#Text["War 'Star Wars 8'. The latest Star Wars is Star Wars 7. So may the spell card be with you."]
#Player["./Reisen/Reisen.txt","./MoF_Reimu/Reimu.txt","./sanae/sane.txt","./Marisa/Marisa.txt"]
#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("Seiran",true);
SetCommonData("BGShow",true);
}

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

//----------------------------------------------------
task mainTask{
	StartCountDown;
	//ObjPlayer_ClearIntersection(GetPlayerObjectID);
	magiccircle(objBoss,1,-1);
	ObjMove_SetDestAtWeight(objBoss,stgx,140,5,6);
	Cutin("War 'Star Wars 8'",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	Sound(GCSD ~ "Butterfly.mp3");
	wait( 120 );
	TShot1;
	}
//----------------------------------------------------

task TShot1
{
	if( ObjEnemy_GetInfo( objBoss, INFO_LIFE ) == 1 ){ DeleteShotAll( TYPE_ALL, TYPE_IMMEDIATE ); }
	attack( 70,1 );
	let r = 70;
	let angle = rand(0,80);
	let dir = 0;
	let s = 1;
	maple;
	wait(80);
	PatternPack;
	PatternTX;
	DamageRateAtFrame(42,10,0);
}

	task PatternPack{
	let y = 6;
	let x = 60;
	while(!Obj_IsDeleted( objBoss )){
	PatternPack1( y );
	wait( 10*y + x );
	PatternPack2( y );
	wait ( 10*y + x );
	x += 0;
	y += 0.3;
	}
	}
	
	

              task PatternPack1( y ){ 
              let sy = rand( -150, -140 )*2;
              loop( y ){
              let gap = 35;
              let sy1 = sy;
              loop( GetStgFrameHeight / gap + 30 ){

              			let speed = 1.5;
	                                	let way = 1;
                                                	let shote = 115;
              			let angle = 180;
			let delay = 20;

			loop( way ){

			let sx = GetStgFrameWidth;
				
				let sht1 = TShotA2( sx, sy1, speed, angle, 0, speed, shote, delay );

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

				angle += 360 / way;

			}
			sy1 += gap;
                       		wait( 0 );

	}
			sy += gap/2;
			PlaySound("LenenShot1",92,0);
                       		wait( 10 );

	}

   }

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

                                              let speed = 0;
	                          let way = 1;
                                              let shote = 355;
              		      let angle = 0;
	                          let delay = 30;

			loop( way ){

                      	                    let sx = rand( 80, GetStgFrameWidth - 80 );
                        		let sy = rand( 80, GetStgFrameHeight - 80 );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				ObjShot_SetIntersectionEnable( sht1, false );
				ObjRender_SetBlendType( sht1, BLEND_ALPHA );
				ObjRender_SetColor( sht1, 0, 0, 0 );
				FlashyOrb( sht1, shote );

				PatternBomb( sht1 );
				PatternBomb2( sht1 );

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

				angle += 360 / way;

			}
			PlaySound("Boon1",92,0);

                        if( wait( 120 ) ){ return; }

	}

   }

	task PatternBomb( obj ){ 
	wait( 180 );
	loop( 3 ){ PlaySound("sans",92,0); wait( 6 ); }
                    ScreenShake( 30, 4 );
                	loop( 1 ){

                                              let speed = 8;
	                          let way = 50;
                                              let shote = 532;
              		      let angle = 0;
	                          let delay = 0;

			loop( way ){

                      	                    let sx = ObjMove_GetX( obj );
                        		let sy = ObjMove_GetY( obj );
				
				let sht1 = TShotA2( sx, sy, speed, angle, -0.3, 0, shote, delay );
				DelayDeletes( sht1, 60 );
				DelayDelete( obj, 1 );
                                			ObjShot_SetSpellResist( sht1, true );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle += 360 / way;

			}
			PlaySound("stars",92,0);
                        		if( wait( 0 ) ){ return; }

	}

   }
	task PatternBomb2( obj ){ 
	wait( 180 + 17 );
                	loop( 1 ){

	                          let way = 200;
                                              let shote = 564;
	                          let delay = 0;

			loop( way ){
                                                            let speed = rand( 3, 8 );
              		      	let angle = rand( 0, 360 );
                      	                    let sx = ObjMove_GetX( obj );
                        		let sy = ObjMove_GetY( obj );
				
				let sht1 = TShotA2( sx, sy, speed, angle, -0.3, 0, shote, delay );
				DelayDeletes( sht1, 60 );
                                			ObjShot_SetSpellResist( sht1, true );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle += 360 / way;

			}
			PlaySound("stars",92,0);
                        		if( wait( 0 ) ){ return; }

	}

   }


task DelayDeletes( obj, time ){
wait( time );
ObjShot_FadeDelete( obj );
}

task ScreenShake( time, size ){

        loop( time/2 ){

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

                yield;
                Reset2DCamera;
                yield;

        }
        Reset2DCamera;
}

	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_SetAlpha( obj, 255 -i*5 );
			ObjRender_SetBlendType( obj, BLEND_ALPHA );
			ObjRender_SetColor(obj,0,0,0);
			wait( 1 );
		}
		Obj_Delete(obj);
	}

task DarkAngle(obj,speed)
{
   let x = GetAngleToPlayer( obj );
   while(!Obj_IsDeleted(obj))
   {
ObjMove_SetDestAtSpeed( obj, GetPlayerX, GetPlayerY, speed );

       yield;
   }
}

              task PatternPack2( y ){ 
              let sy = rand( -150, -140 )*2;
              loop( y ){
              let gap = 35;
              let sy1 = sy;
              loop( GetStgFrameHeight / gap + 30 ){

              			let speed = 1.5;
	                                	let way = 1;
                                                	let shote = 119;
              			let angle = 0;
			let delay = 20;

			loop( way ){

			let sx = 0;
				
				let sht1 = TShotA2( sx, sy1, speed, angle, 0, speed, shote, delay );

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

				angle += 360 / way;

			}
			sy1 += gap;
                       		wait( 0 );

	}
			sy += gap/2;
			PlaySound("LenenShot1",92,0);
                       		wait( 10 );

	}

   }

	task ReflectAndAim(obj, acceleration, angular, v )
{
while( !Obj_IsDeleted( obj ) && ObjMove_GetX( obj ) > 0 && ObjMove_GetX( obj ) < GetStgFrameWidth && ObjMove_GetY( obj ) > 0 ){ yield; }

   	if(ObjMove_GetX( obj )<0 || ObjMove_GetX( obj ) > GetStgFrameWidth )
   	{ ObjMove_AddPatternA2( obj, 0, NO_CHANGE, GetAngleToPlayer( obj ), acceleration, angular, v );}
   	if( ObjMove_GetY( obj ) < 0 )
   	{ ObjMove_AddPatternA2( obj, 0, NO_CHANGE, GetAngleToPlayer( obj ), acceleration, angular, v );}

	PlaySound("LenenBulletWave",70,0);

}

	task DelayDeletess( obj, t ){
	wait( t );
	Obj_Delete( obj );
	}

	function GetDotAngle(x1,y1,x2,y2){
	let angle=atan2(y1-y2,x1-x2);
	return angle;
	}

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


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

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