#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Rumia Non Spell 8"]
#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(3000)
	}
	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;
	ObjMove_SetDestAtWeight(objBoss,stgx,GetStgFrameHeight()/4,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 TMovement{
	wait(120);
	loop{
		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.15,1.25,1.35];
	let n=1;
	let d=4;
	let t=0;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){
		loop(90){
		let angle=rand(0,360);
		let obj=CreateLooseLaserA1(GetEnemyX+100*cos(n/d*t)*sin(t),GetEnemyY+100*sin(n/d*t)*sin(t),5,angle,100,10,G_LARGE_BLUE,25);
		TSpeed(obj);
		t+=d*4;
	}
	t=0;
	PlaySound(6,90,25);
	wait(180);
	}
	task TSpeed(obj){
		ObjMove_SetAcceleration(obj,-0.05);
		ObjMove_SetMaxSpeed(obj,0);
		wait(205);
		ObjMove_SetAcceleration(obj,0.05);
		ObjMove_SetMaxSpeed(obj,5);
		while(!Obj_IsDeleted(obj)){
			if(ObjMove_GetY(obj)>GetEnemyY){
				CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),6,ObjMove_GetAngle(obj)+180,ICE_GREEN,5);
				}
			PlaySound(8,85,0);
			wait(2);
		}
	}
}

task TShoot02{
	wait(90);	
	let bullets=[1];
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){
		let angle=0;
		while(angle<360){
			angle+=(360/2);
			ascent(i in 0..length(bullets)){
				CreateShotA1(GetEnemyX,GetEnemyY,bullets[i],angle+plusangle*7.34,PELLET_PURPLE,5);
			}
		}
		PlaySound(9,80,0);
		wait(3);
	}
}