
#ScriptVersion[3]
#Title["YuyukoN3"]
#Text["YuyukoN3"]
#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(4000);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(55);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	DamageRateAtFrame(100,25,180);
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,10);
	magiccircle(objBoss,1,-1);
	CallFan(-1);
	Sound(GCSD ~ "Butterfly.mp3");
	wait(120);
	TShot1;
	}

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

task TShot1
{
	let count = 0;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		let startangle = rand(0,360);
		ascent(i in 0..15)
		{
			ascent(j in 0..1+Level)
			{
				KnifeSet(i*(63-Level*10)+j*360/(1+Level)+startangle,1,0);
			}
		wait(10);
		}
		wait(60);
		ascent(i in 0..18)
		{
			ascent(j in 0..1+Level)
			{
				KnifeSet(-i*(63-Level*10)+j*360/(1+Level)+startangle,1,1);
			}
		wait(8);
		}
		TMovement(35,10,5);
		wait(60);
		ascent(i in 0..8+Level*4)
		{
				KnifeSet(i*360/(8+Level*4)+startangle,1,0);
		}	
		wait(45);
		ascent(i in 0..8+Level*4)
		{
				KnifeSet(i*360/(8+Level*4)+180/(8+Level*4)+startangle,1,1);
		}
		wait(45);
		ascent(i in 0..8+Level*4)
		{
				KnifeSet(i*360/(8+Level*4)+startangle,1,0);
		}
		wait(30);
		ObjMove_SetDestAtWeight(objBoss,stgx,120,10,5);
	    wait(60);
		BubbleSet;
		//ArrowSet;
		count++;
		wait(90);
	}
	task ArrowSet
	{
		ascent(i in 0..15)
		{
			Arrow(i*24+angleToPlayer+12);
		}
	}
	task BubbleSet
	{
		PlaySound("Shot6",95,0);
		ascent(i in 0..12+6*Level)
		{
			ascent(j in 0..3)
			{
				ShotA1(GetEnemyX,GetEnemyY,1+j,i*360/(12+6*Level)+angleToPlayer,828,0,12);
			}
		}
	}
	task KnifeSet(angle,type,pcolor)
	{
		ascent(i in 0..4)
		{
			PlaySound("Shot6",96,0);
			Knife(angle-i,type,pcolor);
			Knife(angle+i,-type,pcolor);
			wait(7);
		}
	}
}

task Arrow(angle)
{
	PlaySound("Shot1",95,0);
	PlaySound("Eff1",95,45);
	ascent(i in -3..4)
	{
		ascent(j in 0..4)
		{
		let v = 1-(|i|)/9+j*0.75;
		let obj = TShotA1(GetEnemyX,GetEnemyY,v/5,angle+i*1.5+j*12,57,8);
		ObjMove_AddPatternA2(obj,45,NO_CHANGE,NO_CHANGE,v/60,0,v);
		if(i==0)
		{
			obj = TShotA1(GetEnemyX,GetEnemyY,v/5,angle+i*1.5+j*12+12,747,8);
			ObjMove_AddPatternA2(obj,45,NO_CHANGE,NO_CHANGE,v/60,0,v);
		}
		}
	}
}

task Knife(angle,type,pcolor)
{
	let color = [304+pcolor,59+pcolor*3];
	let obj = TShotA2(GetEnemyX,GetEnemyY,5,angle,-5/30,1,color[0],8);
	//ObjMove_SetAngularVelocity(obj,type/4);
	wait(30);
	ObjMove_AddPatternA2(obj,0,NO_CHANGE,NO_CHANGE,0.02,type*0.5,3);
	if(!Obj_IsDeleted(obj))
	{
		TShotA2(ObjMove_GetX(obj),ObjMove_GetY(obj),ObjMove_GetSpeed(obj),ObjMove_GetAngle(obj),0.015,6,color[1],6);
	}
	wait(90);
	ObjMove_SetAngularVelocity(obj,0);
}
//---------------------------------------------------

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

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