#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["BonusSpellCard"]
#Text["BonusSpellCard"]
#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
{
SetPlayerLife(0);
SetPlayerSpell(0);
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(40);
	}
	case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
	case(EV_REQUEST_IS_DURABLE_SPELL)
	{
		SetScriptResult(true);
	}
}

//----------------------------------------------------
task mainTask{
	magiccircle(objBoss,1,-1);
	DamageRateAtFrame(47,10,180);
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,7);
	Sound(GCSD ~ "Butterfly.mp3");
	wait(60);
	SetCommonData("FanAtYuyuko",0);
	PlaySound("Charge3",100,0);
	RayCharge("PURPLE",2,60);
	wait(120);
	CallFan(1);
	Cutin("\"????????\"",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	ObjMove_SetDestAtWeight(objBoss,stgx,-1200,10,10);
	//ManualPlayerClip;
	wait(120);
	TShot1;
	wait(1200);
	DamageRateAtFrame(57,10,180);
	}
//----------------------------------------------------

task TShot1
{
	PlaySound("Charge4",100,0);
	ShinkiCharge(45,"PURPLE");
	wait(60);
	CycleShot("-150");
	CycleShot("150");
	wait(420);
	PlaySound("Charge4",100,0);
	//ShinkiCharge(45,"AQUA");
	wait(60);
	UpperShot(-120);
	UpperShot(120);
	wait(420);
	PlaySound("Charge4",100,0);
	//ShinkiCharge(45,"YELLOW");
	wait(60);
	SideShot(-200);
	SideShot(200);
	wait(420);
	PlaySound("Charge4",100,0);
	//ShinkiCharge(45,"GREEN");
	wait(60);
	BottomShot(-120);
	BottomShot(120);
}

task BottomShot(pos)
{
	let count = 0;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		TrailSet(GetPlayerX+pos,-0.5,count*17);
		wait(60);
		TrailSet(GetPlayerX+pos,0.5,count*17);
		wait(60);
		count++;
	}
}

task TrailSet(px,ang,sig)
{
	ascent(i in 0..4)
	{
		ButterflyTrail(i*90+sig);
	}
	task ButterflyTrail(angle)
	{
		let core = TShotA1(px,GetPlayerY+100,1.25,angle,296,12);
		ObjMove_SetAngularVelocity(core,ang);
		ObjShot_SetSpellResist(core,true);
		ObjShot_SetAutoDelete(core,false);
		Trail(core);
		wait(240);
		ObjMove_SetAngularVelocity(core,0);
		ObjShot_SetAutoDelete(core,true);
			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(3);
				}
			}
	}
		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;
			}
		}
}

task SideShot(pos)
{
	let count = 0;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		PlaySound("Shot5",95,0);
		ascent(i in -1..2)
		{
			let px = GetPlayerX+pos;
			let py = GetPlayerY;
			let angle = GetPointAngle(GetPlayerX,GetPlayerY,px,py);
			ascent(j in 0..3)
			{
				let obj = ShotA2(GetPlayerX+pos,GetPlayerY,1,i*50+angle,0.005+j/200,3.5,305,0,8);
				ImmuneDelay(obj);
			}
		}
		count++;
		wait(90);
	}
}

task UpperShot(pos)
{
	let count = 0;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		PlaySound("Shot6",95,0);
		ascent(i in 0..3)
		{
			let obj = ShotA2(GetPlayerX+pos,GetPlayerY-90,1,i*120+count*27*pos/120,0.005,2,279,0,12);
			ImmuneDelay(obj);
		}
		count++;
		wait(45);
	}
}

task CycleShot(pos)
{
	let count = 0;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		PlaySound("BulletWave",90,0);
		ascent(i in 0..2)
		{
			let obj = TShotA2(GetPlayerX+pos,GetPlayerY,0.75,i*180+count*9*-pos/90,0.005,2.25,5,8);
			ImmuneDelay(obj);
		}
		count++;
		wait(8);
	}
}

task ImmuneDelay(obj)
{
		ObjShot_SetAutoDelete(obj,false);
		wait(120);
		ObjShot_SetAutoDelete(obj,true);
}

task ManualPlayerClip
{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		if(GetPlayerX<120)
		{
			ObjMove_SetX(GetPlayerObjectID,120);
		}
		if(GetPlayerX>384-120)
		{
			ObjMove_SetX(GetPlayerObjectID,384-120);
		}
		yield;
	}
}
//----------------------------------------------------

task TEnd{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
		ObjMove_SetPosition(objBoss,stgx,120);
		SetCommonData("IsFan",false);
		EndBoss(1);
		yield;
		CloseScript(GetOwnScriptID());
	}