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

@Initialize{
	mainTask;
}

@Event{
	alternative(GetEventType)
	case(EV_REQUEST_LIFE){
		SetScriptResult(3500)
	}
	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_SetPosition(objBoss,stgx,-150);
	ObjMove_SetDestAtWeight(objBoss,stgx,GetStgFrameHeight()/4,25,10);
	TEnemyHitboxStart(objBoss,120);
	wait(30);
	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);
	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(120);
	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;
		}
		loop(10){
			TLaser01(GetEnemyX,GetEnemyY,angleToPlayer,500,10,60,ST_LASER_RED,60);
			PlaySound(5,90,60);
			wait(5);
			}
		wait(90);
		}
	}

task TShoot02{
	wait(30);
	charge=TCharge01(GetEnemyX,GetEnemyY,0.3,3,3);
	SetColor(charge,"VIOLET","BRIGHT");
	PlaySound(0,90,0);
	wait(60);
	let bullets=[1,2];
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){
		let angle=0;
		while(angle<360){
			angle+=(360/3);
			ascent(i in 0..length(bullets)){
				let obj=CreateShotA1(GetEnemyX,GetEnemyY,bullets[i],angle+plusangle*2.37,PELLET_PURPLE,5);
				PlaySound(8,75,0);
			}
		}
		wait(5);
	}
}

task TLaser01(x,y,dir,l,w,dt,g,d){
	let obj=CreateStraightLaserA1(x,y,dir,l,w,dt,g,d);
}