#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Flipping Sign\"Flip a table [Normal]\""]
#Text["Spell2N"]
#Background["./BG.txt"]
#Player[DEFAULT]
#System["./system/Default_System2.txt"]
#include"./Functions/Index.txt"
#include"./SetBoss.txt"
#include"./Shot/ZUNShot_Const.txt"
#include"./system/Default_Effect.Txt"


let objBoss;
let GCSD=GetCurrentScriptDirectory~"";
let enemy;
let bSpell=false;
let stgx=GetStgFrameWidth()/2;
let stgy=GetStgFrameHeight()/2;
let fog = 0;
let objScene=GetEnemyBossSceneObjectID();
let arr = [1,6,4,2,3,5,0];
let xis = 0;
let yis = 0;
@Initialize
{
SetBoss(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(2225);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(3000000);
	}
}

//----------------------------------------------------
task mainTask{
	SetShotAutoDeleteClip(64,64,64,16);
	DamageRateAtFrame(50,0,180);
	DamageRateAtFrame(75,0,1380);
	magiccircle(objBoss,0.8,true);
	ObjMove_SetDestAtWeight(objBoss,stgx,140,10,7);
	Cutin("Flipping Sign\"Flip a table [Normal]\"",15);
	ObjEnemyBossScene_StartSpell(objScene);
	wait(90);
	TShot1;
	}
//----------------------------------------------------

task TShot1{
	while(!Obj_IsDeleted(objBoss)){
	descent(n in 0..24){
		PlaySound("Shot1",95,0);
		ascent(i in 0..6){
			let shot = ShotA1(i*116+63*sin(n*67),n*10+rand(-2,2),rand(0.1,0.2),90+10*sin(n*67),379,0,8);
			ObjMove_AddPatternA2(shot,180,0,NO_CHANGE,rand(0.01,0.02),0,rand(1,3));
			ObjShot_SetSpellResist(shot,true);
				if(n%3==0){
				ShotA1(i*116+63*sin(n*67),n*10+rand(-2,2),rand(2,3),90+10*sin(n*67),379,0,8);
				}
		}
		wait(5);
	}
	TRotate;
	wait(150);
	TMovement(50,5,1);
	ascent(n in 0..4){
		PlaySound("Shot3",92,0);
		ascent(i in 0..7){
		ShotOA1(objBoss,2,angleToPlayer+i*30-90,294,0,12);
		}
		wait(30);
	}
	wait(135);
	TRotate2;
	ObjMove_SetDestAtWeight(objBoss,stgx,140,10,2);
	wait(45);
	ascent(n in 0..24){
		PlaySound("Shot1",95,0);
		ascent(i in 0..3){
			let shot = ShotA1(168-n*7+rand(-2,2),i*220+90*sin(n*47),rand(0.1,0.2),15*sin(n*47),376,0,8);
			ObjMove_AddPatternA2(shot,180,0,NO_CHANGE,rand(0.01,0.02),0,rand(1,3));
			ObjShot_SetSpellResist(shot,true);
			shot = ShotA1(472+n*7+rand(-2,2),i*220+90*sin(n*47),rand(0.1,0.2),180+15*sin(n*47),376,0,8);
			ObjMove_AddPatternA2(shot,180,0,NO_CHANGE,rand(0.01,0.02),0,rand(1,3));
			ObjShot_SetSpellResist(shot,true);
		}
		wait(5);
	}
	TRotate3;
	wait(150);
	TMovement(50,5,1);
	ascent(n in 0..4){
		PlaySound("Shot3",92,0);
		ascent(i in 0..7){
		ShotOA1(objBoss,2,angleToPlayer+i*30-90,293,0,12);
		}
		wait(30);
	}
	wait(135);
	TRotate4;
	ObjMove_SetDestAtWeight(objBoss,stgx,140,10,2);
	wait(45);
	}
		task Manage(shot){
		wait(180);
		ObjMove_AddPatternA2(shot,0,0,GetAngleToPlayer(shot),rand(0.0075,0.01),0,rand(1,3));
		}
}

task TRotate{
	maple(2);
	wait(70);
	PlaySound("Boon1",100,0);
	ClearBullet2(15,60);
	loop(60){
	if(Obj_IsDeleted(objBoss)){break;}
	Set2DCameraRatioY(cos(yis));
	yis+=3;
	yield;
	}
}

task TRotate2{
	yis = 180;
	PlaySound("Boon1",100,0);
	ClearBullet(30,30);
	loop(60){
	if(Obj_IsDeleted(objBoss)){break;}
	Set2DCameraRatioY(cos(yis));
	yis+=3;
	yield;
	}
}

task TRotate3{
	maple(2);
	wait(70);
	PlaySound("Boon1",100,0);
	ClearBullet2(15,60);
	loop(60){
	if(Obj_IsDeleted(objBoss)){break;}
	Set2DCameraRatioX(cos(xis));
	xis+=3;
	yield;
	}
}

task TRotate4{
	xis = 180;
	PlaySound("Boon1",100,0);
	ClearBullet(30,30);
	loop(60){
	if(Obj_IsDeleted(objBoss)){break;}
	Set2DCameraRatioX(cos(xis));
	xis+=3;
	yield;
	}
}

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

task TRender
{
	DrawBoss;
}

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

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