#TouhouDanmakufu[Single]
#ScriptVersion[3]

#include "./functions.txt"

timer = 60;

@Initialize
{
	Obj_SetValue(GetEnemyBossSceneObjectID,"INIT",false);
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	bspell = true;

	TEnemyWork;
	ObjEnemy_Render;
	TBackground;
	TLife(330,20,32,1,0);
	TEnd(false);
}

@MainLoop
{
	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
		{
		SetScriptResult(2500/spellLife);
		}
	case(EV_REQUEST_TIMER)
		{
		SetScriptResult(10^10);
		}
	case(EV_REQUEST_SPELL_SCORE)
		{
		SetScriptResult(30000);
		}
}
task TEnemyWork
{
	TXY;
	TSpellName("\"Will You Ease the Illness that is Boredom?\"");
	loop(75){yield;}
	ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth/2,GetStgFrameHeight/2-65,20,5);
	loop(90){yield;}
	let spreadS = [8,3,1,4+Dif*2];
	let time = [20,20,112-Dif*7];
	let timeStop = false;
	let dir = 1;
	loop
		{
		let c = -1;
		loop(6)
			{
			PlaySound("se_Shot1",75);
			TShot(GetStgFrameWidth*(0.5+dir*0.375),rand(18,50));
			loop(time[1])
				{
				c+=1;
				if(c == 6*time[1]+time[0]-65)
					{
					PlaySound("se_Charge",100);
					}
				yield;
				}
			dir*=-1;
			}
		timeStop = true;
		PlaySound("se_LaserDelay",100);
		loop(time[0]){yield;}
		TStop;
		IsTimeStop = true;
		loop(30+time[0]+time[2]){yield;}
		TStart;
		timeStop = false;
		IsTimeStop = false;
		dir*=-1;
		}
	task TShot(x,y)
		{
		let shot = CreateBulletA1(x,y,0,90,BL_SMALL,0,0,SHOT_ORANGE);
		Obj_SetValue(shot,"SKIP_TIME_STOP",true);
		ObjShot_SetIntersection(shot,false);
		ObjShot_SetSpellResist(shot,true);
		ObjShot_SetDeathResist(shot,true);
		ascent(t in 0..time[0])
			{
			ObjShot_SetScale(shot,(1)*(2-t/(time[0]-1)));
			ObjRender_SetAlpha(shot,255*t/time[0]);
			yield;
			}
		ObjShot_SetIntersection(shot,true);
		ObjMove_SetSpeed(shot,96/(time[0]+time[1]));
		while(!Obj_IsDeleted(shot) && timeStop == false){yield;}
		if(Obj_IsDeleted(shot)){return;}
		ObjShot_SetGraphic(shot,BL_SMALL_GRAY);
		ObjMove_SetSpeed(shot,0);
		TSpam;
		descent(t in 0..time[0])
			{
			ObjShot_SetScale(shot,(1)*(2-t/(time[0]-1)));
			ObjRender_SetAlpha(shot,255*(t/time[0]));
			yield;
			}
		Obj_Delete(shot);
		task TSpam
			{
			let dir = -1;
			if(ObjMove_GetX(shot) < GetStgFrameWidth*0.5)
				{
				dir = 1;
				}
			let x = GetStgFrameWidth*0.5-ObjMove_GetX(shot);
			let obj = CreateBulletA1(ObjMove_GetX(shot),ObjMove_GetY(shot),0,0,BUBBLE,0,0,SHOT_RED);
			ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
			Obj_SetValue(obj,"SKIP_TIME_STOP",true);
			ObjShot_SetIntersection(obj,false);
			ObjShot_SetSpellResist(obj,true);
			ObjShot_SetDeathResist(obj,true);
			ascent(t in 0..time[0])
				{
				ObjShot_SetScale(obj,(1)*t/(time[0]-1));
				ObjRender_SetAlpha(obj,255*t/time[0]);
				yield;
				}
			ObjShot_SetIntersection(obj,true);
			loop(15){yield;}
			if(Obj_IsDeleted(obj)){return;}
			PlaySound("se_Shot1",80);
			ascent(i0 in 0..spreadS[0])
				{
				i0 = i0-spreadS[0]*0.5+0.5;
				ascent(i1 in 0..spreadS[1])
					{
					let graph = ARROWHEAD;
					let shot = CreateBulletA1(ObjMove_GetX(obj),ObjMove_GetY(obj),0,90+dir*90+i0*185/(spreadS[0]-1),graph,8,1.25,SHOT_GRAY);
					Obj_SetValue(shot,"TIME_SPEED",0.5+i1*6/spreadS[1]);
					Obj_SetValue(shot,"TIME_GRAPH",graph);
					ObjShot_SetSpellResist(shot,true);
					}
				}
			ascent(i3 in 0..spreadS[3])
				{
				let speed = 0.25+i3*3.5/spreadS[3];
				let accel = speed/90;
				let dirA = rand(-1,1)*0.5;
				ascent(i2 in 0..spreadS[2])
					{
					i2 = i2-spreadS[2]*0.5+0.5;	
					let graph = PELLET;
					let shot = CreateBulletA1(ObjMove_GetX(obj),ObjMove_GetY(obj),0,90-dir*(110-i3*20/spreadS[3])+i2*90/max(1,spreadS[2]-1),graph,8,1.25,SHOT_GRAY);
					Obj_SetValue(shot,"TIME_ACCEL",accel);
					Obj_SetValue(shot,"TIME_MSPEED",speed);
					Obj_SetValue(shot,"TIME_GRAPH",graph);
					ObjShot_SetSpellResist(shot,true);
					}
				}
			ascent(t in 0..time[2])
				{
				ObjMove_SetX(obj,GetStgFrameWidth*0.5-x*cos(180*t/time[2]));
				yield;
				}
			loop(15){yield;}
			if(Obj_IsDeleted(obj)){return;}
			TShot(ObjMove_GetX(obj),ObjMove_GetY(obj));
			descent(t in 0..time[0])
				{
				ObjShot_SetScale(obj,(1)*t/(time[0]-1));
				ObjRender_SetAlpha(obj,255*t/time[0]);
				yield;
				}
			Obj_Delete(obj);
			}
		}
	task TStop
		{
		let array = GetShotIdInCircleA2(GetStgFrameWidth*0.5,GetStgFrameHeight*0.5,GetStgFrameHeight*1.5,TARGET_ENEMY);
		ascent(i in 0..length(array))
			{
			let shot = array[i];
			if(Obj_GetValueD(shot,"SKIP_TIME_STOP",false) == false)
				{
				Obj_SetValue(shot,"TIME_SPEED",ObjMove_GetSpeed(shot));
				ObjMove_SetSpeed(shot,0);
				ObjMove_SetAcceleration(shot,0);
				ObjShot_SetGraphic(shot,Obj_GetValueD(shot,"TIME_GRAPH",PELLET)[SHOT_GRAY]);
				ObjShot_SetSpellResist(shot,true);
				}
			}
		}
	task TStart
		{
		let array = GetShotIdInCircleA2(GetStgFrameWidth*0.5,GetStgFrameHeight*0.5,GetStgFrameHeight*1.5,TARGET_ENEMY);
		ascent(i in 0..length(array))
			{
			let shot = array[i];
			if(Obj_GetValueD(shot,"SKIP_TIME_STOP",false) == false)
				{
				ObjMove_SetSpeed(shot,Obj_GetValueD(shot,"TIME_SPEED",0));
				ObjMove_SetAcceleration(shot,Obj_GetValueD(shot,"TIME_ACCEL",0));
				ObjMove_SetMaxSpeed(shot,Obj_GetValueD(shot,"TIME_MSPEED",0));
				ObjShot_SetGraphic(shot,Obj_GetValueD(shot,"TIME_GRAPH",PELLET)[SHOT_BLUE]-1);
				ObjShot_SetSpellResist(shot,false);
				}
			}

		}
}