
#ScriptVersion[3]
#Title["YuyukoS2"]
#Text["YuyukoS2"]
#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"


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();
@Initialize
{
Sound(GCSD ~ "Little.mp3");
SetBoss("Yuyuko",true);
}

@MainLoop
{
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),25);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),26);
	if(GetCommonData("IsFan",false)==true){
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss)-90,ObjMove_GetY(objBoss),26*3.5);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss)+90,ObjMove_GetY(objBoss),26*3.5);
	}
	yield;

}

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

//----------------------------------------------------
task mainTask{
	magiccircle(objBoss,1,-1);
	DamageRateAtFrame(47,10,180);
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,7);
	Cutin("Cherry Blossom \"Saigyou Tornado\"",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	Sound(GCSD ~ "Butterfly.mp3");
	if(GetCommonData("IsFan",false)==true)
	{
		CallFan(0);
	}
	else
	{
		CallFan(1);
	}
	wait(60);
	TShot1;
	wait(1200);
	DamageRateAtFrame(57,10,180);
	}
//----------------------------------------------------

task TShot1
{
	PlaySound("Charge3",100,0);
	RayCharge("PINK",2,60);
	wait(90);
	TCycle(1);
	TCycle(-1);
	wait(120);
	TButterfly(GetEnemyX,2.25,294,1750);
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>1750){yield;}
	DamageRateAtFrame(0,0,0);
	ClearBullet(10,100);
	wait(60);
	PlaySound("Charge3",100,0);
	RayCharge("PINK",2,60);
	wait(90);
	DamageRateAtFrame(47,10,0);
	TCycle2;
	wait(120);
	TButterfly(GetEnemyX-125,2.5,292,0);
	TButterfly(GetEnemyX+125,2.5,292,0);
}

task TButterfly(px,spd,color,life)
{
	
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>life)
	{
		PlaySound("Shot6",95,0);
		ascent(i in 0..15)
		{
			ascent(j in 0..3+Level^2)
			{
				let obj = TShotA1(px,GetEnemyY,spd+j*0.4,i*24+angleToPlayer,color,8);
				ObjMove_SetAngle(obj,i*24+GetAngleToPlayer(obj));
			}
		}
		wait(90);
	}
}

task TCycle(type)
{
	let count = 0;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>1750){
		PlaySound("BulletWave",92,0);
		ascent(i in 0..9+Level*3)
		{
			let angle = i*360/(9+Level*3)+count*4.7*type+count*180/(9+Level*3);
			let obj = TShotA2(GetEnemyX+125*type,GetEnemyY,0.5,angle,0.02,4,809,8);
			ObjMove_SetAngularVelocity(obj,0.85*type);
			ObjMove_AddPatternA2(obj,120,NO_CHANGE,NO_CHANGE,-0.04,0,1.5);
		}
		count++;
		if(Level==2)
		{
			wait(20);
		}
		else
		{
			wait(30);
		}
	}
}

task TCycle2
{
	let s = 1;
	let count = 0;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		PlaySound("BulletWave",91,0);
		ascent(i in 0..9+Level*3)
		{
			let angle = i*360/(9+Level*3)+count*6*s+count*180/(9+Level*3);
			let obj = TShotA2(GetEnemyX,GetEnemyY,1,angle,0.02,5,809,8);
			ObjMove_SetAngularVelocity(obj,1.5*s);
			ObjMove_AddPatternA2(obj,120,NO_CHANGE,NO_CHANGE,-0.04,0,1.75);
		}
		count++;
		s = -s;
		if(Level==2)
		{
			wait(10);
		}
		else
		{
			wait(15);
		}
	}
	
}

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

task FEffect(x, y, x2, y2, angle, angle2,color,time){
				let vx=(x2-x)/time;
				let vy=(y2-y)/time;
				let r=0;
				let a=0;
					loop(time){
					//angle+=1; angle2+=1;
					x+=vx; y+=vy;
					a+=360/time; r=150-150*cos(a);
					let sangle = GetPointAngle(x,y,x+r*cos(angle),y+r*sin(angle2));
					let dummy = ShotA1(x+r*cos(angle), y+r*sin(angle2),0,sangle,color,0,12);
					ObjShot_SetDeleteFrame(dummy,0);
					yield;
					}
}

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

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