#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["ReimuNS1"]
#Text["."]
#System["./System.txt"]
#include"./Functions/Index.txt"

let frame=0;
let objScene=GetEnemyBossSceneObjectID;
let GCSD=GetCurrentScriptDirectory~"";

@Initialize{
	mainTask;
}

@Event{
	alternative(GetEventType)
	case(EV_REQUEST_LIFE){
		SetScriptResult(2000)
	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(30)
	}
}

@MainLoop{
	frame++;
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),24);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),26);
	yield;
	
}

task mainTask{
	objBoss=TDrawBoss;
	TEnemyHitboxStart(objBoss,150);
	ObjMove_SetPosition(objBoss,GetStgFrameWidth/2,-150);
	TEnd;
	ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2,GetStgFrameHeight/3,7.5,5);
	wait(150);
	TShoot01;
}

task TEnd{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
	TExplosionA(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),10,0.5);
	DeleteShotAll(TYPE_ALL,TYPE_ITEM);
	Obj_Delete(objBoss);
	loop(120){
		DeleteShotAll(TYPE_ALL,TYPE_IMMEDIATE);
		yield;
		}
	CloseScript(GetOwnScriptID());
	return;
}

task TShoot01{
	let bS=[1,2,3];
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){
		let t=1;
		let side=1;
		ANIM_IDLE=false;
		loop(8){
			let s=3.25;
			ascent(i in 1..6){
				if(side==1){
					let angle=0;
					while(angle<360){
						let obj=CreateShotA1(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),s,angle+GetAngleToPlayer(objBoss)+i*t-t,AMULET_GRAY,10);
						TBounce(obj);
						angle+=360/3;
					}
				}else{
					let angle=0;
					while(angle<360){
						let obj=CreateShotA1(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),s,angle+GetAngleToPlayer(objBoss)-i*t+t,AMULET_GRAY,10);
						TBounce(obj);
						angle+=360/3;
					}
				}
				s-=3.25/6.25;
			}
			t+=3;
			side=-side;
			PlaySound(GCSD~"se/tan00.wav");
			wait(8);
		}
		side=1;
		ascent(i in 0..length(bS)){
			let angle=0;
			while(angle<360){
				let obj=CreateShotA1(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),bS[i],GetAngleToPlayer(objBoss)+angle,AMULET_RED,15);
				angle+=360/30;
			}
			side=-side;
		}
		ANIM_IDLE=true;
		TMovement;
		PlaySound(GCSD~"se/tan01.wav");
		while(ObjMove_GetSpeed(objBoss)>0){ yield; }
		wait(90);
	}
}

task TBounce(obj){
	while(!Obj_IsDeleted(obj)){
		if(ObjMove_GetX(obj)<=0){
			ObjMove_SetAngle(obj,180-ObjMove_GetAngle(obj));
			ObjMove_SetX(obj,ObjMove_GetX(obj)+0.01);
			break;
		}
		if(ObjMove_GetX(obj)>=GetStgFrameWidth){
			ObjMove_SetAngle(obj,180-ObjMove_GetAngle(obj));
			ObjMove_SetX(obj,ObjMove_GetX(obj)-0.01);
			break;
		}
		if(ObjMove_GetY(obj)<=0){
			ObjMove_SetAngle(obj,360-ObjMove_GetAngle(obj));
			ObjMove_SetY(obj,ObjMove_GetY(obj)+0.01);
			break;
		}
		yield;
	}
}

sub TMovement{
	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=50;
		}else{
			posx=-50;
		}
	}
	if((ObjMove_GetX(objBoss)+posx)<=50||(ObjMove_GetX(objBoss)+posx)>=(GetStgFrameWidth()-50)){
		posx=-posx;
	}
	let posy=rand(25,-25);
	if(posy<25&&posy>-25){
		if(resulty==1){
			posy=10;
		}else{
			posy=-10;
		}
	}
	if((ObjMove_GetY(objBoss)+posy)<=32||(ObjMove_GetY(objBoss)+posy)>=GetStgFrameHeight()/3){
		posy=-posy;
	}
	ObjMove_SetDestAtWeight(objBoss,ObjMove_GetX(objBoss)+posx,ObjMove_GetY(objBoss)+posy,15,10);
}