
#ScriptVersion[3]
#Title["YuyukoN4"]
#Text["YuyukoN4"]
#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(5500);
	}
	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(60);
	Sound(GCSD ~ "Butterfly.mp3");
	PlaySound("Charge3",100,0);
	RayCharge("PURPLE",2,60);
	wait(105);
	PlaySound("Eff1",100,45);
	CallFan(1);
	wait(90);
	TShot1;
	}

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

task TShot1
{
	ButterflyLoop;
	wait(180);
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){
	PlaySound("Charge5",95,0);
	ShinkiCharge(30,"PINK");
	wait(60);
	PlaySound("Boon1",95,0);
	LaserSet;
	wait(240);
	}
}

task ButterflyLoop
{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		let randir = rand(-15,15);
		PlaySound("BulletWave",94,0);
		ascent(i in 0..9+Level*3)
		{
			Butterfly(GetEnemyX+100,GetEnemyY,i*360/(9+Level*3)+randir,1);
			Butterfly(GetEnemyX-100,GetEnemyY,i*360/(9+Level*3)+randir,-1);
		}
		wait(150);
		PlaySound("BulletWave",94,0);
		ascent(i in 0..9+Level*3)
		{
			Butterfly(GetEnemyX-100,GetEnemyY,i*360/(9+Level*3)+randir,1);
			Butterfly(GetEnemyX+100,GetEnemyY,i*360/(9+Level*3)+randir,-1);
		}
		wait(150);		
	}
	task Butterfly(x,y,dir,way)
	{
		ascent(j in 0..2+Level)
		{
			let v = 2+j*1.5;
			let obj = TShotA1(x,y,v,dir-j*5*way,291,8);
			ObjMove_AddPatternA2(obj,0,NO_CHANGE,NO_CHANGE,-v/90,way,v/2.5);
			ObjMove_AddPatternA2(obj,90,NO_CHANGE,NO_CHANGE,0,way/8,0);
		}
	}
}

	task LaserSet
	{
		ascent(i in -6-Level*3..7+Level*3)
		{
			Laser(i);
		}
		task Laser(pos)
		{
			let obj = CreateStraightLaserA1(GetEnemyX,GetEnemyY,270,500,20,30,1004,135);
			let fangle = pos*360/(12+Level*6);
			let ratio = 0;
			let pangle = angleToPlayer+180;
			loop(120)
			{
				ObjStLaser_SetAngle(obj,pangle+fangle*sin(ratio));
				ratio += 90/120;
				yield;
			}
			wait(15);
			PlaySound("Eff1",95,0);
			ObjLaser_SetRenderWidth(obj,15);
			ObjLaser_SetIntersectionWidth(obj,15);
			let dummy = CreateStraightLaserA1(GetEnemyX,GetEnemyY,pangle+fangle,500,35,0,1005,0);
			ObjShot_SetIntersectionEnable(dummy,false);
			ObjRender_SetColor(obj,192,128,128);
			ObjRender_SetColor(dummy,128,128,128);
			ascent(j in 0..8+Level*2)
			{
				if(pos!=7+Level*3-1)
				{
					CreateShotA2(GetEnemyX,GetEnemyY,0,pangle+fangle,0.005+j/200,10,793,0);
				}
			}
			
		}
	}

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

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

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