#東方弾幕風[Single]
#ScriptVersion[3]
#Title["Discernment\"Ray of Ninth Articles\""]
#Text["Spell6"]
#Background["./Background.txt"]
#BGM[DEFAULT]
#Player[DEFAULT]

#include"./Functions/Index.txt"
#include"script/Miko/Shot/ZUNShot_Const.txt"
#include"script/Default_system/Default_Effect.Txt"

let objBoss;
let enemy;
let bSpell=false;
let GCSD=GetCurrentScriptDirectory~"";
let stgx=GetStgFrameWidth()/2;
let stgy=GetStgFrameHeight()/2;
let idle = true;
let objScene=GetEnemyBossSceneObjectID();
let s2 = 1;
let count = 0;
let spd = 3;

let orbcolor = [ORB_RED,ORB_YELLOW,ORB_GREEN,ORB_AQUA,ORB_BLUE,ORB_PURPLE];
let gcolor = [G_LARGE_RED,G_LARGE_YELLOW,G_LARGE_GREEN,G_LARGE_AQUA,G_LARGE_BLUE,G_LARGE_PURPLE];
@Initialize
{
LoadTexture(GCSD~"shot/ZUNShot.png");
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	ObjMove_SetDestAtWeight(objBoss,stgx,150,10,7);
	ObjEnemy_SetDamageRate(objBoss,0,0);
	mainTask;
	TRender;
	TEnd;
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);//出現と同時に敵弾を全て削除	
}

@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(3500);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(40000);
	}
}

//----------------------------------------------------
task mainTask{
	SetShotAutoDeleteClip(64,64,64,64);
	wingset(2);
	ObjEnemy_SetDamageRate(objBoss,50,20);
	PlaySound("cardcall",100,0);
	ObjEnemyBossScene_StartSpell(objScene);
	Cutin("Miko","Discernment\"Ray of Ninth Articles\"",15);
	wait(60);
	TLaser;
	//TTest;
	}
//----------------------------------------------------

task TTest{
	let dir = 0;
	loop(3){
	set(90);
	wait(60);
	ascent(i in 0..36){
	PlaySound("Eff4",95,0);
	dir = i*10+5;
	let obj = CreateStraightLaserA1(GetEnemyX,GetEnemyY-70,dir,500,15,0,G_LARGE_YELLOW,30);
	let shot = ShotA1(GetEnemyX,GetEnemyY-70,0,0,ORB_YELLOW,60);
	ObjShot_SetDeleteFrame(shot,0);
	}
	wait(50);
	ascent(i in 0..36){
	PlaySound("Eff2",95,0);
	dir = i*10+5;
	let obj = CreateStraightLaserA1(GetEnemyX,GetEnemyY-70,dir,0,15,60,G_LARGE_YELLOW,0);
	let shot = ShotA1(GetEnemyX,GetEnemyY-70,0,0,ORB_YELLOW,60);
	ObjShot_SetDeleteFrame(shot,0);
	ManageLaser(obj);
	TShot(GetEnemyX,GetEnemyY-70,dir,i);
	}
	ascent(i in 0..12){
	let shot = LargeBullet(GetEnemyX,GetEnemyY-70,0,i*30,0.04,5,249,30);
	ObjMove_SetAngularVelocity(shot,1);
	shot = LargeBullet(GetEnemyX,GetEnemyY-70,0,i*30,0.04,5,249,30);
	ObjMove_SetAngularVelocity(shot,-1);
	}
	wait(60);
	TMovement(30,5,5);
	wait(60);
	}
	}

