#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Rumia Non Spell 4"]
#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 spinpos=0;
let GCSD=GetCurrentScriptDirectory~"";
let stgx=GetStgFrameWidth()/2;
let stgy=GetStgFrameHeight()/2;

@Initialize{
	mainTask;
}

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

@MainLoop{
	frame++;
	spinpos++;
	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()/3,10,5);
	TEnemyHitboxStart(objBoss,120);
	TMovement;
	TShoot01;
	TShoot02;
	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 TShoot01{
	wait(90);
	let spinpos=0;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){
		let angleplayer=angleToPlayer;
		loop(2){
		let angle2=0;
		while(angle2<360){
			angle2+=(360/30);
			let obj=CreateShotA2(GetEnemyX+50*cos(angle2+angleplayer),GetEnemyY+50*sin(angle2+angleplayer),0,angle2+angleplayer+45,0.1,2.75,PELLET_GREEN,25);
			let obj2=CreateShotA2(GetEnemyX+50*cos(angle2+angleplayer),GetEnemyY+50*sin(angle2+angleplayer),0,angle2+angleplayer-45,0.1,2.75,PELLET_AQUA,25);
			}
		PlaySound(9,90,0);
		wait(15);
		let angle3=0;
		while(angle3<360){
			angle3+=(360/45);
			CreateShotA2(GetEnemyX,GetEnemyY,0,angle3+angleplayer+12,0.1,2.25,DOT_GREEN,25);
			}
		PlaySound(9,90,0);
		wait(15);
		}
		wait(90);
	}
}

task TShoot02{
	wait(90);
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){
		let angleplayer=angleToPlayer;
		let angle=0;
		let X=GetEnemyX;
		let Y=GetEnemyY;
		while(angle<360){
			angle+=(360/45);
			CreateStraightLaserA1(X+50*cos(angle+angleplayer),Y+50*sin(angle+angleToPlayer),angleplayer+angle,550,10,45,ST_LASER_PURPLE,45);
			PlaySound(5,80,45);
			wait(1);
		}
		wait(45);
	}
}
	
task TMovement{
	wait(150);
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){
		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);
		wait(90);
	}
}