#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Unused"]
#Text["Unused"]
#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("\"I didn't use this. xD\"",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	Sound(GCSD ~ "Butterfly.mp3");
	if(GetCommonData("IsFan",false)==true)
	{
		CallFan(-1);
	}
	wait(60);
	TShot1;
	wait(1200);
	DamageRateAtFrame(57,10,180);
	}
//----------------------------------------------------

task TShot1
{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){
	FireEffect(384,448,791,120,1);
	wait(60);
	FireEffect(0,448,791,120,-1);
	wait(180);
	BSet(1,30);
	wait(270);
	BSet(-1,30);
	wait(270);
	BSet(1,0);
	wait(180);
	}
}

task BSet(type,time)
{
	let color = round(rand(792,798));
	FireEffect(0,rand(0,448),color,120,1*type);
	wait(time);
	color = round(rand(792,798));
	FireEffect(384,rand(0,448),color,120,-1*type);
	wait(time);
	color = round(rand(792,798));
	FireEffect(rand(0,384),0,color,120,1*type);
	wait(time);
	color = round(rand(792,798));
	FireEffect(rand(0,384),448,color,120,-1*type);
	wait(time);
}

task ButterFlyCircle(px,py,color,way)
{
	PlaySound("BulletWave",95,0);
	ascent(i in 0..20)
	{
		ascent(j in 0..4)
		{
			BShot(px,py,1.5,i*18,j,color-500,8);
		}
	}
	
	task BShot(x,y,v,dir,j,color,delay)
	{
			let obj = TShotA1(x,y,v,dir,color,delay);
			ObjMove_SetAngularVelocity(obj,2.5*way);
			ObjMove_AddPatternA2(obj,60,v/1.25,NO_CHANGE,0.005+j/300,0,6);
			ObjShot_SetAutoDelete(obj,false);
			wait(180);
			ObjShot_SetAutoDelete(obj,true);
	}
}

task FireEffect(x,y,color,time,way)
{
	PlaySound("Eff2",95,0);
	ascent(i in 0..9)
	{
		FEffect(GetEnemyX, GetEnemyY, x, y, i*40, i*40,1,color,time-10);
		FEffect(GetEnemyX, GetEnemyY, x, y, i*40, i*40,-1,color,time-10);
	}
	wait(120);
	ButterFlyCircle(x,y,color,way);
}


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

task FEffect(x, y, x2, y2, angle, angle2,way,color,time){
				time = time/2;
				let vx=(x2-x)/time;
				let vy=(y2-y)/time;
				let r=0;
				let a=0;
					loop(time){
					angle+=1*way; angle2+=1*way;
					x+=vx; y+=vy;
					a+=360/time; r=60-60*cos(a);
					let sangle = GetPointAngle(x,y,x+r*cos(angle),y+r*sin(angle2));
					DummyShot(x+r*cos(angle), y+r*sin(angle2),0,sangle,color,0);
					wait(2);
					}
}

task DummyShot(x,y,spd,angle,color,delay)
{
	let dummy = ShotA1(x,y,spd,angle,color,0,delay);
	ObjRender_SetColor(dummy,32,32,32);
	ObjShot_SetIntersectionEnable(dummy,false);
	ObjShot_SetSpellResist(dummy,true);
	descent(i in 0..12)
	{
		ObjRender_SetScaleXYZ(dummy,2*i/24,2*i/24,0);
		yield;
	}
	Obj_Delete(dummy);
}

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

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