task TLaser{
	let dir = 0;
	let p  = 0;
	let s = 1;
	while(!Obj_IsDeleted(objBoss)){
	dir = getDotAngle(GetPlayerX,GetPlayerY,GetEnemyX,GetEnemyY-70);
	set(120);
	wait(60);
	ascent(i in 0..5){
	PlaySound("Eff3",95,0);
	CreateStraightLaserA1(GetEnemyX,GetEnemyY-70,dir+i*3,500,15,0,G_LARGE_YELLOW,70);
	CreateStraightLaserA1(GetEnemyX,GetEnemyY-70,dir-i*3,500,15,0,G_LARGE_YELLOW,70);
	let shot = ShotA1(GetEnemyX,GetEnemyY-70,0,0,ORB_YELLOW,60);
	ObjShot_SetDeleteFrame(shot,0);
	wait(4); 
	}
	ascent(i in 15..25){
	PlaySound("Eff3",95,0);
	CreateStraightLaserA1(GetEnemyX,GetEnemyY-70,dir+i*5,500,15,0,G_LARGE_YELLOW,70);
	CreateStraightLaserA1(GetEnemyX,GetEnemyY-70,dir-i*5,500,15,0,G_LARGE_YELLOW,70);
	let shot = ShotA1(GetEnemyX,GetEnemyY-70,0,0,ORB_YELLOW,60);
	ObjShot_SetDeleteFrame(shot,0);
	wait(3);
	}
	ascent(i in 0..5){
	PlaySound("Eff2",95,0);
	let obj = CreateStraightLaserA1(GetEnemyX,GetEnemyY-70,dir+i*3,0,15,60,G_LARGE_YELLOW,0);
	TShot(GetEnemyX,GetEnemyY-70,dir+i*3,i);
	ManageLaser(obj);
	obj = CreateStraightLaserA1(GetEnemyX,GetEnemyY-70,dir-i*3,0,15,60,G_LARGE_YELLOW,0);
	TShot(GetEnemyX,GetEnemyY-70,dir-i*3,-i);
	ManageLaser(obj);
	if(count>=1){LargeBullet(GetEnemyX,GetEnemyY-70,0,dir+i*3,0.05,5,G_LARGE_YELLOW,20);}
	if(count>=1){LargeBullet(GetEnemyX,GetEnemyY-70,0,dir-i*3,0.05,5,G_LARGE_YELLOW,20);}
	wait(4); 
	}
	ascent(i in 15..25){
	PlaySound("Eff2",95,0);
	let obj = CreateStraightLaserA1(GetEnemyX,GetEnemyY-70,dir+i*5,0,15,90,G_LARGE_YELLOW,0);
	TShot(GetEnemyX,GetEnemyY-70,dir+i*5,i);
	ManageLaser(obj);
	obj = CreateStraightLaserA1(GetEnemyX,GetEnemyY-70,dir-i*5,0,15,60,G_LARGE_YELLOW,0);
	TShot(GetEnemyX,GetEnemyY-70,dir-i*5,-i);
	ManageLaser(obj);
	if(count>=1){LargeBullet(GetEnemyX,GetEnemyY-70,0,dir+i*5,0.05,5,G_LARGE_YELLOW,20);}
	if(count>=1){LargeBullet(GetEnemyX,GetEnemyY-70,0,dir-i*5,0.05,5,G_LARGE_YELLOW,20);}
	wait(3); 
	}
	wait(30);
	TMovement(20,3,5);
	wait(60);
	set(300);
	wait(60);
	ascent(n in 0..20){
	ascent(i in 0..3){
	PlaySound("Eff3",95,0);
	dir = i*120+n*13.5*s;
	CreateStraightLaserA1(GetEnemyX,GetEnemyY-70,dir,500,15,0,G_LARGE_YELLOW,60);
	let shot = ShotA1(GetEnemyX+n*cos(dir),GetEnemyY-70+n*sin(dir),0,0,ORB_YELLOW,60);
	ObjShot_SetDeleteFrame(shot,0);
	}
	wait(4); 
	}
	ascent(n in 0..20){
	ascent(i in 0..3){
	PlaySound("Eff2",95,0);
	dir = i*120+n*13.5*s;
	let obj = CreateStraightLaserA1(GetEnemyX,GetEnemyY-70,dir,0,15,60,G_LARGE_YELLOW,0);
	ManageLaser(obj);
	TShot(GetEnemyX,GetEnemyY-70,dir,i);
	if(count>=1){LargeBullet(GetEnemyX,GetEnemyY-70,0,dir,0.05,5,G_LARGE_YELLOW,20);}
	}
	wait(4); 
	}
	wait(30);
	ascent(n in 0..20){
	ascent(i in 0..3){
	PlaySound("Eff3",95,0);
	dir = i*120-n*10.5*s-4;
	CreateStraightLaserA1(GetEnemyX,GetEnemyY-70,dir,500,15,0,G_LARGE_YELLOW,70);
	let shot = ShotA1(GetEnemyX+n*cos(dir),GetEnemyY-70+n*sin(dir),0,0,ORB_YELLOW,60);
	ObjShot_SetDeleteFrame(shot,0);
	}
	wait(4);
	}
	p = 0;
	ascent(n in 0..20){
	ascent(i in 0..3){
	PlaySound("Eff2",95,0);
	dir = i*120-n*10.5*s-4;
	let obj = CreateStraightLaserA1(GetEnemyX,GetEnemyY-70,dir,0,15,60,G_LARGE_YELLOW,0);
	ManageLaser(obj);
	TShot(GetEnemyX,GetEnemyY-70,dir,i);
	if(count>=1){LargeBullet(GetEnemyX,GetEnemyY-70,0,dir,0.05,5,G_LARGE_YELLOW,20);}
	}
	wait(4);
	}
	wait(30);
	TMovement(25,5,5);
	wait(60);
	set(120);
	wait(60);
	ascent(n in 0..10){
	ascent(i in 0..9){
	PlaySound("Eff3",95,0);
	dir = i*360/9+getDotAngle(GetPlayerX,GetPlayerY,GetEnemyX,GetEnemyY-70);
	CreateStraightLaserA1(GetEnemyX,GetEnemyY-70,dir,500,15,0,G_LARGE_YELLOW,40);
	let shot = ShotA1(GetEnemyX+n*cos(dir),GetEnemyY-70+n*sin(dir),0,0,ORB_YELLOW,60);
	ObjShot_SetDeleteFrame(shot,0);
	TAimLaser(dir,i);
	}
	wait(10);
	}
	wait(30);
	TMovement(20,0,5);
	wait(60);
	set(90);
	wait(60);
	ascent(i in 0..36){
	PlaySound("Eff3",95,0);
	dir = i*10+5;
	let obj = CreateStraightLaserA1(GetEnemyX,GetEnemyY-70,dir,500,15,0,G_LARGE_YELLOW,30);
	let shot = ShotA1(GetEnemyX,GetEnemyY-70,0,0,ORB_YELLOW,60);
	ObjShot_SetDeleteFrame(shot,0);
	}
	wait(50);
	ascent(i in 0..36){
	PlaySound("Eff2",95,0);
	dir = i*10+5;
	let obj = CreateStraightLaserA1(GetEnemyX,GetEnemyY-70,dir,0,15,60,G_LARGE_YELLOW,0);
	let shot = ShotA1(GetEnemyX,GetEnemyY-70,0,0,ORB_YELLOW,60);
	ObjShot_SetDeleteFrame(shot,0);
	ManageLaser(obj);
	TShot(GetEnemyX,GetEnemyY-70,dir,i);
	if(count>=1){LargeBullet(GetEnemyX,GetEnemyY-70,0,dir,0.05,5,G_LARGE_YELLOW,20);}
	}
	ascent(i in 0..12){
	let shot = LargeBullet(GetEnemyX,GetEnemyY-70,0,i*30,0.04,5,249,30);
	ObjMove_SetAngularVelocity(shot,1);
	shot = LargeBullet(GetEnemyX,GetEnemyY-70,0,i*30,0.04,5,249,30);
	ObjMove_SetAngularVelocity(shot,-1);
	}
	wait(75);
	ObjMove_SetDestAtWeight(objBoss,stgx,150,10,7);
	wait(60);
	s = -s;
	count++;
	}
	}

