#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["SeiranS5"]
#Text["Portal 'Galacta Wormhole'. Who said anything about copying Yuke's Seiran Pattern ??"]
#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("Yukari",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(1);
	}
                case(EV_REQUEST_IS_DURABLE_SPELL)
	{
		SetScriptResult(true);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(62);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(40000000);
	}
}

//----------------------------------------------------
task mainTask{
	wait( 200 );
	SetCommonData("ForceLifebar",1);
	StartCountDown;
                //ObjPlayer_ClearIntersection(GetPlayerObjectID);
	magiccircle(objBoss,1,-1);
	ObjMove_SetDestAtWeight(objBoss,stgx,stgy-100,5,6);
	Cutin("Portal 'Galacta Wormhole'",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	Sound(GCSD ~ "Butterfly.mp3");
	wait(105);
	TShot1;
	ascent( i in 0..60 ){
	ObjRender_SetAlpha( objBoss, 255 - i );
	wait( 1 );
	}
	wait(1200);
	}
//----------------------------------------------------

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;
	PatternWormhole;
	wait( 1500 );
	PlaySound("Shot1",92,0);
	PatternSide;
	wait( 1200 );
	PlaySound("Shot1",92,0);
	PatternSide2;
	DamageRateAtFrame(30,10,60);
}

	task PatternWormhole{
	let ang;
                	while( !Obj_IsDeleted( objBoss )){

                                              let speed = 0;
	                          let way = 6;
                                              let shote = 275;
              		      let angle = rand( 0, 360 );
	                          let delay = 30;
	                          let x = ObjMove_GetX( objPlayer );
		      let y = ObjMove_GetY( objPlayer );
			loop( way ){
		                    ang = angle - 180;
			let r = 90;
                      	                    let sx = x + r*cos( angle );
                        		let sy = y + r*sin( angle );
				
				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 );


				PatternWorm( sht1, ang );

				DelayDelete( sht1, 151 );

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

				angle += 360 / way;
				wait( 2 );
				PlaySound("Boon1",92,0);
			}

                        	wait( 200 );

	}

   }

              task PatternWorm( obj, ang ){
              wait( 150 );
              let e = ang + 2/2;
              let sx = ObjMove_GetX( obj );
              let sy = ObjMove_GetY( obj );
              let speed = 2;
              if( Obj_IsDeleted( obj )){ break; }
              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+5, angle, -0.4, speed, shote, delay );
                                NotifyEventAll( EV_USER + 40, [ sht, delay ] );
                        }
	    speed -= 0.08;
                        PlaySound("LenenShot1",92,0);
                        wait( 2 );

                }
}

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

	                                	let way = 9;
                                                	let shote = 115;
			let delay = 30;
			let speed = 1.4;
			let angle1 = rand( 80, 100 );
			let angle2 = rand( 80, 100 );
                      	                	let sx = [ 0 + rand( -10, 10 ), GetStgFrameWidth + rand( -10, 10 )];
                        		let sy = 0 + rand( -10, 10 );

			loop( way ){
				
				let sht1 = TShotA2( sx[0], sy, speed+3, angle1, -0.2, speed, shote, delay );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				let sht2 = TShotA2( sx[1], sy, speed+3, angle2, -0.2, speed, shote, delay );
				NotifyEventAll( EV_USER + 40, [ sht2, delay ] );

				angle1 -= 100/way;
				angle2 += 100/way;
			}
			PlaySound("LenenShot1",92,0);
                       		wait( 60 );

	}

   }

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

	                                	let way = 1;
                                                	let shote = 116;
			let delay = 30;
			let speed = rand( 1, 2 );
			let angle1 = rand( 80, 100 );
                      	                	let sx = rand( 0, GetStgFrameWidth );
                        		let sy = rand( -10, 10 );

			loop( way ){
				
				let sht1 = TShotA2( sx, sy, speed+3, angle1, -0.2, speed, shote, delay );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

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

	}

   }

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