#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Non 2 N"]
#Text["Skylight Overseer"]
#Background["./Background.txt"] 

let bossObj;
let bossX = 0;
let bossY = 0;

#include "./Expanded CTC (Darkness1)/Expanded_ShotConst.txt"
#include"./FX/Bloom VFX darkwalker247/BloomFX.txt"
#include"./lib.txt"
#include"./FX/Effects.cs"

@Initialize {
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(bossObj);
	ObjMove_SetDestAtSpeed(bossObj,GetStgFrameWidth/2,GetStgFrameHeight/4,5);
	SFXload;
	mainTask;
} 

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

@MainLoop {
	bossX = ObjMove_GetX(bossObj);
	bossY = ObjMove_GetY(bossObj);

	ObjEnemy_SetIntersectionCircleToShot(bossObj,bossX,bossY,32);
	ObjEnemy_SetIntersectionCircleToPlayer(bossObj,bossX,bossY,20);
	
	yield;
} 

@Finalize {
} 

task mainTask {
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);	
	ObjEnemy_SetDamageRate(bossObj,1,1);
	//Insert Cut-in task
	BossRender;
	movement;
	end;
} 


task movement {
let F1_bul_num = 60;
let F1_bul_wave = 4;
let F1_bul_wave2 = 1;
let F1_angadd = 2;
let F1_time = 240;
let F1_min_spd = 0.75;	
let F1_max_spd = 3;	

let F2_bul_num = 5;	
let F2_bul_num_time = 180;	
let F2_num = 12;
let F2_min_spd = 2.5;
let F2_max_spd = 3;
let F2_trailnum = 5;

wait(60);

if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
PlaySE(charge4);
BFX_FocusA1(bossX,bossY,100,VFX_Smoke,VFX_Beams,45);
wait(60);

Fire1(F1_bul_num, F1_bul_wave, F1_bul_wave2, F1_angadd, F1_time, F1_min_spd, F1_max_spd,false);

wait(F1_time+120);

if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
PlaySE(charge4);
BFX_FocusA1(bossX,bossY,100,VFX_Smoke,VFX_Beams,45);
wait(60);

ObjEnemy_SetDamageRate(bossObj,25,25);

loop{

Fire1(F1_bul_num, F1_bul_wave, F1_bul_wave2, F1_angadd, F1_time, F1_min_spd, F1_max_spd,true);
Fire2(F2_num, F2_bul_num, F2_bul_num_time, F2_min_spd, F2_max_spd, F2_trailnum);

wait(F1_time+120);

if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
PlaySE(charge4);
BFX_FocusA1(bossX,bossY,100,VFX_Smoke,VFX_Beams,45);
wait(60);

Fire1(F1_bul_num, F1_bul_wave, F1_bul_wave2, F1_angadd, F1_time, F1_min_spd, F1_max_spd,false);
Fire2(F2_num, F2_bul_num, F2_bul_num_time, F2_min_spd, F2_max_spd, F2_trailnum);

wait(F1_time+120);

if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
PlaySE(charge4);
BFX_FocusA1(bossX,bossY,100,VFX_Smoke,VFX_Beams,45);
wait(60);

}
}



task Fire1(bul_num, bul_wave, bul_wave2, angadd, time, min_spd, max_spd, rev){

let ang = rand(0,360);

let Bul_angadd = 180/bul_num;
if(rev == true){Bul_angadd *= -1;}

loop(bul_num){
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	PlaySE(shot1);
	let spd = rand(min_spd, max_spd);
	
	
	loop(bul_wave){
		loop(bul_wave2){
		let Fire1Obj = CreateShotA2(bossX, bossY,spd*0.1,ang+rand(-angadd, angadd),spd*0.1,spd,123,10);
		ObjRender_SetBlendType(Fire1Obj, BLEND_ADD_ARGB);
		}
		ang+=360/bul_wave;
	}
	
	ang+= Bul_angadd;
	wait(time/bul_num);
}


}

task Fire2(num, bul_num, bul_num_time, min_spd, max_spd, trailnum){
	let ang = rand(0,360);
	loop(bul_num){	
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	PlaySE(shot4);
	loop(num){
		let spd = min_spd;
		loop(trailnum){
		CreateShotA2(bossX, bossY, 0, ang, spd*0.01, spd, 243, 30);
		spd += (max_spd/min_spd)/trailnum;
		}
		CreateShotA2(bossX, bossY, 0, ang, spd* 0.01, spd, 227, 30);
		
		ang+= (360/num);
	}
	ang+= (360/num/2);
	wait(bul_num_time/bul_num);
	}
}


task end {
	while(ObjEnemy_GetInfo(bossObj, INFO_LIFE) > 0) {
		yield;
	}
	PlaySE(SpellOff);
	SetAutoDeleteObject(true);
	loop(5){
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);	
	yield;
	}
	Obj_Delete(bossObj);
	wait(30);	
	CloseScript(GetOwnScriptID());
}