#東方弾幕風[Single]
#ScriptVersion[3]
#Title["Hermit Sign\"Guse Soul\""]
#Text["Spell1"]
#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;
@Initialize
{
LoadTexture(GCSD~"shot/ZUNShot.png");
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	ObjMove_SetDestAtWeight(objBoss,stgx,180,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(2250);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(40);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(30000);
	}
}

//----------------------------------------------------
task mainTask{
	ObjEnemy_SetDamageRate(objBoss,50,20);
	PlaySound("cardcall",100,0);
	ObjEnemyBossScene_StartSpell(objScene);
	Cutin("Miko","Hermit Sign\"Guse Soul\"",15);
	wait(60);
	//Test;
	TBall;
	}
//----------------------------------------------------

task Test{
	let n = 0;
	ascent(i in 0..60){
	ShotA1(GetEnemyX+90*cos(n),GetEnemyY+90*sin(n),2,n,315+n%8,35);
	n+= 13;
	wait(3);
	}
	}

task TBall{
	while(!Obj_IsDeleted(objBoss)){
	set(60);
	wait(60);
	PlaySound("Eff1",100,0);
	ascent(i in 0..8){
	let ball = ShotA1(GetEnemyX,GetEnemyY-70,0,i*45,315+i,30);
	Manage(ball,i);
	}
	wait(150);
	TMovement(40,10,5);
	wait(150);
	set(30);
	wait(90);
	TMovement(40,10,5);
	wait(90);
	s2 = -s2;
	}
	}

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

task Manage(obj,num){
	ObjShot_SetSpellResist(obj,true);
	let angle = ObjMove_GetAngle(obj);
	let c = 0;
	let r = 0;
	let s = 1;
	let color = [ARROWHEAD_GRAY,ARROWHEAD_RED,ARROWHEAD_AQUA,ARROWHEAD_GREEN,ARROWHEAD_PURPLE,ARROWHEAD_BLUE,ARROWHEAD_YELLOW,ARROWHEAD_GRAY];
	let color2 = [G_LARGE_GRAY,G_LARGE_RED,G_LARGE_AQUA,G_LARGE_GREEN,G_LARGE_PURPLE,G_LARGE_BLUE,G_LARGE_YELLOW,G_LARGE_GRAY];
	ObjShot_SetAutoDelete(obj,false);
	wait(30);
	loop(90){
	ObjMove_SetPosition(obj,GetEnemyX+r*cos(c+angle),(GetEnemyY-70)+r*sin(c+angle));
	c+=4*s2;
	r+=0.8;
	yield;
	}
	loop(3){
	PlaySound("BulletWave",100,0);
	ascent(i in 0..15){
	ShotA2(ObjMove_GetX(obj),ObjMove_GetY(obj),0,i*24+num*2.5*s,0.01,1.25,color[num],12);
	}
	angle = getDotAngle(ObjMove_GetX(obj),ObjMove_GetY(obj),ObjMove_GetX(objBoss),ObjMove_GetY(objBoss)-70)+45*s*s2;
	ObjMove_AddPatternA2(obj,0,3,angle,-4/60,0,0);
	wait(40);
	s = -s;
	}
	ObjMove_AddPatternA2(obj,0,3,angle+180,-4/60,0,0);
	PlaySound("BulletWave",100,0);
	wait(120);
	PlaySound("BulletWave",100,0);
	ascent(a in 0..3){
	ascent(i in 0..12){
	ShotA2(ObjMove_GetX(obj),ObjMove_GetY(obj),0.8+a/3,GetAngleToPlayer(obj)+i*30,0,5,color2[num],20);
	}
	}
	Obj_Delete(obj);
	}

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

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;
	}
