#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["SP2"]
#Text["SP2"]
#Background["./BG.txt"]
#Player[DEFAULT]
#System["./system/Default_System.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 s = 1;
let objScene=GetEnemyBossSceneObjectID();
let arr = [1,6,4,2,3,5,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(2000);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(3000000);
	}
}

//----------------------------------------------------
task mainTask{
	DamageRateAtFrame(50,25,240);
	magiccircle(objBoss,0.8,true);
	ObjMove_SetDestAtWeight(objBoss,stgx,130,10,7);
	Cutin("Second Card\"Boisterous Snake Snow\"",15,"SHOU");
	ObjEnemyBossScene_StartSpell(objScene);
	wait(60);
	TShot1;
	}
//----------------------------------------------------

task TShot1{
	let x = 0;
	let y = 0;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>=1000){
	maple(2);
	wait(60);
	loop(2){
	x = 0;
	y = stgy+rand(-150,150);
	Snake(x,y,getDotAngle(stgx,stgy,x,y)+rand(-45,45),15);
	wait(10);
	x = 384;
	y = stgy+rand(-150,150);
	Snake(x,y,getDotAngle(stgx,stgy,x,y)+rand(-45,45),15);
	wait(10);
	x = stgx+rand(-150,150);
	y = 0;
	Snake(x,y,getDotAngle(stgx,stgy,x,y)+rand(-45,45),15);
	wait(10);
	x = stgx+rand(-150,150);
	y = 448;
	Snake(x,y,getDotAngle(stgx,stgy,x,y)+rand(-45,45),15);
	wait(10);
	}
	if(ObjEnemy_GetInfo(objBoss,INFO_LIFE)<1000){break;}
	wait(90);
	if(ObjEnemy_GetInfo(objBoss,INFO_LIFE)<1000){break;}
	TAccel(40,5,0.1,60);
	wait(90);
	if(ObjEnemy_GetInfo(objBoss,INFO_LIFE)<1000){break;}
	maple(2);
	wait(60);
	loop(2){
	x = 0;
	y = stgy+rand(-100,100);
	Snake(x,y,getDotAngle(GetPlayerX,GetPlayerY,x,y)+rand(-3,3),12);
	wait(10);
	x = 384;
	y = stgy+rand(-100,100);
	Snake(x,y,getDotAngle(GetPlayerX,GetPlayerY,x,y)+rand(-3,3),12);
	wait(10);
	x = stgx+rand(-100,100);
	y = 0;
	Snake(x,y,getDotAngle(GetPlayerX,GetPlayerY,x,y)+rand(-3,3),12);
	wait(10);
	x = stgx+rand(-100,100);
	y = 448;
	Snake(x,y,getDotAngle(GetPlayerX,GetPlayerY,x,y)+rand(-3,3),12);
	wait(10);
	}
	if(ObjEnemy_GetInfo(objBoss,INFO_LIFE)<1000){break;}
	wait(90);
	if(ObjEnemy_GetInfo(objBoss,INFO_LIFE)<1000){break;}
	TAccel(40,5,0.1,60);
	wait(90);
	if(ObjEnemy_GetInfo(objBoss,INFO_LIFE)<1000){break;}
	}
	ObjMove_SetDestAtWeight(objBoss,stgx,130,10,2);
	ClearBullet(100,20);
	DamageRateAtFrame(0,0,0);
	maple(3);
	wait(100);
	DamageRateAtFrame(50,25,0);
	while(!Obj_IsDeleted(objBoss)){
		x = 0;
		y = stgy+rand(-150,150);
		Snake(x,y,getDotAngle(stgx,stgy,x,y)+rand(-45,45),10);
		wait(15);
		x = 384;
		y = stgy+rand(-150,150);
		Snake(x,y,getDotAngle(stgx,stgy,x,y)+rand(-45,45),10);
		wait(15);
		x = stgx+rand(-150,150);
		y = 0;
		Snake(x,y,getDotAngle(stgx,stgy,x,y)+rand(-45,45),10);
		wait(15);
		x = stgx+rand(-150,150);
		y = 448;
		Snake(x,y,getDotAngle(stgx,stgy,x,y)+rand(-45,45),10);
		wait(15);
	}
}

task Snake(x,y,dir,num){
	let dummy = CreateStraightLaserA1(x,y,dir,0,15,0,1014,30);
	PlaySound("Laser3",95,0);
	ascent(i in 0..30){
	ObjLaser_SetLength(dummy,i*20);
	yield;
	}
	ObjLaser_SetRenderWidth(dummy,5);
	let shot = CurvyLaser(x,y,6,dir-10,6,20,707,0);
	Stable;
	wait(10);
		while(CheckBoundaries(ObjMove_GetX(shot),ObjMove_GetY(shot),0)==true){yield;}
		PlaySound("Shot1",95,0);
		ascent(i in 0..num){
		ascent(a in 0..2){
		ShotA1(ObjMove_GetX(shot),ObjMove_GetY(shot),1+a/2,i*360/num,111,208,6);
		}
		}
		task Stable{
				while(!Obj_IsDeleted(shot)){
				ObjMove_SetAngularVelocity(shot,2);
				wait(10);
				ObjMove_SetAngularVelocity(shot,-2);
				wait(10);
				}
		}
	}

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

task TRender
{
	DrawBoss;
}

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

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