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

let frame=0;
let sAngle=0;
let hitbox_signal=1;
let part=0;
let objScene=GetEnemyBossSceneObjectID;
let GCSD=GetCurrentScriptDirectory~"";

@Initialize{
	mainTask;
}

@Event{
	alternative(GetEventType)
	case(EV_REQUEST_LIFE){
		SetScriptResult(1750)
	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(70)
	}
	case(EV_REQUEST_IS_DURABLE_SPELL){
		SetScriptResult(true)
	}
}

@MainLoop{
	frame++;
	sAngle++;
	if(hitbox_signal==1){
		ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),24);
	}else{
		ObjRender_SetAlpha(objBoss,128);
	}
	yield;
	
}

task mainTask{
	objBoss=TDrawBoss;
	ObjEnemy_SetDamageRate(objBoss,0,0);
	ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2,GetStgFrameHeight/2,7.5,5);
	while(IsPlayerSpellActive==true||ObjMove_GetSpeed(objBoss)>0){ yield; }
	TEnemyHitboxStart(objBoss,360);
	wait(30);
	ObjEnemyBossScene_StartSpell(objScene);
	Cutin(objBoss,"Beautiful Shintoism \"Exorcism By Boundaries\"");
	TEnd;
	wait(120);
	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 size=50;
	let _wait=180;
	let bullets=1;
	let grow=25/6;
	TCharge(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss));
	wait(60);
	TExplode(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss));
	PlaySound(GCSD~"se/don20.wav");
	hitbox_signal=2;
	let bg=[AMULET_RED,AMULET_ORANGE,AMULET_YELLOW,AMULET_GREEN,AMULET_AQUA,AMULET_BLUE,AMULET_PURPLE];
	let g=[ST_LASER_RED,ST_LASER_ORANGE,ST_LASER_YELLOW,ST_LASER_GREEN,ST_LASER_AQUA,ST_LASER_BLUE,ST_LASER_PURPLE];
	wait(60);
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0&&part<21){
		ascent(i in 0..length(g)){
			if(part==7){
				bullets=2;
			}
			if(part==14){
				bullets=3;
			}
			TCharge(ObjMove_GetX(objPlayer),ObjMove_GetY(objPlayer));
			TBarrier(ObjMove_GetX(objPlayer),ObjMove_GetY(objPlayer),g[i],bg[i],size,bullets,15);
			PlaySoundDelay(GCSD~"se/lazer00.wav",75);
			PlaySoundDelay(GCSD~"se/tan01.wav",210);
			wait(_wait);
			_wait-=8;
			part++;
			size+=grow;
		}
	}
	wait(300);
	DeleteShotInCircle(TYPE_ALL,TYPE_ITEM,ObjMove_GetX(objPlayer),ObjMove_GetY(objPlayer),200);
	wait(120);
	_wait=120;
	size=75;
	let aAdd=360/7;
	let t=1;
	TCharge(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss));
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){
		ascent(i in 0..length(g)){
			TCharge(ObjMove_GetX(objPlayer),ObjMove_GetY(objPlayer));
			TBarrier(ObjMove_GetX(objPlayer),ObjMove_GetY(objPlayer),g[i],bg[i],size/1.25,1,15);
			TBarrier(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),g[i],bg[i],size/1.55,2,15);
			PlaySoundDelay(GCSD~"se/lazer00.wav",75);
			PlaySoundDelay(GCSD~"se/tan01.wav",210);
			wait(_wait);
			_wait-=3;
			size+=5.5;
		}
	}
}

task TBarrier(xx,yy,g,bg,l,j,delay){
	let gaplength=0;
	let delsignal=0;
	let n=0;
	let x;
	let y;
	let nX=xx;
	let nY=yy;
	let obj=[];
	let objn=[];
	wait(60);
	ascent(i in 0..4){
		let o=ObjShot_Create(OBJ_STRAIGHT_LASER);
		x=GetGapX(nX,gaplength,n);
		y=GetGapY(nY,gaplength,n);
		ObjMove_SetPosition(o,x,y);
		ObjStLaser_SetAngle(o,360/4*i+90);
		ObjLaser_SetLength(o,0);
		ObjLaser_SetRenderWidth(o,10);
		ObjLaser_SetIntersectionWidth(o,10);
		ObjShot_SetGraphic(o,g);
		ObjShot_SetDelay(o,10);
		ObjShot_Regist(o);
		obj=obj~[o];
		TBullet(o);
		objn=objn~[n];
		n+=90;
	}
	wait(delay);
	let p=0;
	let f=120;
	let a=l/f;
	let r=rand(-1,1);
	loop(f){
		ascent(i in 0..length(obj)){
			x=GetGapX(nX,gaplength,objn[i]+p);
			y=GetGapY(nY,gaplength,objn[i]+p);
			ObjMove_SetPosition(obj[i],x,y);
			ObjStLaser_SetAngle(obj[i],objn[i]+p+135);
			ObjLaser_SetLength(obj[i],gaplength+(gaplength/2));
		}
		p+=r;
		gaplength+=a;
		yield;
	}
	ascent(i in 0..length(obj)){
		ObjShot_FadeDelete(obj[i]);
	}
	delsignal=1;
	while(!Obj_IsDeleted(obj[0])){
		ascent(i in 0..length(obj)){
			x=GetGapX(nX,gaplength,objn[i]+p);
			y=GetGapY(nY,gaplength,objn[i]+p);
			ObjMove_SetPosition(obj[i],x,y);
			ObjStLaser_SetAngle(obj[i],objn[i]+p+135);
			ObjLaser_SetLength(obj[i],gaplength+(gaplength/2));
		}
		p+=(r/5);
		gaplength+=(a/5);
		yield;
	}
	task TBullet(obj){
		let o=CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),0,0,G_LARGE_GRAY,delay);
		while(!Obj_IsDeleted(obj)&&delsignal==0){
			ObjMove_SetPosition(o,ObjMove_GetX(obj),ObjMove_GetY(obj));
			yield;
		}
		ObjShot_SetIntersectionEnable(o,false);
		if(!Obj_IsDeleted(o)){
			ShootShape(ObjMove_GetX(o),ObjMove_GetY(o),1,GetAngleToPlayer(o),7,j,bg,15);
		}
		wait(15);
		ObjShot_FadeDelete(o);
	}
}

function GetGapX(xA,gapLength,gapAngle){
	return xA+gapLength*cos(gapAngle);
}

function GetGapY(yA,gapLength,gapAngle){
	return yA+gapLength*sin(gapAngle);
}