task TAimLaser(dir,i){
	wait(60);
	PlaySound("Eff2",95,0);
	let obj = CreateStraightLaserA1(GetEnemyX,GetEnemyY-70,dir,0,15,60,G_LARGE_YELLOW,0);
	ManageLaser(obj);
	TShot(GetEnemyX,GetEnemyY-70,dir,i);
	if(count>=1){LargeBullet(GetEnemyX,GetEnemyY-70,0,dir,0.05,5,G_LARGE_YELLOW,20);}
	}
	
task TShot(x,y,dir,p){
	let angle = 0;
	ascent(a in 0..10){
	CreateShotA1(x,y,1+a/3,dir,AMULET_YELLOW,10);
	//CreateShotA1(x,y,0.75+a/4,dir*3+a*77,AMULET_YELLOW,10);
	}
	}

task ManageLaser(obj){
	ascent(i in 0..40){
	ObjLaser_SetLength(obj,i*15);
	yield;
	}
	}

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

task TRender
{
Aura;
TWaveCircle();
	magiccircle(objBoss,1.75,true);
	let imgMiko = GetCurrentScriptDirectory~"img/boss.png";
	let f = 0;
	let t = 0;
	ObjPrim_SetTexture(objBoss, imgMiko);
	ObjRender_SetScaleXYZ(objBoss,1.05,1.05,1);
	while(!Obj_IsDeleted(objBoss))
	{
		let angle = ObjMove_GetAngle(objBoss);
		let speed = ObjMove_GetSpeed(objBoss);
		if(speed == 0 && idle == true){
		if(f<8){ObjSprite2D_SetSourceRect(objBoss, 0, 0, 64, 98);}
		if(f>=8 && f<16){ObjSprite2D_SetSourceRect(objBoss, 64, 0, 128, 98);}
		if(f>=16 && f<24){ObjSprite2D_SetSourceRect(objBoss, 128, 0, 192, 98);}
		if(f>=24 && f<32){ObjSprite2D_SetSourceRect(objBoss, 192, 0, 256, 98);}
		if(f>=32){f=0;}
		f++;
		t = 0;
		}
		else if(cos(angle) > 0 || cos(angle) < 0 && t == 0 && idle ==true){
		if(cos(angle)<0){point = 1;}
		else{point = -1;}
		manageSprite;
		t = 1;
		}
		ObjSprite2D_SetDestCenter(objBoss);
		yield;
	}
}

//----------------------------------------------------
task TEnd{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
		let arr = GetShotIdInCircleA2(stgx,stgy,600,TARGET_ENEMY);
		Obj_Delete(objBoss);
		SetAutoDeleteObject(true);
		yield;
		SetAutoDeleteObject(false);
		ascent(i in 0..length(arr)){
		effbreak(arr[i],"PURPLE");
		Obj_Delete(arr[i]);
		}
		wait(30);
		SetAutoDeleteObject(true);
		CloseScript(GetOwnScriptID());
		return;
	}
