#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["YukariS1"]
#Text["Border Sign 'Quadruple Barrier', Yukari's IaMP Spell Card."]
#Player["./Hecatia/Hecatia.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);
}

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

//----------------------------------------------------
task mainTask{
	StartCountDown;
                //ObjPlayer_ClearIntersection(GetPlayerObjectID);
	YukariCircle(objBoss,1,-1);
	DamageRateAtFrame( 27,10,180 );
	ObjMove_SetDestAtWeight(objBoss,stgx,stgy-80,10,7);
	Cutin("Border Sign 'Quadruple Barrier'",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	Sound(GCSD ~ "Butterfly.mp3");
	wait(120);
	TShot1;
	wait(1200);
	}
//----------------------------------------------------

task TShot1
{
	if( ObjEnemy_GetInfo( objBoss, INFO_LIFE ) == 1 ){ DeleteShotAll( TYPE_ALL, TYPE_IMMEDIATE ); }
	attack( 120 );
	let r = 70;
	let angle = rand(0,80);
	let dir = 0;
	let s = 1;
	maple;
	wait( 80 );
                	PatternQuadruple;
	wait( 250 );
                	PatternMiniQuadruple;
}

	task PatternQuadruple{
			if( Obj_IsDeleted( objBoss ) ){ return; }
			while( !Obj_IsDeleted( objBoss ) ){
			let way = 4;
			let radius = 120;
			let shote = 810;
			let sideway = 16;
			loop( 1 ){
				let angle = rand( 0, 360 );
				loop( way ){
					Set( radius, angle, shote, sideway );
					angle += 360 / way;
				}
				PlaySound("LenenShot1",92,0);
				radius += 80;
				wait( 50 );
				}
			}
}

	task PatternMiniQuadruple{
			if( Obj_IsDeleted( objBoss ) ){ return; }
			while( !Obj_IsDeleted( objBoss ) ){
			let way = 4;
			let radius = 120;
			let shote = 520;
			let sideway = 6;
			let highway = 8;
			let aangle = rand( 0, 360 );
				loop( 1 ){
				let angle = rand( 0, 360 );
					loop( highway ){
						loop( way ){
						MiniSet( radius, angle, shote, sideway, aangle );
						angle += 360 / way;
							  }
						aangle += 360 / highway;
						         }
				PlaySound("LenenShot1",92,0);
				radius += 80;
				wait( 100 );
				}
			}
}
			task Set( radius, p, shote, way ){
				let pos = [ ObjMove_GetX( objBoss ), ObjMove_GetY( objBoss ) ];
				let bx = pos[0] + radius * cos( p );
				let by = pos[1] + radius * sin( p );
				let ag = p - 135;
				let delay = 16;
				let leng = 0;
				loop( way ){
					let tx = bx + leng * cos( ag );
					let ty = by + leng * sin( ag );
					let speed = GetDistanse( pos, [ tx, ty ] ) / 50;
					let angle = GetGapAngle( pos, [ tx, ty ] );
					CreateShot01( pos, 0, angle, speed / 120, speed, shote, delay );
					leng += ( radius * cos( 45 ) * 2 ) / ( way - 1 );
				}
			}

			task MiniSet( radius, p, shote, way, aangle ){
				let pos = [ ObjMove_GetX( objBoss ), ObjMove_GetY( objBoss ) ];
				let bx = pos[0] + radius * cos( p );
				let by = pos[1] + radius * sin( p );
				let ag = p - 135;
				let delay = 16;
				let leng = 0;
				loop( way ){
					let tx = bx + leng * cos( ag );
					let ty = by + leng * sin( ag );
					let speed = GetDistanse( pos, [ tx, ty ] ) / 45;
					let angle = GetGapAngle( pos, [ tx, ty ] );
					let s = CreateShot01( pos, 0, angle, speed / 120, speed, shote, delay );
					ObjMove_AddPatternA2( s, 70, 0, aangle, 0.02, 0, 1.5 );
					leng += ( radius * cos( 45 ) * 2 ) / ( way - 1 );
				}
			}
		

	function CreateShot01( pos, speed, angle, acc, maxspeed, shote, delay ){
	let sht = TShotA2( pos[0], pos[1], speed, angle, acc, maxspeed, shote, delay );
	NotifyEventAll( EV_USER + 40, [ sht, delay ] );
	return sht;
}
 
	function GetDistanse( pos1, pos2 ){
		return ( (pos2[1]-pos1[1])^2 + (pos2[0]-pos1[0])^2 ) ^ 0.5;
	}

	function GetGapAngle( pos1, pos2 ){
		return atan2( pos2[1]-pos1[1], pos2[0]-pos1[0] );
	}

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