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

@Initialize{
	mainTask;
}

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

@MainLoop{
	frame++;
	plusangle++;
	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;
	TEnemyHitboxStart(objBoss,120);
	TMovement;
	TShoot01;
	TShoot02;
	TShoot03;
	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{
	ObjMove_SetDestAtWeight(objBoss,stgx,GetStgFrameHeight()/4,15,10);
	wait(90);
	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);
	}
}

task TShoot01{
	wait(90);
	let bullets=[1,1.05];
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){
	ascent(i in 0..length(bullets)){
		let obj=CreateShotA1(GetEnemyX+(50+rand(-10,10))*cos(plusangle*7.34),GetEnemyY+(50+rand(-10,10))*sin(plusangle*7.34),bullets[i],plusangle*7.34,PELLET_PURPLE,5);
		}
		PlaySound(9,80,0);
		wait(2);
	}
}

task TShoot02{
	wait(90);	
	let bullets=[5,5.5];
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>=0){
		let angle=0;
		while(angle<360){
			angle+=(360/5);
			ascent(i in 0..length(bullets)){
				let obj=CreateShotA2(GetEnemyX+50*cos(angle+plusangle*16),GetEnemyY+50*sin(angle+plusangle*16),bullets[i],angle+plusangle*16,-bullets[i]/90,bullets[i]/2,PELLET_BLUE,5);
			}
			wait(2);
		}
	}
}

task TShoot03{
	wait(90);
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){
	let bullets=1;
	let playerangle=angleToPlayer;
	loop(1){
		let angle=-45;
		while(angle<45){
			angle+=5;
			let obj=CreateShotA1(GetEnemyX,GetEnemyY,bullets,playerangle+angle,BL_SMALL_GREEN,5);
		wait(1);
		bullets+=0.1;
		}
		}
		wait(90);
	bullets=0.5;
	let angle2=-45;
		while(angle2<45){
			angle2+=5;
			let obj=CreateShotA1(GetEnemyX,GetEnemyY,bullets,playerangle+-angle2,BL_SMALL_GREEN,5);
		wait(1);
		bullets+=0.2;
		}
		wait(90);
		if(ObjEnemy_GetInfo(objBoss,INFO_LIFE)<=0){
			break;
		}
		TBullets;
		loop(10){
			TLaser02(GetEnemyX,GetEnemyY,angleToPlayer,500,10,60,ST_LASER_RED,60);
			PlaySound(5,90,60);
			wait(5);
			}
		wait(90);
		}
	}
	
task TBullets{
	let angleplayer=angleToPlayer;
	let angle2=90;
	while(angle2>-90){
		angle2-=15;
		TLaser01(GetEnemyX+50*cos(angle2+angleplayer),GetEnemyY+50*sin(angle2+angleplayer),angle2+angleplayer,0,10,60,ST_LASER_BLUE,90);
		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+=500/60;
		yield;
	}
}
	
task TLaser02(x,y,dir,l,w,dt,g,d){
	let obj=CreateStraightLaserA1(x,y,dir,l,w,dt,g,d);
}