#System["./system/Default_System.txt"]
#Background["./background.txt"]
#include"./Shot/VigorShot_Const.txt"
#include"./function.txt"

let BossObj;
let BossObjX = 0;
let BossObjY = 0;

let alpha = 0;
let hitbox = false;

let ImgBoss;

let scfloat=1;
let floating=false;
let floatz=0;

let auraeffect=true;

let objScene = GetEnemyBossSceneObjectID();

@Initialize 
{
	SetAutoDeleteObject(true);
	BossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(BossObj);
	Obj_SetRenderPriority(BossObj,0.31);
	ObjEnemy_SetDamageRate(BossObj,0,0);
	ObjRender_SetPosition(BossObj,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
	mainTask;
} 

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(3000);
	}
}

@MainLoop 
{
	ObjEnemy_AddLife(BossObj,-3000/(64*60));
	BossObjX = ObjMove_GetX(BossObj);
	BossObjY = ObjMove_GetY(BossObj);
	if(hitbox==true)
	{
		ObjEnemy_SetIntersectionCircleToShot(BossObj,BossObjX,BossObjY,64);
		ObjEnemy_SetIntersectionCircleToPlayer(BossObj,BossObjX,BossObjY,48);
	}
	ObjRender_SetAlpha(BossObj,alpha);
	yield;
} 

@Finalize 
{ 
} 

task mainTask
{
	loop(60){yield;}
	SetCommonData("bossspell","both");
	SetCommonData("spellcolor","grey");
	loop(60){yield;}
	SEPlay(dir ~ "se/spell_0.wav");
	ObjEnemyBossScene_StartSpell(objScene);
	SpellDeclare(5,"both");
	loop(120){yield;}
	ObjEnemyBossScene_SetSpellTimer(objScene,60*60);
	
	mainshooter;
	TEnd;
}

task TEnd
{
	while(ObjEnemy_GetInfo(BossObj, INFO_LIFE) > 0){yield;}
	scoring(GetGraze,GetPlayerLife,GetPlayerSpell,GetPlayerPower);
	otherdrop(BossObjX,BossObjY,100,"p");
	otherdrop(BossObjX,BossObjY,100,"l");
	Obj_Delete(BossObj);
	CloseScript(GetOwnScriptID());
}

task mainshooter
{
	let a;
	let w;
	let xo=GetStgFrameWidth/2;
	let yo=GetStgFrameHeight/2;
	let dif=GetCommonData("diff",1);
	let lp=5+dif*5;
	loop(1){
	w=180;
	loop(2)
	{
		lasers(xo,yo-240,1,0,90,w/2,w-60,BLEND_SUBTRACT,5+dif*5,w,false);
		loop(w-60){yield;}
		lasers(xo+240,yo,0,1,180,w/2,w-60,BLEND_SUBTRACT,5+dif*5,w,false);
		loop(w-60){yield;}
		lasers(xo,yo+240,-1,0,-90,w/2,w-60,BLEND_SUBTRACT,5+dif*5,w,false);
		loop(w-60){yield;}
		lasers(xo-240,yo,0,-1,0,w/2,w-60,BLEND_SUBTRACT,5+dif*5,w,false);
		loop(w-60){yield;}
		w-=60;
	}
	loop(120){yield;}
	w=180;
	let am=1;
	if(dif==1){am=1/8;}
	if(dif==2){am=2/8;}
	if(dif==3){am=3/8;}
	loop(4)
	{
		lasers(xo-240+30*dif,yo-240,am,0,90,w,w-60,BLEND_SUBTRACT,dif*5,60,true);
		lasers(GetPlayerX,yo-240,0,0,90,w/2,w-30,BLEND_SUBTRACT,1,1,false);
		if(dif>=1)
		{
			let lp=dif;
			let c=1;
			loop(lp)
			{
				lasers(GetPlayerX+16*c,yo-240,0,0,90,w/2,w-30+10*c,BLEND_SUBTRACT,1,1,false);
				lasers(GetPlayerX-16*c,yo-240,0,0,90,w/2,w-30+10*c,BLEND_SUBTRACT,1,1,false);
				c++;
			}
		}
		loop(w-30){yield;}
		lasers(xo+240,yo-240+30*dif,0,am,180,w,w-60,BLEND_SUBTRACT,dif*5,60,true);
		lasers(yo+240,GetPlayerY,0,0,180,w/2,w-30,BLEND_SUBTRACT,1,1,false);
		if(dif>=1)
		{
			let lp=dif;
			let c=1;
			loop(lp)
			{
				lasers(yo+240,GetPlayerY+16*c,0,0,180,w/2,w-30+10*c,BLEND_SUBTRACT,1,1,false);
				lasers(yo+240,GetPlayerY-16*c,0,0,180,w/2,w-30+10*c,BLEND_SUBTRACT,1,1,false);
				c++;
			}
		}
		loop(w-30){yield;}
		lasers(xo+240-30*dif,yo+240,-am,0,-90,w,w-60,BLEND_SUBTRACT,dif*5,60,true);
		lasers(GetPlayerX,yo+240,0,0,-90,w/2,w-30,BLEND_SUBTRACT,1,1,false);
		if(dif>=1)
		{
			let lp=dif;
			let c=1;
			loop(lp)
			{
				lasers(GetPlayerX+16*c,yo+240,0,0,-90,w/2,w-30+10*c,BLEND_SUBTRACT,1,1,false);
				lasers(GetPlayerX-16*c,yo+240,0,0,-90,w/2,w-30+10*c,BLEND_SUBTRACT,1,1,false);
				c++;
			}
		}
		loop(w-30){yield;}
		lasers(xo-240,yo+240-30*dif,0,-am,0,w,w-60,BLEND_SUBTRACT,dif*5,60,true);
		lasers(yo-240,GetPlayerY,0,0,0,w/2,w-30,BLEND_SUBTRACT,1,1,false);
		if(dif>=1)
		{
			let lp=dif;
			let c=1;
			loop(lp)
			{
				lasers(yo-240,GetPlayerY+16*c,0,0,0,w/2,w-30+10*c,BLEND_SUBTRACT,1,1,false);
				lasers(yo-240,GetPlayerY-16*c,0,0,0,w/2,w-30+10*c,BLEND_SUBTRACT,1,1,false);
				c++;
			}
		}
		loop(w-30){yield;}
		w-=30;
	}
	}
	loop(120){yield;}
	spinlaser(dif);
	loop(60){yield;}
	a=rand(0,360);
	loop(36)
	{
		loop(lp)
		{
			laser(xo+360*sin(a),yo+360*cos(a),-a-90,365,24,30,132,90,BLEND_SUBTRACT,false);
			a+=360/lp;
		}
		a+=(360/lp)/8;
		loop(15){yield;}
	}
}

