
#ScriptVersion[3]
#Title["YuyukoN1"]
#Text["YuyukoN1"]
#Player[DEFAULT]
#System["./system/Default_System.txt"]
#Background["./BG.txt"]
#Player["./MoF_Reimu/Reimu.txt"]
#include"./Functions/Index.txt"
#include"./SetBoss.txt"
#include"./Shot/AllStarShot_Const.dnh"
#include"./system/Default_Effect.Txt"
#include"./Portrait_Const.dnh"
#include"./DialogueFunctions.dnh"


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("Yuyuko",false);
}

@MainLoop
{
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),25);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),26);
	yield;

}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(4000);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(55);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	ObjMove_SetPosition(objBoss,384/2,-120);
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,10);
	SetCommonData("CircleSize",0);
	magiccircle(objBoss,1,-1);
	NotifyEventAll(EV_DELETE_SONG,0);
	wait(180);
	DamageRateAtFrame(100,50,500);
	yield;
	NotifyEventAll(EV_SET_SONG,1);
	SizeCircle;
	wait(90);
	ScrollBG;
	TShot1;
	}

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

task TShot1
{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){
	ascent(i in 0..10+Level*5)
	{
		PlaySound("BulletWave",92,0);
		CurvyButterfly(2.5,210+i*15,293,1);
	}
	wait(60);
	PlaySound("BulletWave",92,0);
	ascent(i in 0..10+Level*5)
	{
		PlaySound("BulletWave",92,0);
		CurvyButterfly(2.5,330-i*15,293,-1);
	}
	wait(120);
	ascent(n in 0..3)
	{
	descent(i in 0..3+Level)
	{
		PlaySound("BulletWave",92,0);
		CurvyButterfly(2.5,330-i*20+n*120+60,293,-1);
		CurvyButterfly(2.5,210+i*20+n*120+60,293,1);
		CurvyButterfly(2.5,330-i*20-10+n*120+60,293,-1);
		CurvyButterfly(2.5,210+i*20+10+n*120+60,293,1);
	}
	wait(30);
	}
	wait(60);
	TMovement(25,5,3);
	wait(60);
	ascent(i in 0..4+Level)
	{
		PlaySound("BulletWave",92,0);
		ascent(j in 1..4+Level)
		{
			CurvyButterfly(2.5,210+i*45+j*5,294,1);
		}
	}
	wait(60);
	PlaySound("BulletWave",92,0);
	ascent(i in 0..4+Level)
	{
		PlaySound("BulletWave",92,0);
		ascent(j in 1..4+Level)
		{
			CurvyButterfly(2.5,330-i*45+j*5,294,-1);
		}
	}
	wait(120);
	ascent(n in 0..5)
	{
	descent(i in 0..3)
	{
		PlaySound("BulletWave",92,0);
		ascent(j in 2..4+Level)
		{
			CurvyButterfly(2.5,330-i*120+n*75+j*4,294,-1);
			CurvyButterfly(2.5,210+i*120+n*75+j*4,294,1);
		}
	}
	wait(20);
	}
	wait(45);
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,10);
	wait(45);
	if(Level<2)
	{
	FamiliarBullet(0);
	FamiliarBullet(180);
	}
	else
	{
	FamiliarBullet(-30);
	FamiliarBullet(30);
	FamiliarBullet(210);
	FamiliarBullet(150);
	}
	wait(60);
	BossShot;
	wait(240);
	BossShot2;
	wait(300);
	}
}

task FamiliarBullet(angle)
{
	PlaySound("Eff1",95,0);
	let core = TShotA1(GetEnemyX,GetEnemyY,0.75,angle,777,12);
	ObjShot_SetSpellResist(core,true);
	let s = 1;
	wait(60);
	ascent(m in 0..4){
	ascent(n in 0..6){
	PlaySound("BulletWave",92,0);
	ascent(i in 0..9+Level*3)
	{
		TShotOA1(core,3,i*360/(9+Level*3)+n*s*!(angle),53,6);
	}
	wait(5);
	}
	s = -s;
	wait(30);
	}
}

task BossShot
{
	let angle = 0;
	let s = 1;
	ascent(n in 0..24){
	PlaySound("BulletWave",90,0);
	angle += 1;
	ascent(i in 0..4+Level*2){
	ascent(j in 4..5){
	TShotA1(GetEnemyX+120*cos(angle),GetEnemyY+30*sin(angle),1.25+j/4,i*360/(4+Level*2)+GetAngleToPlayer(objBoss)+angle+45,281,12);
	TShotA1(GetEnemyX+120*cos(180-angle),GetEnemyY+30*sin(180-angle),1.25+j/4,i*360/(4+Level*2)+GetAngleToPlayer(objBoss)-angle-45,281,12);
	}
	}
	if(n%6!=5)
	{
	wait(5);
	}
	else{
	angle += 84;
	wait(30);
	}
	}
	s = -s;
}

task BossShot2
{
	ascent(n in 0..6)
	{
		PlaySound("BulletWave",92,0);
		PlaySound("BulletWave",90,135);
		ascent(i in 0..16+Level*4)
		{
			let angle = i*360/(16+Level*4)+n*(7+Level);
			let obj = TShotA1(GetEnemyX+30*cos(angle),GetEnemyY+30*sin(angle),1,angle,294+i%2,4);
			ObjMove_AddPatternA2(obj,0,NO_CHANGE,NO_CHANGE,0.01,-0.01,1.05);
			obj = TShotA1(GetEnemyX+30*cos(angle),GetEnemyY+30*sin(angle),1,angle,294+i%2,4);
			ObjMove_AddPatternA2(obj,0,NO_CHANGE,NO_CHANGE,0.01,-0.01,1.05);
			ObjMove_AddPatternA2(obj,135,NO_CHANGE,NO_CHANGE,0.04,0,5);
			obj = TShotA1(GetEnemyX+30*cos(angle),GetEnemyY+30*sin(angle),1,angle,294+i%2,4);
			ObjMove_AddPatternA2(obj,0,NO_CHANGE,NO_CHANGE,0.01,0,1.05);
			obj = TShotA1(GetEnemyX+30*cos(angle),GetEnemyY+30*sin(angle),1,angle,294+i%2,4);
			ObjMove_AddPatternA2(obj,0,NO_CHANGE,NO_CHANGE,0.01,0,1.05);
			ObjMove_AddPatternA2(obj,135,NO_CHANGE,NO_CHANGE,0.04,0,5);
		}
		wait(10);
	}
}

	task CurvyButterfly(spd,angle,color,way)
	{
		ascent(i in 0..8)
		{
			ButterflyBullet(0.01+i/200);
		}
			task ButterflyBullet(acc)
			{
			let obj = TShotA2(GetEnemyX,GetEnemyY,spd,angle,-spd/90,0.75,color,8);
			let angular = 4.5;
			while(angular>0)
			{
			ObjMove_SetAngle(obj,ObjMove_GetAngle(obj)+angular*way);
			angular -= 0.07;
			yield;
			}
			angular = 0;
			ObjMove_AddPatternA2(obj,0,NO_CHANGE,NO_CHANGE,acc,0,4);
		}
	}

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

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

task ScrollBG
{
	ascent(i in 100..500)
	{
		SetCommonData("Scroll",i/500);
		yield;
	}
}

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

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