#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Unused2"]
#Text["Vessel Sign 'Border Patrol'"]

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(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 {
wait(60);
PlaySE(charge5);
BossConcentrateB1(45);
BFX_FocusA1(bossX,bossY,100,VFX_Smoke,VFX_Beams,45);
wait(60);
startwave1;//1 -----
if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
wait(240);
PlaySE(charge2);
BossConcentrateB1(60);
BFX_FocusA1(bossX,bossY,100,VFX_Smoke,VFX_Beams,60);
wait(65);
wave2;
ObjEnemy_SetDamageRate(bossObj,50,50);
wait(180);
}

task startwave1{ //1 -- --- -----
let X = GetStgFrameWidth;
let N = 10;
PlaySE(charge5);
	loop(N){
		BFX_FocusA1(X,-20,100,VFX_Smoke,VFX_Beams,45);
		X-=GetStgFrameWidth/N;
	}
	wait(60);
	loop(N){
		BFX_ExplosionA1(X,-20,100,VFX_Smoke,5);
		X+=GetStgFrameWidth/N;
	}
	
	CreateTurtleShip(30);
	CreateTurtleShip(GetStgFrameWidth-30);
	
	wait(360);
	
loop{	
	wait(240);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	PlaySE(charge5);
	let newX = GetPlayerX;
	ascent(i in -2..3){
		BFX_FocusA1(newX+i*3,-20,100,VFX_Smoke,VFX_Beams,45);
		X-=GetStgFrameWidth/N;
	}
	wait(60);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	ascent(i in -2..3){
		BFX_ExplosionA1(newX+i*3,-20,100,VFX_Smoke,5);
		X+=GetStgFrameWidth/N;
	}
	CreateTurtleShip(newX);
}
	
}

task wave2{
loop{
	loop(3){
fireA1;
wait(60);
	}
	task MoveObj(obj,ang){
	wait(60);
	ObjMove_SetAngle(obj,ang);
	ObjMove_SetAcceleration(obj,0);
	ObjMove_SetMaxSpeed(obj,3);
	ObjMove_SetSpeed(obj,2);
}
wait(10);
BossMove;
wait(50);
}
}

task wave3{
	
	let delay = 60;
	let i = 14;
	let i2 = -i;
	let angleT = rand(-30,30);
	loop{
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		PlaySE(charge4);
		angleT = rand(-10,10);
	loop(7){
	loop(2){
	let obj = CreateStraightLaserA1(GetCenterX+ 40*cos(angleT),-40+10*sin(angleT),angleT,600,30,30,74,delay);
	ObjShot_SetAutoDelete(obj , false);
	ObjStuff(obj,delay);
	angleT+=(360/2);
	wait(30/7);
	}
	angleT+=360/i;
	}
	wait(240);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	PlaySE(charge4);
	angleT = rand(-10,10);
	loop(7){
	loop(2){
	let obj = CreateStraightLaserA1(GetCenterX+ 40*cos(angleT),-40+10*sin(angleT),angleT,600,30,30,74,delay);
	ObjShot_SetAutoDelete(obj , false);
	ObjStuff(obj,delay);
	angleT+=(360/2);
	wait(30/7);
	}
	angleT-=360/i;
	}
	wait(240);
	}
}

task ObjStuff(Obj,delay){
	wait(delay-5);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	PlaySE(laser5);
	let obj2 = CreateLooseLaserA1(ObjMove_GetX(Obj),ObjMove_GetY(Obj),30,ObjStLaser_GetAngle(Obj),1000,30,29,0);
	Obj2Stuff(obj2);
	wait(3);
	Obj_Delete(Obj);
}

task Obj2Stuff(Obj2){
	loop{
		if(Obj_IsDeleted(Obj2)){return;}
		let ang = ObjMove_GetAngle(Obj2);
		loop(8){
			ascent(i in 1..3){
			let obj2stf = CreateShotA2(ObjMove_GetX(Obj2),ObjMove_GetY(Obj2),i*0.75,ang,-0.1,0,281,30);
			moveshot(obj2stf,65,1.5);
			}
			ang+=360/8;
		}
		wait(3);
	}
}

task fireA1{
	PlaySE(shot1);
	ascent(i in 1..40){
	let MfBObjA = CreateShotA2(bossX,bossY,i*2,0,-0.030*i,0,9,0);	
	let MfBObjB = CreateShotA2(bossX,bossY,i*2,180,-0.030*i,0,10,0);	
	ObjShot_SetSpellResist(MfBObjA,true);
	ObjShot_SetAutoDelete(MfBObjA,false);
	ObjShot_SetSpellResist(MfBObjB,true);
	ObjShot_SetAutoDelete(MfBObjB,false);
	MoveObj(MfBObjA,90+65);
	MoveObj(MfBObjB,90-65);

	}
	}
	
	task MoveObj(obj,ang){
	wait(60);
	ObjMove_SetAngle(obj,ang);
	ObjMove_SetAcceleration(obj,0);
	ObjMove_SetMaxSpeed(obj,3);
	ObjMove_SetSpeed(obj,2);
}

task BossMove{
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		ObjMove_SetDestAtSpeed(bossObj,GetPlayerX+rand(-25,25),rand(50,75),2.75);
}

/* -- --- ----- Turtle Ship ----- --- --*/
task CreateTurtleShip(X){// TurtMain,Cannon,MainCan
//Nice boat
//The turtle ship was actually revived by Yi, at least to say that it's the BEST DAMN THING I HAVE EVER SEEN IN THE OLDER AGES.
PlaySE(Eff9);

	let angleT = 90;
	let Y = -150;
	let spd = 6;
	
	//main body
	let TurtMain = CreateShotA2(X,Y,spd,90,-0.1,0,404,0);//----
	MoveBoat(TurtMain);
	ObjShot_SetAutoDelete(TurtMain,false);
	ObjShot_SetSpellResist(TurtMain,true);
	
	loop(20){//Boat rim
		let TurtBody = CreateShotA2(X+ 30 * cos(angleT),Y + 120 * sin(angleT),spd,90,-0.1,0,80,0);//----
		MoveBoat(TurtBody);
		ObjShot_SetAutoDelete(TurtBody,false);
		ObjShot_SetSpellResist(TurtBody,true);
		
		ObjRender_SetBlendType(TurtBody, BLEND_ADD_ARGB);
		angleT+=360/20;
	}
	
	//boat side cannons
	let AngCan = 90;
	loop(2){
	let N = 30;
	loop(2){
		
		let cannon = CreateShotA2(X,Y + N * sin(AngCan),spd,90,-0.1,0,74,0);//----
		MoveBoat(cannon);
		ObjShot_SetAutoDelete(cannon,false);
		ObjShot_SetSpellResist(cannon,true);
		
		let CanAng = 0;
		loop(2){
			//LASERS
		let cannon2 = CreateStraightLaserA1(ObjMove_GetX(cannon),ObjMove_GetY(cannon),CanAng,60,20,9999,41,0);
		let WarnLas = CreateStraightLaserA1(ObjMove_GetX(cannon),ObjMove_GetY(cannon),CanAng,990,19,0,285,99999);
		ObjShot_SetAutoDelete(WarnLas,false);
		ObjShot_SetAutoDelete(cannon2,false);
		ObjShot_SetSpellResist(WarnLas,true);
		ObjShot_SetSpellResist(cannon2,true);
		ShootSideCannon(WarnLas);
		
		moveCan(cannon2,cannon);
		moveCan(WarnLas,cannon);
		CanAng+=180;
		}
		N+=30;
	}
	AngCan+=180;
	}
	
	//Main Canon(Dragon head?)
	let MainCan = CreateShotA2(X,Y + 90 * sin(AngCan),spd,90,-0.1,0,300,0);//----
	MoveBoat(MainCan);
	ObjShot_SetAutoDelete(MainCan,false);
	ObjShot_SetSpellResist(MainCan,true);
	
	ascent(i in -1..2){
		
		let LasCan = CreateStraightLaserA1(ObjMove_GetX(MainCan),ObjMove_GetY(MainCan),90+(i*5),60,20,9999,41,0);
		ObjShot_SetAutoDelete(LasCan,false);
		ObjShot_SetSpellResist(LasCan,true);
		
		moveCan(LasCan, MainCan);
		FireFlames(LasCan);
	}
}

task FireFlames(LasCan){//Flamethrower
	wait(60);
	PlaySE(Eff2);
	ascent(i in -1..2){
		let WarnLas = CreateStraightLaserA1(ObjMove_GetX(LasCan),ObjMove_GetY(LasCan),90,990,19,0,285,60);
		moveWarn(WarnLas,i);
	}
	wait(55);
	PlaySE(Eff9);
	BFX_ExplosionA1(ObjMove_GetX(LasCan),ObjMove_GetY(LasCan)+70,100,VFX_Smoke,2.5);
	loop{
		if(Obj_IsDeleted(LasCan)){return;}
	CreateShotA1(ObjMove_GetX(LasCan),ObjMove_GetY(LasCan)+70,5,rand(85,95),285,0);
	yield;
	}
}

task moveWarn(WarnLas,i){//Just as it says
	loop(10){
		ObjStLaser_SetAngle(WarnLas, ObjStLaser_GetAngle(WarnLas)+i/2);
		wait(2);
	}
	wait(35);
	Obj_Delete(WarnLas);
}

task moveCan(cannon2,cannon){//For moving the lasers
	while(!Obj_IsDeleted(cannon)){
	ObjMove_SetPosition(cannon2,ObjMove_GetX(cannon),ObjMove_GetY(cannon));
	yield;
	}
	Obj_Delete(cannon2);
}

task MoveBoat(Obj){//cuz' the can't stay there forever #WalangForever
	wait(120);
	ObjMove_SetAcceleration(Obj,0.1);
	ObjMove_SetMaxSpeed(Obj,2);
	while(ObjMove_GetY(Obj)<500){yield;}
	Obj_Delete(Obj);
}

task ShootSideCannon(WarnLas){
	wait(120);
	loop{
		if (Obj_IsDeleted(WarnLas)){return;}
		if((ObjStLaser_GetAngle(WarnLas) < GetAngleToPlayer(WarnLas)+1)&&(ObjStLaser_GetAngle(WarnLas) > GetAngleToPlayer(WarnLas)-1)){
		PlaySE(shot1);
		let sideshot = CreateShotA2(ObjMove_GetX(WarnLas)+ 50* cos(ObjStLaser_GetAngle(WarnLas)),ObjMove_GetY(WarnLas),3,ObjStLaser_GetAngle(WarnLas),-0.1,0,186,2.5);
		moveshot(sideshot,15,3);
		Obj_Delete(WarnLas);
		}
		else{wait(0.02);}
	}
	}

/* -- --- ----- End of Turtle Ship ----- --- --*/


task moveshot(obj,time,maxspd){
	wait(time);
	ObjMove_SetAcceleration(obj,0.1);
	ObjMove_SetMaxSpeed(obj,maxspd);
}

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