
#ScriptVersion[3]
#Title["YuyukoN2"]
#Text["YuyukoN2"]
#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
{
SetBoss("Yuyuko",false);
}

@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(5000);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(55);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	DamageRateAtFrame(100,25,360);
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,10);
	magiccircle(objBoss,1,-1);
	wait(90);
	Sound(GCSD ~ "Butterfly.mp3");
	PlaySound("Charge3",100,0);
	RayCharge("PURPLE",2,60);
	wait(105);
	CallFan(1);
	wait(45);
	PlaySound("Eff1",100,0);
	wait(60);
	TShot1;
	}

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

task TShot1
{
	let s = 1;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){
	WhirlWind(GetEnemyX-100*s,GetEnemyY+25,293,1);
	wait(90);
	WhirlWind(GetEnemyX+100*s,GetEnemyY+25,292,-1);
	wait(90);
	WhirlWind(GetEnemyX-100*s,GetEnemyY-25,293,-1);
	wait(60);
	WhirlWind(GetEnemyX+100*s,GetEnemyY-25,292,1);
	wait(60);
	WhirlWind(GetEnemyX-100*s,GetEnemyY,293,-1);
	wait(45);
	WhirlWind(GetEnemyX+100*s,GetEnemyY,292,1);
	wait(30);
	WhirlWind(GetEnemyX,GetEnemyY,292,-1);
	WhirlWind(GetEnemyX,GetEnemyY,293,1);
	wait(30);
	CallFan(-1);
	wait(30);
	PlaySound("Charge5",95,0);
	ShinkiCharge(30,"PINK");
	TMovement(25,10,3);
	wait(60);
	CircleButterfly;
	wait(120);
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,5);
	wait(120);
	CallFan(1);
	wait(120);
	s = -s;
	}
}

task CircleButterfly
{
	PlaySound("Eff1",100,0);
	PlaySound("BulletWave",92,90);
	PlaySound("BulletWave",92,180);
	PlaySound("BulletWave",92,225);
	let sangle = [rand(-9,9),rand(-12,12),rand(-15,15)];
	ascent(j in 0..5+Level*3)
	{
		ascent(i in 0..20)
		{
			ButterflyBullet(1+j/3.75,i*18+sangle[0],2.5);
			ButterflyBullet(1+j/3.75,i*18+sangle[0],-2.5);
		}
			ascent(i in 0..15)
		{
			ButterflyBullet2(0.75+j/3,i*24+sangle[1],1.25);
			ButterflyBullet2(0.75+j/3,i*24+sangle[1],-1.25);
		}
			ascent(i in 0..12)
		{
			ButterflyBullet3(0.5+j/3,i*30+sangle[2],1);
			ButterflyBullet3(0.5+j/3,i*30+sangle[2],-1);
		}
	}
	task ButterflyBullet(v,dir,angular)
	{
		let obj = TShotA1(GetEnemyX,GetEnemyY,2.3,dir,294,0);
		ObjShot_SetSpellResist(obj,true);
		ObjMove_SetAngularVelocity(obj,angular);
		wait(90);
		ObjMove_AddPatternA2(obj,0,1,NO_CHANGE,v/130,0,6);
	}
	task ButterflyBullet2(v,dir,angular)
	{
		let obj = TShotA1(GetEnemyX,GetEnemyY,1.5,dir,295,0);
		ObjMove_SetAngularVelocity(obj,angular);
		ObjShot_SetSpellResist(obj,true);
		wait(180);
		ObjMove_AddPatternA2(obj,0,1,NO_CHANGE,v/100,0,6);
	}
	task ButterflyBullet3(v,dir,angular)
	{
		let obj = TShotA1(GetEnemyX,GetEnemyY,0.75,dir,296,0);
		ObjMove_SetAngularVelocity(obj,angular);
		ObjShot_SetSpellResist(obj,true);
		wait(225);
		ObjMove_AddPatternA2(obj,0,1,NO_CHANGE,v/100,0,6);
	}
}

task WhirlWind(x,y,color,type)
{
	let sangle = rand(-12,12);
	PlaySound("BulletWave",92,0);
	ascent(i in 0..15)
	{
		ascent(j in 0..3+Level)
		{
			WWBullet(1+j*0.65,i*24+sangle);
		}
	}
	task WWBullet(v,dir)
	{
		let obj = TShotA1(x,y,v,dir,color,8);
		ObjMove_SetAngularVelocity(obj,type);
		wait(90);
		ObjMove_SetAngularVelocity(obj,0);
	}
}

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

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

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