#ScriptVersion[3]
#System["script/LOCAA7 - The Forgot Warship/System/system/Default_system.txt"]


let objEnemy;
let frame = -50;
let frame2 = -50;
let frame3 =0;
let angcount =0;
let ang=0;
let objScene=GetEnemyBossSceneObjectID();
let argument = GetCommonData("StageDiffic", 36);
//let bg = LoadScript("script/LOCAA7 - The Forgot Warship/script/DPStg2BG.txt");
let cut = GetCurrentScriptDirectory ~ "img/cut1.png";
let spellStart=false;

#include "script/LOCAA7 - The Forgot Warship/System/Index.txt"
#include "./AkitsuMaruAnimationFile.txt"

@Initialize
{
	
	//StartScript(bg);
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	ObjEnemy_SetDamageRate(objEnemy, 0, 0);
	NameOnBossSingle(objEnemy,"Akitsu Maru");
	MainTask();
	
		
	
	TEnd();
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);//出現と同時に敵弾を全て削除			
}

@MainLoop
{

	frame++;
	frame2++;
	frame3++;
	angcount++;
	ang++;
	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(150);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);
	}
	case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(200000);
	}
	
}

//----------------------------------------------------------------//
task MainTask{
newAnimation(objEnemy);
	TEnemyWork();
		BackgroundBulgeA2(objEnemy);
	AuraOnBossSingle(objEnemy, 252, 252, 252);
		PlayEnemyHitSound(objEnemy, 1);
		GlitterOnBoss(objEnemy, 252, 252, 252);
		MagicCircleV2(objEnemy);
		SummonAmp();
	wait(120);
	ObjEnemy_SetDamageRate(objEnemy, 3, 3);
	StartSpell();
}
//----------------------------------------------------------------//

task StartSpell(){

ObjEnemyBossScene_StartSpell(objScene);
	StartBG();
	//CutInS1(objEnemy, "NAZRIN", "Type 3 \""~"Command Liaison Aircraft"~"\"", cut, 0, 0, 170, 480);
	ObjCutin_SetSpellcardS4("Type 3 \""~"Command Liaison Aircraft"~"\"", cut, NAZRIN, 240, 104, 104);
	ObjCutin_LaunchS3(NAZRIN, cut, "Normal");
	se_cat00;
	frame=60;
	frame2=0;
	frame3=0;
	spellStart=true;
}

//Handles the enemy's actions
task TEnemyWork()
{
	//ObjMove_SetPosition(objEnemy,GetStgFrameWidth() / 2, 130);
	let ag=GetAngleToPlayer(objEnemy);
	
	while(!Obj_IsDeleted(objEnemy))
	{
		ObjEnemy_SetIntersectionCircleToShot(objEnemy, ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 16);
		ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 12);
		
		if(spellStart==true){
		
		if(frame == 200)
		{
			Plane((cos(GetAngleToPlayer(objEnemy)+90)*60),(sin(GetAngleToPlayer(objEnemy)+90)*60));
			Plane(-(cos(GetAngleToPlayer(objEnemy)+90)*60),(-sin(GetAngleToPlayer(objEnemy)+90)*60));
			ag+=3;
			
		}
		
		if(frame2==200+60+20){
			Plane2(GetStgFrameWidth,rand(0,GetStgFrameHeight));
			Plane2(0,rand(0,GetStgFrameHeight));
			frame=0;
			frame2=0;
		}

		if(frame3==120){
			Move(objEnemy,0);
			frame3=0;
		}
		
		}

		yield;
	}
}

task Transform(delay){
ConcentrationF3(objEnemy,delay);
se_charge;
wait(delay);
se_enep02;
CallKai();

}

task RotateShot(ag){
let X=ObjMove_GetX(objEnemy);
let Y=ObjMove_GetY(objEnemy);
let density=16;
let a=ag;
let dist=0;

loop(density){
se_tan00;
let bulletObj00=CreateShotA1(X+(cos(a)*dist),Y+(sin(a)*dist),3,a,194,10);
a+=(360/density);
}

}

task Plane2(movX,movY){
let a=GetAngleToPlayer(objEnemy);
SetShotAutoDeleteClip(64*10,64*10,64*10,64*10);
se_lazer00;
let warning=CreateStraightLaserA1(movX,movY,a,999,10,20,17,60);
a=GetAngleToPlayer(warning);
ObjStLaser_SetAngle(warning,GetAngleToPlayer(warning));
wait(20);

let X=ObjMove_GetX(objEnemy);
let Y=ObjMove_GetY(objEnemy);
//let a=GetAngleToPlayer(objEnemy);


se_kira00;

let bulletObj00=CreateShotA1(movX,movY,7,a,376,10);
a=GetAngleToPlayer(bulletObj00);
ObjMove_SetAngle(bulletObj00,GetAngleToPlayer(bulletObj00));



;

RPlane2(bulletObj00,a);
yield;


}

task Plane(movX,movY){
let X=ObjMove_GetX(objEnemy);
let Y=ObjMove_GetY(objEnemy);
let a=GetAngleToPlayer(objEnemy);

se_tan00;
let bulletObj00=CreateShotA1(X+movX,Y+movY,7,a,376,10);
RPlane(bulletObj00,a);
yield;


}

