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

@Initialize{
	mainTask;
}

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

@MainLoop{
	frame++;
	if(gsignal==1){
		spinangle++;
		}
	if(gsignal==-1){
		spinangle--;
		}
	sinangle+=3;
	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,stgy*2/4,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 TMovement{
		let result=rand(-1,1);
		if((GetEnemyX-50)<=50){
			result=-0.5;
		}
		if((GetEnemyX+50)>=GetStgFrameWidth-50){
			result=0.5;
		}
		if(result>=-1&&result<0){
			ObjMove_SetDestAtWeight(objBoss,GetEnemyX+50,GetStgFrameHeight()/4,10,5);
		}
		if(result>0&&result<=1){
			ObjMove_SetDestAtWeight(objBoss,GetEnemyX-50,GetStgFrameHeight()/4,10,5);
		}
		if(result==0){
			ObjMove_SetDestAtWeight(objBoss,stgx,GetStgFrameHeight()/4,10,5);
		}
		yield;
}

task TMovement02{
		let resultx=rand(0,1);
		resultx=round(resultx);
		let resulty=rand(0,1);
		resulty=round(resulty);
		let posx=rand(100,-100);
		if(posx<=50&&posx>=-50){
			if(resultx==1){
				posx=100;
			}else{
				posx=-100;
			}
		}
		if((GetEnemyX+posx)<=100||(GetEnemyX+posx)>=(GetStgFrameWidth()-100)){
			posx=-posx;
		}
		
		let posy=rand(75,-75);
		if(posy<=37.5&&posy>=-37.5){
			if(resulty==1){
				posy=100;
			}else{
				posy=-100;
			}
		}
		if((GetEnemyY+posy)<=100||(GetEnemyY+posy)>=GetStgFrameHeight()-100){
			posy=-posy;
		}
		ObjMove_SetDestAtWeight(objBoss,GetEnemyX+posx,GetEnemyY+posy,25,5);
}

task TShoot01{
	wait(90);
	let graph;
	let speed;
	let speed2;
	let gplus;
	let splus;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){
	loop(2){
		graph=186;
		speed=1;
		speed2=-1;
		gplus=1;
		splus=0.25;
		let playerangle=angleToPlayer;
		loop(7){
			let angle=0;
			while(angle<360){
				angle+=(360/20);
				let obj=CreateShotA1(GetEnemyX,GetEnemyY,speed,angle+spinangle*6+angleToPlayer,graph,5);
				TSpeed(obj,-speed/60,speed/1.25,90,speed/60,speed*1.5);
				}
			wait(2);
			graph+=gplus;
			speed+=splus;
			speed2-=splus;
			}
		PlaySound(9,90,0);
		gsignal=-gsignal;
		TMovement;
		wait(75);
		}
		if(ObjEnemy_GetInfo(objBoss,INFO_LIFE)<=0){
			break;
		}
		loop(2){
		graph=192;
		speed=2.75;
		speed2=-2.75;
		gplus=-1;
		splus=-0.25;
		let playerangle=angleToPlayer;
		loop(7){
			let angle=0;
			while(angle<360){
				angle+=(360/20);
				let obj=CreateShotA1(GetEnemyX,GetEnemyY,speed,angle+spinangle*6+angleToPlayer,graph,5);
				TSpeed(obj,-speed/60,speed/1.25,90,speed/60,speed*1.5);
				}
			wait(2);
			graph+=gplus;
			speed+=splus;
			speed2-=splus;
			}
		PlaySound(9,90,0);
		gsignal=-gsignal;
		TMovement;
		wait(75);
		}
		if(ObjEnemy_GetInfo(objBoss,INFO_LIFE)<=0){
			break;
		}
		wait(30);
		TMovement02;
		let bullets=[1.5,1.9,2.3,2.7,3.1,3.5,3.9];
		let gap=5;
		let angleplayer=angleToPlayer;
		let p=0;
		loop(6){
			let angle=-gap;
			while(angle<=gap){
				angle+=7.5;
				ascent(i in 0..length(bullets)){
					CreateShotA2(GetEnemyX,GetEnemyY,bullets[i]+p,angle+angleToPlayer-6.25,0,0,SMALL_BLUE,30);
					}
			}
			PlaySound(8,90,0);
			wait(10);
			gap+=3.75;
			p-=0.125;
		}
		wait(60);
		TBullets;
		if(ObjEnemy_GetInfo(objBoss,INFO_LIFE)<=0){
			break;
		}
		wait(45);
		TMovement;
		wait(45);
		let cangle=90;
		let angle3=0;
		while(angle3<360){
			angle3+=360/30;
			let obj=CreateShotA2(GetEnemyX,GetEnemyY,5,angle3+angleToPlayer-(360/30),-0.15,0,SMALL_BLUE,60);
			TAngle(obj,2,cangle);
			cangle=-cangle;
			}
		let angle4=-15;
		let bullets3=[1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3.0,3.1,3.2,3.3,3.4,3.5,3.6,3.7,3.8,3.9,4.0,4.1,4.2,4.3,4.4,4.5,4.6,4.7,4.8,4.9,5.0];
		while(angle4<=15){
			angle4+=30/5;
			ascent(i in 0..length(bullets3)){
				CreateShotA2(GetEnemyX,GetEnemyY,bullets3[i],angle4+angleToPlayer-(30/5),0,0,PELLET_GREEN,60);
				}
			PlaySound(8,90,60);
			}
		TMovement;
		wait(105);
	}
}

task TBullets{
	let obj;
	let obj2;
	let addangle=-2.5;
	let angleplayer=angleToPlayer;
	let angle3=90;
	while(angle3>-90){
		angle3-=10;
		obj=CreateStraightLaserA1(GetEnemyX-50*cos(angle3+angleplayer-addangle),GetEnemyY-50*sin(angle3+angleplayer-addangle),angle3+angleplayer-addangle,0,10,70,ST_LASER_RED,75);
		PlaySound(5,90,75);
		TIncrease(obj);
		yield;
	}
	let angle2=-90;
	addangle=2.5;
	while(angle2<90){
		angle2+=10;
		obj2=CreateStraightLaserA1(GetEnemyX+50*cos(angle2+angleplayer-addangle),GetEnemyY+50*sin(angle2+angleplayer-addangle),angle2+angleplayer-addangle,0,10,85,ST_LASER_PURPLE,60);
		TIncrease(obj2);
		yield;
	}
	
	task TIncrease(obj){
		let length=0;
		loop(60){
		ObjLaser_SetLength(obj,length);
		length+=475/60;
		yield;
		}
	}
}

task TSpeed(obj,sd,mxb,w,su,mx){
	ObjMove_SetAcceleration(obj,sd);
	ObjMove_SetMaxSpeed(obj,mxb);
	loop(w){ yield; }
	ObjMove_SetAcceleration(obj,su);
	ObjMove_SetMaxSpeed(obj,mx);
	}
	
task TAngle(shot,s,a){
	while(!Obj_IsDeleted(shot)){
		if(ObjMove_GetSpeed(shot)==0){
		ObjMove_SetAngle(shot,ObjMove_GetAngle(shot)+a);
		ObjMove_SetSpeed(shot,5);
		ObjMove_SetAcceleration(shot,-0.15);
		break;
		}
	yield;
	}
	while(!Obj_IsDeleted(shot)){
		if(ObjMove_GetSpeed(shot)==0){
		ObjMove_SetAngle(shot,ObjMove_GetAngle(shot)-a);
		ObjMove_SetSpeed(shot,s);
		ObjMove_SetAcceleration(shot,0);
		break;
		}
	yield;
	}
}