
#ScriptVersion[3]
#Title["YuyukoS1"]
#Text["YuyukoS1"]
#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();
let color = [276,277,278];
let color2 = [51,53,55];
let dcolor = [308,309,310];
@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);
	yield;

}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(3000);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(55);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	magiccircle(objBoss,1,-1);
	DamageRateAtFrame(100,50,180);
	ObjMove_SetDestAtWeight(objBoss,stgx,140,10,7);
	Cutin("\"Butterflies Rebirth\"",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	Sound(GCSD ~ "Butterfly.mp3");
	wait(90);
	TShot1;
	}
//----------------------------------------------------

task TShot1
{
	let s = 1;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){
	PlaySound("Eff5",95,0);
	ascent(i in 0..5+(Level^2)*2)
	{
		BButterfly(i*360/(5+(Level^2)*2),i,s);
	}
	wait(150);
	TMovement(25,5,3);
	wait(150);
	PlaySound("Eff5",95,0);
	ascent(i in 0..5+(Level^2)*2)
	{
		BButterfly(i*360/(5+(Level^2)*2),i,-s);
	}
	wait(150);
	TMovement(25,5,3);
	wait(150);
	ascent(n in 0..3){
	ascent(i in 0..2+(Level^2))
	{
		PlaySound("Eff5",95,0);
		BButterfly(GetAngleToPlayer(objBoss)+i*360/(2+(Level^2))+n*180/(2+(Level^2)),i*2,0);
	}
	wait(30);
	}
	wait(165);
	ObjMove_SetDestAtWeight(objBoss,stgx,140,10,5);
	wait(165);
	s = -s;
	}
}

task BButterfly(angle,num,way)
{
	let core = TShotA1(GetEnemyX,GetEnemyY,3,angle,color[num%3]+500,12);
	let sangle = rand(-6,6);
	ObjShot_SetSpellResist(core,true);
	CheckWall;
	ObjMove_AddPatternA2(core,0,NO_CHANGE,NO_CHANGE,-3/45,2*way,0.5);
	wait(60);
	ObjMove_AddPatternA2(core,0,NO_CHANGE,NO_CHANGE,5/120,0.1*way,5);
		task CheckWall
		{
			let count = 0;
			while(ObjMove_GetX(core)>0 && ObjMove_GetX(core)<384 && ObjMove_GetY(core)>0 && ObjMove_GetY(core)<448)
			{
				if(count%14==num*2 && count<75)
				{
					PlaySound("Shot6",95,0);
					ascent(i in 0..9)
					{
					TShotOA1(core,rand(1.25,3.25),GetAngleToPlayer(core)+i*40+rand(-0.5,0.5),color2[num%3]+500,6);
					}
				}
				/*if(count%2==0)
				{
					DummyShot;
				}*/
				count++;
				yield;
			}
			PlaySound("BulletWave",92,0);
			ascent(i in -6..7){
			SpiritBullet(ObjMove_GetX(core),ObjMove_GetY(core),rand(2,7),ObjMove_GetAngle(core)+i*13+180+sangle);
			}
		}
		task SpiritBullet(x,y,v,angle)
		{
			let spir = TShotA2(x,y,v,angle,-v/60,0,color[num%3],8);
			Obj_SetVisible(spir,false);
			ObjShot_SetIntersectionEnable(spir,false);
			ObjShot_SetSpellResist(spir,true);
			Trail;
			wait(60);
			if(GetDistance(GetPlayerX,GetPlayerY,ObjMove_GetX(spir),ObjMove_GetY(spir))>30)
			{
			let obj = TShotOA1(spir,0,angle,color[num%3]+16,12);
			ObjMove_AddPatternA2(obj,0,NO_CHANGE,NO_CHANGE,0.015,0,2.25);
			ObjShot_SetSpellResist(obj,true);
			}
			Obj_Delete(spir);
			task Trail
			{
				while(!Obj_IsDeleted(spir))
				{
					let dummy = TShotOA1(spir,0,angle,color[num%3]+16+500,0);
					Shrink(dummy,20);
					ObjShot_SetDeleteFrame(dummy,20);
					ObjShot_SetIntersectionEnable(dummy,false);
					wait(3);
				}
			}
		}
		task DummyShot
		{
					let dummy = TShotOA1(core,0,0,color[num%3]+500,0);
					ObjShot_SetIntersectionEnable(dummy,false);
					Shrink(dummy,20);
		}
}

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

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

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