task RPlane(Core,a){
let pFrame=0;

let X=ObjMove_GetX(Core);
let Y=ObjMove_GetY(Core);

let p0=CreateShotA1(X+(cos(a+180)*16),Y+(sin(a+180)*16),2,a+180,186,10);
let p1=CreateShotA1(X,Y,2,a,200,10);
let p2=CreateShotA1(X+(cos(a+180)*16),Y+(sin(a+180)*16),2,a,186,10);
let p3=CreateShotA1(X+(cos(a+180)*32),Y+(sin(a+180)*32),2,a,186,10);

let wing1=CreateShotA1(X+(cos(a-90)*8),Y+(sin(a-90)*8),2,a+90,186,10);
let wing2=CreateShotA1(X+(cos(a+90)*8),Y+(sin(a+90)*8),2,a-90,186,10);

let wing12=CreateShotA1(X+(cos(a-90)*8),Y+(sin(a-90)*8),2,a+90,186,10);
let wing22=CreateShotA1(X+(cos(a+90)*8),Y+(sin(a+90)*8),2,a-90,186,10);

let hel=CreateShotA1(X+(cos(a+180)*32),Y+(sin(a+180)*32),2,a,262,10);

while(!Obj_IsDeleted(Core)){
X=ObjMove_GetX(Core);
Y=ObjMove_GetY(Core);

ObjMove_SetPosition(p0,X+(cos(a)*16),Y+(sin(a)*16));
ObjMove_SetPosition(p1,X,Y);
ObjMove_SetPosition(p2,X+(cos(a+180)*16),Y+(sin(a+180)*16));
ObjMove_SetPosition(p3,X+(cos(a+180)*32),Y+(sin(a+180)*32));

ObjMove_SetPosition(wing1,X+(cos(a-90)*8),Y+(sin(a-90)*8));
ObjMove_SetPosition(wing2,X+(cos(a+90)*8),Y+(sin(a+90)*8));

ObjMove_SetPosition(wing12,X+(cos(a-90)*16),Y+(sin(a-90)*16));
ObjMove_SetPosition(wing22,X+(cos(a+90)*16),Y+(sin(a+90)*16));

ObjMove_SetPosition(hel,X+(cos(a)*16),Y+(sin(a)*16));

if(pFrame==6){
let smallB=CreateShotA1(X,Y,0.1,rand(0,360),300,10);
beha(smallB);
se_kira00;

pFrame=0;
}

pFrame++;
yield;
}

task beha(bullet){
let density=10;
ObjShot_SetAutoDelete(bullet,false);
wait(60);

let X=ObjMove_GetX(bullet);
let Y=ObjMove_GetY(bullet);

loop(density){
let explo=CreateShotA1(X,Y,1,rand(0,360),371,10);
moreBeha(explo);
}
ObjShot_FadeDelete(bullet)
}

}

task RPlane2(Core,a){
let pFrame=0;

let X=ObjMove_GetX(Core);
let Y=ObjMove_GetY(Core);

let p0=CreateShotA1(X+(cos(a+180)*16),Y+(sin(a+180)*16),2,a+180,186,10);
let p1=CreateShotA1(X,Y,2,a,200,10);
let p2=CreateShotA1(X+(cos(a+180)*16),Y+(sin(a+180)*16),2,a,186,10);
let p3=CreateShotA1(X+(cos(a+180)*32),Y+(sin(a+180)*32),2,a,186,10);

let wing1=CreateShotA1(X+(cos(a-90)*8),Y+(sin(a-90)*8),2,a+90,186,10);
let wing2=CreateShotA1(X+(cos(a+90)*8),Y+(sin(a+90)*8),2,a-90,186,10);

let wing12=CreateShotA1(X+(cos(a-90)*8),Y+(sin(a-90)*8),2,a+90,186,10);
let wing22=CreateShotA1(X+(cos(a+90)*8),Y+(sin(a+90)*8),2,a-90,186,10);

let hel=CreateShotA1(X+(cos(a+180)*32),Y+(sin(a+180)*32),2,a,262,10);

while(!Obj_IsDeleted(Core)){
X=ObjMove_GetX(Core);
Y=ObjMove_GetY(Core);

ObjMove_SetPosition(p0,X+(cos(a)*16),Y+(sin(a)*16));
ObjMove_SetPosition(p1,X,Y);
ObjMove_SetPosition(p2,X+(cos(a+180)*16),Y+(sin(a+180)*16));
ObjMove_SetPosition(p3,X+(cos(a+180)*32),Y+(sin(a+180)*32));

ObjMove_SetPosition(wing1,X+(cos(a-90)*8),Y+(sin(a-90)*8));
ObjMove_SetPosition(wing2,X+(cos(a+90)*8),Y+(sin(a+90)*8));

ObjMove_SetPosition(wing12,X+(cos(a-90)*16),Y+(sin(a-90)*16));
ObjMove_SetPosition(wing22,X+(cos(a+90)*16),Y+(sin(a+90)*16));

ObjMove_SetPosition(hel,X+(cos(a)*16),Y+(sin(a)*16));

if(pFrame==6){
let smallB=CreateShotA1(X,Y,0.1,rand(0,360),300,10);
beha2(smallB);
se_kira00;

pFrame=0;
}

pFrame++;
yield;
}

task beha2(bullet){
let density=4;
ObjShot_SetAutoDelete(bullet,false);
wait(60);

let X=ObjMove_GetX(bullet);
let Y=ObjMove_GetY(bullet);

loop(density){
let explo=CreateShotA1(X,Y,2,rand(0,360),448,10);
moreBeha2(explo);
}
ObjShot_FadeDelete(bullet)
}

}

task moreBeha(explo){
wait(15);
ObjShot_FadeDelete(explo)
}

task moreBeha2(explo){
wait(120);
ObjShot_FadeDelete(explo)
}


task Move(obj, delay){
wait(delay);
ObjMove_SetDestAtWeight(objEnemy,GetPlayerX+rand(-30,30),130+rand(-30,30),30,5);

}



//Finalizing the spellcard
task TEnd()
{

	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0)
	{
		yield;
	}

	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	FinalizeSpell();

loop(30){yield;}
		SetAutoDeleteObject(true);
CloseScript(GetOwnScriptID());

}

