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

@Initialize{
	mainTask;
}

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

@MainLoop{
	frame++;
	sinangle++;
	sinangle2++;
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),25);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),26);
	yield;

}

task mainTask{
	TLoadSounds;
	objBoss=TDrawBoss;
	ObjMove_SetDestAtWeight(objBoss,stgx,GetStgFrameHeight()/2,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 TShoot01{
	wait(90);
	let spinpos=0;
	let bullets=[1.5,2.5,3.5];
	let bullets2=[1.5,2,2.5];
	let ad=2;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){
	loop(20){
		ascent(i in 0..length(bullets2)){
			let angle=0;
			while(angle<360){
				angle+=(360/5);
				CreateShotA1(GetEnemyX,GetEnemyY,bullets2[i],angle+spinpos*7.38321,KUNAI_PURPLE,15);
			}
		spinpos+=ad;
	}
	wait(8);
	PlaySound(9,90,0);
	}
	signal=0;
	spinpos=0;
	ad=-ad;
	wait(15);
	loop(3){
	ascent(i in 0..length(bullets)){
			let angles=0;
			while(angles<360){
				angles+=(360/20);
				CreateShotA1(GetEnemyX,GetEnemyY,bullets[i],angles+angleToPlayer,PELLET_GREEN,10);
				}
			yield;
			PlaySound(8,90,0);
			}
		}
		loop(5){
			TBullets;
			PlaySound(5,90,60);
			wait(10);
		}
		wait(90);
		signal=1;
	}
}

task TBullets{
	TLaser01(GetEnemyX,GetEnemyY,angleToPlayer,0,10,60,ST_LASER_BLUE,60);
}
	
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;
	}
}