
#ScriptVersion[3]
#Title["SeiranN2"]
#Text["SeiranN2"]
#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 objScene=GetEnemyBossSceneObjectID();
let color = [0,0];
@Initialize
{
SetCommonData("Scroll",0);
SetBoss("Seiran",false);
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(4300);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(85);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	StartCountDown;
                //ObjPlayer_ClearIntersection(GetPlayerObjectID);
	ObjMove_SetDestAtWeight(objBoss,stgx,120,5,7);
	magiccircle(objBoss,1,-1);
	SetCommonData("Scroll",1);
	NotifyEventAll(EV_SET_SONG,1);
	wait(60);
	wait(90);
	TShot1;
	yield;

	}

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

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);
	Loop;
	DamageRateAtFrame(180,20,0);
}
	task Loop{
	Portal;
	while( !Obj_IsDeleted( objBoss )){
	PatternRandom01;
	PatternRandom02;
	PatternRandom03;
	wait( 20 );
	PatternRandom2;
	wait( 80 );
              	TMovement( 30, 0, 2 );
              	//BorderMove( 80, GetStgFrameWidth - 80, 50, GetStgFrameHeight / 6, 4, 3);
	wait( 80 );
	}
	}

              task Portal{ 
              let c = 0;
              loop( 1 ){

              			let speed = 0;
	                                	let way = 1;
                                                	let shote = 330;
              			let angle = 0;
			let delay = 0;

			loop( way ){

                      	                	let sx = [ ObjMove_GetX( objBoss ) + 100 , ObjMove_GetX( objBoss ) - 100 ];
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx[0], sy, 0, angle, 0, speed, shote, delay );
				ObjRender_SetColor( sht1, 0, 0, 0 );
				ObjShot_SetSpellResist( sht1, true );
				ObjShot_SetAutoDelete( sht1, false );

				let sht2 = TShotA2( sx[1], sy, 0, angle, 0, speed, shote, delay );
				ObjRender_SetColor( sht2, 0, 0, 0 );
				ObjShot_SetSpellResist( sht2, true );
				ObjShot_SetAutoDelete( sht2, false );

				FlashyOrb(sht1, shote);
				FlashyOrb(sht2, shote);

				Stick( sht1, 120 );
				Stick( sht2, -120 );

				PatternRandom11( sht1, 75 );
				PatternRandom11( sht2, 180 );

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

				angle += 360 / way;

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

   }
	task Stick( obj, r ){
	let sx;
	let sy;
	while( !Obj_IsDeleted( objBoss )){
		sx = ObjMove_GetX( objBoss ) + r;
		sy = ObjMove_GetY( objBoss );
		ObjMove_SetPosition( obj, sx, sy );
		yield;
	}
	}

task BorderMove(leftX,rightX,topY,bottomY,weight,time)
{
    let vx = (rightX-leftX)/2;
    let vy = (bottomY-topY)/2;
    let rx = rand(-vx,vx);
    let ry = rand(-vy,vy);
    if(GetEnemyX-leftX+rx<0){rx*=-1;}
    if(GetEnemyX-rightX+rx>0){rx*=-1;}
    if(GetEnemyY-topY+ry<0){ry*=-1;}
    if(GetEnemyY-bottomY+ry>0){ry*=-1;}
    ObjMove_SetDestAtWeight(objBoss, GetEnemyX+rx, GetEnemyY+ry, weight,time);
}

              task PatternRandom01{
              loop( 1 ){
              let e = GetAngleToPlayer( objBoss ) + 2/2;
              let sx = ObjMove_GetX( objBoss );
              let sy = ObjMove_GetY( objBoss );
              let speed = 2.5;
              ascent(i in 0..10){

                        let way = i;
                        let shote = 116;
                        let delay = 10;
                        let t = 2;
                        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 );
                                NotifyEventAll( EV_USER + 40, [ sht, delay ] );
                        }
                        PlaySound("LenenShot1",92,0);
                        wait( 6 );

                }
                        wait( 40 );

                }
}

              task PatternRandom02{
              loop( 1 ){
              let e = GetAngleToPlayer( objBoss ) + 2/2 + 45;
              let sx = ObjMove_GetX( objBoss );
              let sy = ObjMove_GetY( objBoss );
              let speed = 1.8;
              ascent(i in 0..10){

                        let way = i;
                        let shote = 119;
                        let delay = 10;
                        let t = 2;
                        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 );
                                NotifyEventAll( EV_USER + 40, [ sht, delay ] );
                        }
                        PlaySound("LenenShot1",92,0);
                        wait( 6 );

                }
                        wait( 40 );

                }
}
              task PatternRandom03{
              loop( 1 ){
              let e = GetAngleToPlayer( objBoss ) + 2/2 - 45;
              let sx = ObjMove_GetX( objBoss );
              let sy = ObjMove_GetY( objBoss );
              let speed = 1.8;
              ascent(i in 0..10){

                        let way = i;
                        let shote = 123;
                        let delay = 10;
                        let t = 2;
                        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 );
                                NotifyEventAll( EV_USER + 40, [ sht, delay ] );
                        }
                        PlaySound("LenenShot1",92,0);
                        wait( 6 );

                }
                        wait( 40 );

                }
}



              task PatternRandom11( obj, t ){
              wait( t );
              while( !Obj_IsDeleted( obj )){
              let e = GetAngleToPlayer( obj ) + 1/2;
              let sx = ObjMove_GetX( obj );
              let sy = ObjMove_GetY( obj );
              let speed = 1.4;
              ascent(i in 0..10){

                        let way = i;
                        let shote = 126;
                        let delay = 10;
                        let t = 1;
                        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 );
                                NotifyEventAll( EV_USER + 40, [ sht, delay ] );
                        }
                        PlaySound("LenenShot1",92,0);
                        wait( 6 );

                }
                        wait( 150 );

                }
}


              task PatternRandom2{
              loop( 1 ){
              let e = GetAngleToPlayer( objBoss ) + 14/2 - 9*14/2;
              let speed = 2.8;
              let c = 0;
              ascent(i in 0..18){

              let sx = ObjMove_GetX( objBoss );
              let sy = ObjMove_GetY( objBoss );

                        let way = 9 + i;
                        let shote = [ 777, 778, 779, 780, 781, 782, 776 ];
                        let delay = 10;
                        let t = 14;
                        ascent(j in 0..way){
 
                                let angle = e+j*t-i*t/2;
                                let sht = TShotA2( sx, sy, speed+5, angle, -0.4, speed, shote[c%length( shote )], delay );
                                NotifyEventAll( EV_USER + 40, [ sht, delay ] );
                        }
	    c+=1;
                        PlaySound("LenenShot1",92,0);
                        wait( 6 );

                }
                        wait( 40 );

                }
}

	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);
		ObjMove_AddPatternA2( obj, 0, 0, 90, 0.1, 0, 3 );
		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 PatternMove{
              while( !Obj_IsDeleted( objBoss )){
              	TMovement(30,30,2);
              	wait( 150 );
		}
	}


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



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

task SizeCircle
{
	ascent(i in 0..60)
	{
		SetCommonData("CircleSize",sin(i*1.5));
		yield;
	}
}	

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

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