
#ScriptVersion[3]
#Title["YuyukoS4"]
#Text["YuyukoS4"]
#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(3000);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(70);
	}
		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("\"Butterfly's Enticing into the Afterlife\"",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	Sound(GCSD ~ "Butterfly.mp3");
	if(GetCommonData("IsFan",false)==true)
	{
		CallFan(-1);
	}
	wait(120);
	TShot1;
	wait(1200);
	DamageRateAtFrame(57,10,180);
	}
//----------------------------------------------------

task TShot1
{
	LaserSet(0);
	LaserSet(180);
	ButterflyBurst(30);
	ButterflyBurst(60);
	ButterflyBurst(90);
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){
	let sig = rand(360,360);
	wait(150);
	TrailSet(GetEnemyX-60,-1,sig);
	TrailSet(GetEnemyX+60,1,sig);
	wait(210);
	LaserSet(0);
	LaserSet(180);
	wait(210);
	TMovement(35,5,3);
	wait(120);
	LaserSet(0);
	LaserSet(180);
	ButterflyBurst(30);
	ButterflyBurst(60);
	ButterflyBurst(90);
	wait(150);
	TrailSet(GetEnemyX-60,1,60+sig);
	TrailSet(GetEnemyX+60,-1,60+sig);
	wait(210);
	LaserSet(0);
	LaserSet(180);
	wait(210);
	TMovement(35,5,3);
	wait(120);
	LaserSet(0);
	LaserSet(180);
	ButterflyBurst(30);
	ButterflyBurst(60);
	ButterflyBurst(90);
	}
}

task TrailSet(px,ang,sig)
{
	PlaySound("Boon2",95,0);
	ascent(i in 0..2+Level)
	{
		ButterflyTrail(i*360/(2+Level)+sig);
	}
	task ButterflyTrail(angle)
	{
		let core = TShotA1(px,GetEnemyY+60,2.25,angle,293,12);
		ObjMove_SetAngularVelocity(core,1*(px-GetEnemyX)/60);
		ObjShot_SetSpellResist(core,true);
		ObjShot_SetAutoDelete(core,false);
		Trail(core);
		ascent(i in -39..450)
		{
			if(i%50==0 && !Obj_IsDeleted(core))
			{
				PelletWave;
			}
			if(i==270)
			{
				ObjMove_SetAngularVelocity(core,0);
				ObjShot_SetAutoDelete(core,true);
			}
			yield;
		}
			task PelletWave
			{
				ascent(i in 0..3+Level)
				{
					PlaySound("Shot9",95,0);
					let obj = TShotOA1(core,0,ObjMove_GetAngle(core)+90,53,8);
					ObjMove_AddPatternA2(obj,0,NO_CHANGE,NO_CHANGE,0.01,0,1.5);
					obj = TShotOA1(core,0,ObjMove_GetAngle(core)-90,53,8);
					ObjMove_AddPatternA2(obj,0,NO_CHANGE,NO_CHANGE,0.01,0,1.5);
					obj = TShotOA1(core,0,ObjMove_GetAngle(core)+180,53,8);
					ObjMove_AddPatternA2(obj,0,NO_CHANGE,NO_CHANGE,0.01,0,1.5);
					wait(3);
				}
			}
			task Trail(obj)
			{
				while(!Obj_IsDeleted(obj))
				{
					let dummy = TShotOA1(obj,0,ObjMove_GetAngle(obj),ObjShot_GetImageID(obj)+500,0);
					Shrink(dummy,25);
					ObjShot_SetDeleteFrame(dummy,25);
					ObjShot_SetIntersectionEnable(dummy,false);
					wait(5);
				}
			}
	}
}

task Shrink(obj,time)
{
	ObjShot_SetSpellResist(obj,true);
	descent(i in 0..time)
	{
		ObjRender_SetScaleXYZ(obj,i/time,i/time,0);
		ObjRender_SetColor(obj,128,128,128);
		yield;
	}
	Obj_Delete(obj);
}

task SmartBurst
{
	ascent(i in 2..5)
	{
		PlaySound("Shot1",100,0);
		MiniBurst(i);
		wait(20);
	}
	task MiniBurst(num)
	{
		let ra = rand(0,360);
		let obj = TShotA2(GetEnemyX,GetEnemyY,num,num*120+ra,-num/60,0,310,12);
		wait(60);
		PlaySound("BulletWave",95,0);
		if(!Obj_IsDeleted(obj))
		{
			ascent(i in 0..24)
			{
				ascent(j in 0..4)
				{
					CreateShotA2(ObjMove_GetX(obj),ObjMove_GetY(obj),0,i*15+ra,0.0075+j/100,10,294,10);
				}
			}
		}
	}
}

task ButterflyBurst(delay)
{
	PlaySound("BulletWave",95,delay);
	ascent(i in 0..26+Level*4)
	{
		ascent(j in 0..4+Level)
		{
			CreateShotA2(GetEnemyX,GetEnemyY,0,i*360/(26+Level*4)+angleToPlayer+180/(26+Level*4),0.0075+j/100,10,292,delay);
		}
	}
}

	task LaserSet(offset)
	{
		ascent(i in -3-Level..4+Level)
		{
			if(i!=4+Level-1)
			{
				Laser(i);
			}
		}
		task Laser(pos)
		{
			let obj = CreateStraightLaserA1(GetEnemyX,GetEnemyY,270,500,30,75,1004,105);		
			let fangle = pos*360/(6+Level*2)+offset/(6+Level*2);
			let ratio = 0;
			let pangle = angleToPlayer+offset;
			ObjStLaser_SetSource(obj,true);
			PlaySound("Laser2",95,0);
			loop(90)
			{
				ObjStLaser_SetAngle(obj,pangle+fangle*sin(ratio));
				ObjMove_SetPosition(obj,GetEnemyX+60*cos(ObjStLaser_GetAngle(obj)),GetEnemyY+60*sin(ObjStLaser_GetAngle(obj)));
				let stick = TShotOA1(obj,0,0,777,12);
				ObjShot_SetDeleteFrame(stick,12);
				ratio += 90/90;
				yield;
			}
			loop(90)
			{
				let stick = TShotOA1(obj,0,0,777,12);
				ObjShot_SetDeleteFrame(stick,12);
				yield;
			}
			descent(i in 0..30)
			{
				ObjLaser_SetIntersectionWidth(obj,i);
				ObjLaser_SetRenderWidth(obj,i);
				yield;
			}
			
		}
	}

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

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