task spinlaser(dif)
{
	let a=rand(0,360);
	let xo=GetStgFrameWidth/2;
	let yo=GetStgFrameHeight/2;
	let lp=16*60;
	let lpp=5+dif*5;
	let c=0;
	let w=5;
	loop(lp/w)
	{
		let aa=0;
		loop(lpp)
		{
			laser(xo+360*sin(a+aa),yo+360*cos(a+aa),-a-aa-90,390*c,32,30,132,30,BLEND_SUBTRACT,true);
			aa+=3;
		}
		c+=1/(lp/w);
		loop(w)
		{
			a+=3;
			yield;
		}
	}
}

task lasers(xo,yo,mx,my,a,dt,d,blend,lp,w,mute)
{
	let x=rand(240,300);
	let y=rand(240,300);
	let xx=xo-x*mx;
	let yy=yo-y*my;
	loop(lp)
	{
		laser(xx,yy,a,480,32,dt,132,d,blend,mute);
		xx+=(x*2)/(lp-1)*mx;
		yy+=(y*2)/(lp-1)*my;
		loop(w/lp){yield;}
	}
}

task shot(x,y,rx,ry,s,a,aa,st,w,t,blend)
{
	let ao=atan2(y+rx*cos(a)-y,x+ry*sin(a)-x)+aa;
	let obj = CreateShotA1(x+rx*sin(a),y+ry*cos(a),0,ao,st,0);
	if(ObjEnemy_GetInfo(BossObj, INFO_LIFE)<=0){ObjShot_FadeDelete(obj);}
	ObjRender_SetBlendType(obj,blend);
	ObjShot_SetIntersectionEnable(obj,false);
	ObjShot_SetAutoDelete(obj,false);
	let al=0;
	let xyz=0;
	loop(w)
	{
		ObjRender_SetAlpha(obj,al);
		ObjRender_SetScaleXYZ(obj,xyz,xyz,0);
		al+=256/w;
		xyz+=1/w;
		yield;
	}
	if(!Obj_IsDeleted(obj)){SEPlay(dir ~ "se/e_shot_00.wav");}
	ObjRender_SetAlpha(obj,256);
	ObjRender_SetScaleXYZ(obj,1,1,1);
	ObjShot_SetIntersectionEnable(obj,true);
	ObjShot_SetAutoDelete(obj,true);
	let xx=0;
	let yy=0;
	while(!Obj_IsDeleted(obj))
	{
		xx=ObjMove_GetX(obj);
		yy=ObjMove_GetY(obj);
		ObjMove_SetSpeed(obj,ObjMove_GetSpeed(obj)+s/t);
		yield;
	}
	itemdrop(xx,yy,100);
}

task laser(x,y,a,l,w,dt,st,d,blend,mute)
{
	let obj=CreateStraightLaserA1(x,y,a,0,w,dt,st,d);
	ObjRender_SetBlendType(obj,blend);
	ObjShot_SetAutoDelete(obj,false);
	let c=0;
	if(!Obj_IsDeleted(obj) && mute==false){SEPlay(dir ~ "se/warning.wav");}
	loop(d)
	{
		c+=1/d;
		ObjLaser_SetLength(obj,l*c);
		yield;
	}
	if(!Obj_IsDeleted(obj) && mute==false){SEPlay(dir ~ "se/laser_2.wav");}
	if(!Obj_IsDeleted(obj) && mute==true){SEPlay(dir ~ "se/e_shot_00.wav");}
	loop(dt){yield;}
}