#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Rumia Non Spell 2"]
#Text["."]
#include"./Functions/Index.txt"
#include"script/Rumia Boss/ZUNShot_Const.txt"
#include"script/Default_system/Default_Effect.Txt"

let objBoss;
let frame=0;
let spinangle=0;
let spinangle2=0;
let spsignal=1;
let GCSD=GetCurrentScriptDirectory~"";
let stgx=GetStgFrameWidth()/2;
let stgy=GetStgFrameHeight()/2;

@Initialize{
	mainTask;
}

@Event{
	alternative(GetEventType)
	case(EV_REQUEST_LIFE){
		SetScriptResult(4000)
	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(40)
	}
}

@MainLoop{
	frame++;
	spinangle++;
	if(spsignal==1){
		spinangle2++;
		}
	if(spsignal==-1){
		spinangle2--;
		}
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),25);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),27);
	yield;

}

task mainTask{
	TLoadSounds;
	objBoss=TDrawBoss;
	ObjMove_SetDestAtWeight(objBoss,stgx,GetStgFrameHeight()/4,10,5);
	TEnemyHitboxStart(objBoss,120);
	TShoot01;
	TEnd;
	yield;
}

task TEnd{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
		TExplosionA(GetEnemyX,GetEnemyY,10,0.6);
		DeleteShotAll(TYPE_ALL,TYPE_ITEM);
		Obj_Delete(objBoss);
		loop(120){
			DeleteShotAll(TYPE_ALL,TYPE_IMMEDIATE);
			yield;
			}
		CloseScript(GetOwnScriptID());
		return;
	}
	
task TMovement{
		let resultx=rand(0,1);
		resultx=round(resultx);
		let resulty=rand(0,1);
		resulty=round(resulty);
		let posx=rand(50,-50);
		if(posx<=10&&posx>=-10){
			if(resultx==1){
				posx=15;
			}else{
				posx=-15;
			}
		}
		if((GetEnemyX+posx)<=32||(GetEnemyX+posx)>=(GetStgFrameWidth()-32)){
			posx=-posx;
		}
		
		let posy=rand(20,-20);
		if(posy<=7.5&&posy>=-7.5){
			if(resulty==1){
				posy=10;
			}else{
				posy=-10;
			}
		}
		if((GetEnemyY+posy)<=32||(GetEnemyY+posy)>=GetStgFrameHeight()/3){
			posy=-posy;
		}
		ObjMove_SetDestAtWeight(objBoss,GetEnemyX+posx,GetEnemyY+posy,10,5);
}

task TShoot01{
	wait(90);
	let bullets=[1.5,2,2.5];
	let signal=1;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){
	loop(2){
		loop(5){
		let angle=-0;
		while(angle<360){
			angle+=(360/10);
			CreateShotA2(GetEnemyX,GetEnemyY,5,angle+spinangle2,-0.1,1,SMALL_RED,5);
			CreateShotA2(GetEnemyX,GetEnemyY,5,angle+-spinangle2,-0.1,1,SMALL_ORANGE,5);
		}
		PlaySound(10,85,0);
		wait(2);
	}
	spsignal=-spsignal;
		loop(5){
		let angle=-0;
		while(angle<360){
			angle+=(360/10);
			CreateShotA2(GetEnemyX,GetEnemyY,5,angle+-spinangle2,-0.1,1,SMALL_RED,5);
			CreateShotA2(GetEnemyX,GetEnemyY,5,angle+spinangle2,-0.1,1,SMALL_ORANGE,5);
		}
		wait(2);
	}
	let bullets3=[5,6,7];
	let angleplayer=angleToPlayer;
	loop(3){
		let angle2=0;
		while(angle2<360){
			angle2+=(360/30);
			ascent(i in 0..length(bullets3)){
				CreateShotA2(GetEnemyX,GetEnemyY,bullets3[i],angle2+bullets3[i]/6+angleplayer+15,-0.5,bullets3[i]/3,LARGE_AQUA,15);
			}
		}
	PlaySound(8,85,0);
	wait(5);
	}
	if(signal==1){
	}
	signal=0;
	wait(50);
	}
	TMovement;
	wait(45);
	TBullets;
	wait(15);
	spinangle2=0;
	}
}

task TBullets{
	let angleplayer=angleToPlayer;
	let angle2=-90;
	while(angle2<90){
		angle2+=7.5;
		TLaser01(GetEnemyX+50*cos(angle2+angleplayer),GetEnemyY+50*sin(angle2+angleplayer),angle2+angleplayer,0,10,60,ST_LASER_RED,60);
		PlaySound(5,90,60);
		yield;
	}
}
	
task TLaser01(x,y,dir,l,w,dt,g,d){
	let obj=CreateStraightLaserA1(x,y,dir,l,w,dt,g,d);
	let length=0;
	loop(60){
		ObjLaser_SetLength(obj,length);
		length+=650/60;
		yield;
	}
}