#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Unused"]
#Text["Formation 'Crane's Wings'"]

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

#include "./Zun Expanded (Ozzy)/ZUNShot_Const.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(4556);
	}
	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 {
loop{
wait(60);
PlaySE(charge5);
BossConcentrateB1(45);
BFX_FocusA1(bossX,bossY,100,VFX_Smoke,VFX_Beams,45);
wait(60);
Lure;
wait(120);
PlaySE(charge2);
BossConcentrateB1(45);
BFX_FocusA1(bossX,bossY,100,VFX_Smoke,VFX_Beams,90);
wait(120);
Wings;
bossFire;
wait(600)
}
}

task bossFire{
	loop(5){//----
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	PlaySE(shot1);
		ascent(i in -2..3){
			ascent(a in 1..3){
			CreateShotA2(bossX,bossY,0.1,GetAngleToPlayer(bossObj)+(i*20),0.1,a,410,5);
			}
		}
		wait((118*2.5)/5);
	}
}

task Lure{
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	PlaySE(shot4);
	let LureBall = CreateShotA2(bossX,bossY,6,90,-0.1,0,404,0);
	ObjShot_SetSpellResist(LureBall,true);
	wait(60);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	PlaySE(charge5);
	BFX_FocusA1(ObjMove_GetX(LureBall),ObjMove_GetY(LureBall),100,VFX_Smoke,VFX_Beams,45);
	wait(60);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	moveLureBall(LureBall);
	shootLureBall(LureBall);
}

task moveLureBall(LureBall){wait(60);if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}ObjMove_SetDestAtSpeed(LureBall,ObjMove_GetX(LureBall),bossY+60,1);}
task shootLureBall(LureBall){
	let angleA = 90;
	let angleB = 90;
	let trig = 200;
	loop(118){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		if(Obj_IsDeleted(LureBall)){return;}
		PlaySE(shot3);
		loop(4){
			let ObjA = CreateShotA1(ObjMove_GetX(LureBall)+trig*cos(angleA),ObjMove_GetY(LureBall)+trig*sin(angleA),0.1,angleA,404,30);
			let ObjB = CreateShotA1(ObjMove_GetX(LureBall)+trig*cos(angleB),ObjMove_GetY(LureBall)+trig*sin(angleB),0.1,angleB,404,30);
			angleA+=360/4;
			angleB+=360/4;
			moveLureBall_Obj(ObjA);
			moveLureBall_Obj(ObjB);
		}
		angleA+=5;
		angleB-=5;
		trig-=0.75;
		wait(2.5);
	}
	
	wait(30);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	if(Obj_IsDeleted(LureBall)){return;}
PlaySE(charge5);
	BFX_FocusA1(ObjMove_GetX(LureBall),ObjMove_GetY(LureBall),100,VFX_Smoke,VFX_Beams,45);
	wait(60);
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	if(Obj_IsDeleted(LureBall)){return;}
	let angA = 45;
	let angB = 0;
	loop(2){
		let timeA = 90;
		let timeB = 180;
		ascent(i in 1..10){
			let newobjA = CreateShotA2(bossX,bossY,i*2,angA,-0.040*i,0,405,0);
			let newobjB = CreateShotA2(bossX,bossY,i*2,angB,-0.040*i,0,405,0);
			ObjShot_SetSpellResist(newobjA,true);
			ObjShot_SetSpellResist(newobjB,true);
			ObjShot_SetAutoDelete(newobjA,false);
			ObjShot_SetAutoDelete(newobjB,false);
			shoot_newobjA(newobjA,timeA);
			shoot_newobjB(newobjB,timeB);
			timeA+=5;
			timeB+=5;
		}
	angA+=90;	
	angB+=180;	
	}
	BFX_ExplosionA1(ObjMove_GetX(LureBall),ObjMove_GetY(LureBall),100,VFX_Smoke,5);
	PlaySE(Eff9);
	Obj_Delete(LureBall);
	
}

