#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["SeiranS3"]
#Text["Trap 'Death By Cartridge'. Looks like a rat trap, but it's a rabbit trap."]
#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(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	StartCountDown;
	//ObjPlayer_ClearIntersection(GetPlayerObjectID);
	magiccircle(objBoss,1,-1);
	ObjMove_SetDestAtWeight(objBoss,stgx,stgy-100,5,6);
	Cutin("Trap 'Death By Cartridge'",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( 80, 1 );
	maple;
	wait( 90 );
	DamageRateAtFrame(26,10,0);
	PatternLoop;
}
	task PatternLoop{
	while( !Obj_IsDeleted( objBoss )){
	PatternSuck3;
	wait( 720 );
	PatternRandom01;
	wait( 220 );
	PatternRandom02;
	wait( 150 );
	maple;
	wait( 80 );
	}
}

              task PatternRandom01{
              loop( 1 ){
              let e = 270 + 9/2;
              let sx = ObjMove_GetX( objBoss );
              let sy = ObjMove_GetY( objBoss );
              let speed = 2.2;
              ascent(i in 0..35){

                        let way = i;
                        let shote = 3;
                        let delay = 10;
                        let t = 9;
                        ascent(j in 0..way){
 
                                let angle = e+j*t-i*t/2;
                                let sht = TShotA2( sx, sy, speed+10, angle, -0.8, speed, shote, delay );
	            Reflect( sht, 0, 0, NO_CHANGE );
                                NotifyEventAll( EV_USER + 40, [ sht, delay ] );
                        }
                        PlaySound("LenenShot1",92,0);
                        wait( 4 );

                }
                        wait( 40 );

                }
}

              task PatternRandom02{
              loop( 1 ){
              let e = 270 + 10.5/2;
              let sx = ObjMove_GetX( objBoss );
              let sy = ObjMove_GetY( objBoss );
              let speed = 1.9;
              ascent(i in 0..34){

                        let way = i;
                        let shote = 278;
                        let delay = 10;
                        let t = 10.5;
                        ascent(j in 0..way){
 
                                let angle = e+j*t-i*t/2;
                                let sht = TShotA2( sx, sy, speed+10, angle, -1, speed, shote, delay );
	            //Reflect( sht, 0, 0, NO_CHANGE );
                                NotifyEventAll( EV_USER + 40, [ sht, delay ] );
                        }
                        PlaySound("LenenShot1",92,0);
                        wait( 4 );

                }
                        wait( 40 );

                }
}


	task Reflect( 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, 180-ObjMove_GetAngle( obj ), acceleration, angular, v ); }

   	if( ObjMove_GetY( obj ) < 0 )
   	{ ObjMove_AddPatternA2( obj, 0, NO_CHANGE, -ObjMove_GetAngle( obj ), acceleration, angular, v ); }

	PlaySound("BulletWave",70,0);

}


              task PatternSuck3{ 
              let r = 0;
              let angle1 = rand( 0, 360 );
              let R = 300;
              loop( 100 ){

              			let speed1 = -0.05;
              			let speed2 = -2;
	                                	let way = 1;
                                                	let shote = 277;
			let delay = 30;

			loop( way ){
                      	                	let sx = ObjMove_GetX( objBoss ) + r*cos( angle1 );
                        		let sy = ObjMove_GetY( objBoss ) + r*sin( angle1 );
				
				let sht1 = TShotA2( sx, sy, speed1, angle1, 0, speed1, shote, delay );
				//ObjShot_SetAutoDelete( sht1, false );
				DelayDelete( sht1, R );

				//ObjMove_AddPatternA2( sht1, 400, speed1, NO_CHANGE, -0.015, 0, speed2 );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				PatternSuck4( R, sht1 );

				angle1 += 360 / way;

			}
			r += 3;
			R += 2;
			angle1 -= 16;
			PlaySound("LenenShot1",92,0);
                       		wait( 2 );

	}

   }

              task PatternSuck4( R, obj ){ 
              wait( R - 1);
              let speed = 6;
              if( Obj_IsDeleted( obj )){ break; }
              loop( 10 ){

	                                	let way = 1;
                                                	let shote = 309;
			let delay = 30;
			let angle = GetAngleToPlayer( obj );

			loop( way ){
                      	                	let sx = ObjMove_GetX( obj );
                        		let sy = ObjMove_GetY( obj );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle += 360 / way;

			}
			speed -= 0.8;
			PlaySound("LenenShot1",92,0);
                       		wait( 0 );

	}

   }

              task PatternSuck2{ 
              let r = 300;
              let angle1 = rand( 0, 360 );
              loop( 45 ){

              			let speed1 = -0.05;
              			let speed2 = -2;
	                                	let way = 10;
                                                	let shote = 310;
			let delay = 30;

			loop( way ){
                      	                	let sx = ObjMove_GetX( objBoss ) + r*cos( angle1 );
                        		let sy = ObjMove_GetY( objBoss ) + r*sin( angle1 );
				
				let sht1 = TShotA2( sx, sy, speed1, angle1, 0, speed1, shote, delay );
				ObjMove_AddPatternA2( sht1, 400, speed1, NO_CHANGE, -0.015, 0, speed2 );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle1 += 360 / way;

			}
			r -= 5;
			angle1 -= 0.8;
			PlaySound("LenenShot1",92,0);
                       		wait( 6 );

	}

   }




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