#東方弾幕風[Single]
#ScriptVersion[3]
#Title["Secret Treasure\"Chandelier of Ikaruga-dera\""]
#Text["Spell5"]
#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;
@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(2500);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(45);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(30000);
	}
}

//----------------------------------------------------
task mainTask{
	wingset(2);
	PlaySound("cardcall",100,0);
	ObjEnemyBossScene_StartSpell(objScene);
	Cutin("Miko","Secret Treasure\"Chandelier of Ikaruga-dera\"",15);
	wait(60);
	ObjEnemy_SetDamageRate(objBoss,50,20);
	TBullet;
	}
//----------------------------------------------------

task TBullet{
	let obj;
	ascent(m in 0..10){
	spd = 4;
	ManageSpd(G_LARGE_AQUA,m);
	ascent(n in 0..40){
	PlaySound("BulletWave",95,0);
	ascent(i in 0..7){
	obj = ShotA1(GetEnemyX,GetEnemyY,0,i*360/7+n*27,SMALL_BLUE,0);
	Manage(obj,100+i*2.5+n*18,1);
	}
	wait(2);
	}
	wait(360);
	spd = 4;
	ManageSpd(G_LARGE_ORANGE,m+1);
	ascent(n in 0..40){
	PlaySound("BulletWave",95,0);
	ascent(i in 0..7){
	obj = ShotA1(GetEnemyX,GetEnemyY,0,i*360/7+n*27*-1,SMALL_RED,0);
	Manage(obj,100+i*2.5+n*18,-1);
	}
	wait(2);
	}
	wait(300);
	}
	}

task ManageSpd(color,m){
	while(spd>0){
	spd = spd-0.02;
	yield;
	}
	set(60);
	wait(60);
	if(m>0){
	ascent(i in 0..24){
	ascent(a in 0..2){
	ShotA2(GetEnemyX,GetEnemyY-60,1+a,i*15,0,0,color,30);
	}
	}
	}
	PlaySound("BulletWave",95,0);
	spd = 0;
	wait(60);
	TMovement(35,0,5);
	}
//----------------------------------------------------

task Manage(obj,r,way){
	let c = 0;
	let a = ObjMove_GetAngle(obj);
	let alpha = 0;
	let dir = 0;
	let px = 0;
	let py = 0;
	let cp = 0;
	let color;
	let shot;
	if(way==1){color = PELLET_BLUE;}
	else{color = PELLET_RED;}
	ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
	ObjShot_SetIntersectionEnable(obj,false);
	ObjShot_SetAutoDelete(obj,false);
	while(spd!=0){
	if(GetDistance(GetEnemyX,GetEnemyY,ObjMove_GetX(obj),ObjMove_GetY(obj))>325){Obj_Delete(obj);}
	ObjRender_SetColor(obj,alpha,alpha,alpha);
	if(alpha<128){alpha+=2;}
	ObjMove_SetPosition(obj,GetEnemyX+r*cos(c+a),GetEnemyY+r*sin(c+a));
	c += spd*way;
	yield;
	}
	ascent(i in 0..6){
	dir = getAtanAngle(obj,objBoss);
	px = ObjMove_GetX(obj)+(i*7-21)*cos(dir+90)*way;
	py = ObjMove_GetY(obj)+(i*7-21)*sin(dir+90)*way;
	cp = GetDistance(GetPlayerX,GetPlayerY,px,py);
	 if((|cp|)>30 && !Obj_IsDeleted(obj)){
	 shot = ShotA2(px,py,0,dir,0.01+i/1500,2,color,40);
	 Delete(shot);
	 ObjShot_SetAutoDelete(shot,false);
	 ObjMove_AddPatternA2(shot,60,NO_CHANGE,getAtanAngle(shot,objBoss),0.015+i/1500,0,5);
	 }
	}
	Obj_Delete(obj);
	task Delete(shot){
	wait(180);
	ObjShot_SetAutoDelete(shot,true);
	}
	}

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

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