task shoot_newobjA(newobjA,timeA){
	wait(timeA);
	let ang = 45;
	PlaySE(Eff1);
	loop(4){
		let warnLas = CreateStraightLaserA1(ObjMove_GetX(newobjA),ObjMove_GetY(newobjA),ang,500,30,60,24,60);
		deletewarnLas(warnLas,60);
		ang+=360/4;
	}
	wait(60);
	PlaySE(laser2);
	PlaySE(Eff9);
	BFX_ExplosionA1(ObjMove_GetX(newobjA),ObjMove_GetY(newobjA),100,VFX_Smoke,5);
	loop(4){
		CreateLooseLaserA1(ObjMove_GetX(newobjA),ObjMove_GetY(newobjA),5,ang,300,10,28,0);
		ang+=360/4;
	}
	let c =90;
	loop(5){
		ascent(i in 1..4){
		CreateShotA2(ObjMove_GetX(newobjA),ObjMove_GetY(newobjA),0.1*i,c,0.025,3,71,0);
		}
		ang+=360/5;
	}
	yield;
	Obj_Delete(newobjA);
}

task shoot_newobjB(newobjB,timeB){
	wait(timeB);
	let ang = GetAngleToPlayer(newobjB);
	PlaySE(Eff1);
	loop(16){
		let warnLas = CreateStraightLaserA1(ObjMove_GetX(newobjB),ObjMove_GetY(newobjB),ang,500,30,60,24,60);
		deletewarnLas(warnLas,60);
		ang+=360/16;
	}
	wait(60);
	PlaySE(Eff9);
	PlaySE(laser2);
	BFX_ExplosionA1(ObjMove_GetX(newobjB),ObjMove_GetY(newobjB),100,VFX_Smoke,5);
	loop(16){
		CreateLooseLaserA1(ObjMove_GetX(newobjB),ObjMove_GetY(newobjB),5,ang,300,10,28,0);
		ang+=360/16;
	}
	loop(20){
		ascent(i in -1..2){
		CreateShotA2(ObjMove_GetX(newobjB),ObjMove_GetY(newobjB),0.1,ang+(i),0.025,5,71,0);
		}
		ang+=360/20;
	}
	yield;
	Obj_Delete(newobjB);
}

task deletewarnLas(obj,time){
	wait(time-1);
	Obj_Delete(obj);
}

task moveLureBall_Obj(obj){
	wait(45);
	ObjMove_SetAcceleration(obj,0.1);
	ObjMove_SetMaxSpeed(obj,5);
}

task Wings{//----
	BFX_ExplosionA1(bossX,bossY,100,VFX_Smoke,5);
	PlaySE(Eff9);
	let AngLeft = 180; 
	let AngRight = 0; 
	let A = 9; 
	let Avel = 1.25; 
	loop(7){
		ascent(i in -2..3){
		let WL = CreateShotA1(bossX,bossY,3,AngLeft+(i*7),332,5);
		let WR = CreateShotA1(bossX,bossY,3,AngRight+(i*7),332,5);
		moveWing(WL,-Avel);
		moveWing(WR,Avel);
		}
		AngLeft += A; 
		AngRight -= A; 
		wait(5);
	}
	loop(3){
	loop(10){
		ascent(i in -2..3){
		let WL = CreateShotA1(bossX,bossY,3,AngLeft+(i*7),332,5);
		let WR = CreateShotA1(bossX,bossY,3,AngRight+(i*7),332,5);
		moveWing(WL,-Avel);
		moveWing(WR,Avel);
		}
		AngLeft -= A; 
		AngRight += A; 
		wait(5);
	}
	loop(10){
		ascent(i in -2..3){
		let WL = CreateShotA1(bossX,bossY,3,AngLeft+(i*7),332,5);
		let WR = CreateShotA1(bossX,bossY,3,AngRight+(i*7),332,5);
		moveWing(WL,-Avel);
		moveWing(WR,Avel);
		}
		AngLeft += A; 
		AngRight -= A; 
		wait(5);
	}
	}
		
}

task moveWing(obj, Angvel){
	ObjMove_SetAngularVelocity(obj,Angvel);
	wait(60);
	ObjMove_SetAngularVelocity(obj,0);
}

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());
}