#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/cut2.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);
CallKai();
	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.5, 3.5);
	StartSpell();
}
//----------------------------------------------------------------//

task StartSpell(){

ObjEnemyBossScene_StartSpell(objScene);
	StartBG();
	//CutInS1(objEnemy, "NAZRIN", "Ka Type \""~"Observation Autogyro"~"\"", cut, 0, 0, 299, 480);
	ObjCutin_SetSpellcardS4("Ka Type \""~"Observation Autogyro"~"\"", cut, NAZRIN, 240, 104, 104);
	ObjCutin_LaunchS3(NAZRIN, cut, "Lunatic");
	se_cat00;
	frame=60*3;
	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 == 60*4)
		{
		FireGyros(4);
			//ag+=3;
			
		}
		
		if(frame2==160+60){
			
			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 FireGyros(repeat){
loop(repeat){
Autogyro(rand(-15,15),rand(-60,60));
}
}

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 RotateShot2(x,y){
let X=ObjMove_GetX(objEnemy)+x;
let Y=ObjMove_GetY(objEnemy)+y;
let density=60;
let a=GetAngleToPlayer(objEnemy);;
let dist=0;

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

}

task Autogyro(movX,movY){
let X=ObjMove_GetX(objEnemy);
let Y=ObjMove_GetY(objEnemy);
let a=-90+rand(-75,75);

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



}

task RGyro(Core,a){
let pFrame=0;
let speedarg=rand(-1,1);
let shotlaser=false;
let speed=5;
let agyro=rand(0,360);
let density=12;

if(speedarg<=0){
speed= -5;
}
let bounce=2;
let X=ObjMove_GetX(Core);
let Y=ObjMove_GetY(Core);
let ac=0;
let p0=CreateShotA1(X+(cos(a)*16),Y+(sin(a)*16),0,a,186,10);
let p1=CreateShotA1(X+(cos(a+90)*16),Y+(sin(a+90)*16),0,a+90,186,10);
let p2=CreateShotA1(X+(cos(a+180)*16),Y+(sin(a+180)*16),0,a+180,186,10);
let p3=CreateShotA1(X+(cos(a-90)*16),Y+(sin(a-90)*16),0,a-90,186,10);
let hel=CreateShotA1(X,Y,0,a,262,10);

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

ObjMove_SetPosition(p0,X+(cos(a+ac)*16),Y+(sin(a+ac)*16));
ObjMove_SetAngle(p0,a+ac);
ObjMove_SetPosition(p1,X+(cos(a+ac+90)*16),Y+(sin(a+ac+90)*16));
ObjMove_SetAngle(p1,a+ac+90);
ObjMove_SetPosition(p2,X+(cos(a+ac+180)*16),Y+(sin(a+ac+180)*16));
ObjMove_SetAngle(p2,a+ac+180);
ObjMove_SetPosition(p3,X+(cos(a+ac-90)*16),Y+(sin(a+ac-90)*16));
ObjMove_SetAngle(p3,a+ac-90);
ac+=speed;


ObjMove_SetPosition(hel,X,Y);

if(pFrame==10 && ObjMove_GetSpeed(Core)>0){

let follow=CreateShotA1(X,Y,3,90,348,10);
ObjMove_SetAngle(follow,GetAngleToPlayer(follow));
loop(density){
let smallB=CreateShotA1(X,Y,2,agyro,51,10);
agyro+=360/density;
beha(smallB);
se_kira00;
}
pFrame=0;
}

if(bounce>0){
if(ObjMove_GetY(Core)<=0){

	if(ObjMove_GetAngle(Core)<270){
		ObjMove_SetAngle(Core,ObjMove_GetAngle(Core)-90);
	}
	
	if(ObjMove_GetAngle(Core)==270){
		ObjMove_SetAngle(Core,ObjMove_GetAngle(Core)+180);
	}
	
	if(ObjMove_GetAngle(Core)>270){
		ObjMove_SetAngle(Core,ObjMove_GetAngle(Core)+90);
	}
	bounce--;
}

if(ObjMove_GetY(Core)>=GetStgFrameHeight){

	if(ObjMove_GetAngle(Core)<90){
		ObjMove_SetAngle(Core,ObjMove_GetAngle(Core)-90);
	}
	
	if(ObjMove_GetAngle(Core)==90){
		ObjMove_SetAngle(Core,ObjMove_GetAngle(Core)+180);
	}
	
	if(ObjMove_GetAngle(Core)>90){
		ObjMove_SetAngle(Core,ObjMove_GetAngle(Core)+90);
	}
	bounce--;
}

if(ObjMove_GetX(Core)<=0){

	if(ObjMove_GetAngle(Core)<180){
		ObjMove_SetAngle(Core,ObjMove_GetAngle(Core)-90);
	}
	
	if(ObjMove_GetAngle(Core)==180){
		ObjMove_SetAngle(Core,ObjMove_GetAngle(Core)+180);
	}
	
	if(ObjMove_GetAngle(Core)>180){
		ObjMove_SetAngle(Core,ObjMove_GetAngle(Core)+90);
	}
	bounce--;
}

if(ObjMove_GetX(Core)>=GetStgFrameWidth){

	if(ObjMove_GetAngle(Core)<0){
		ObjMove_SetAngle(Core,ObjMove_GetAngle(Core)-90);
	}
	
	if(ObjMove_GetAngle(Core)==0){
		ObjMove_SetAngle(Core,ObjMove_GetAngle(Core)+180);
	}
	
	if(ObjMove_GetAngle(Core)>0){
		ObjMove_SetAngle(Core,ObjMove_GetAngle(Core)+90);
	}
	bounce--;
}

}
pFrame++;

if(bounce==0 && shotlaser==false){
frame=0;
SLaser(Core);
shotlaser=true;
}
yield;
}

ObjShot_FadeDelete(p0);
ObjShot_FadeDelete(p1);
ObjShot_FadeDelete(p2);
ObjShot_FadeDelete(p3);
ObjShot_FadeDelete(hel);

task SLaser(Core){
ObjMove_SetAcceleration(Core,-0.05);
ObjMove_SetMaxSpeed(Core,0);
while(ObjMove_GetSpeed(Core)>0){
yield;
}
let density=8;
let a=rand(0,360);
let X=ObjMove_GetX(Core);
let Y=ObjMove_GetY(Core);

loop(density){
se_lazer00;
let lazah=CreateStraightLaserA1(X,Y,a,800,30,50,25,150);
//MoveLaser(lazah,a);
a+=360/density;
}
wait(200);
ObjShot_FadeDelete(Core);

task MoveLaser(laser,a){
let sparg=rand(-1,1);
let speed=2;
let count=200;
let sacc=0.08;
if(sparg<0){
speed=-2;
}

while(count>0){
ObjStLaser_SetAngle(laser,a);
speed-=sacc;
a+=speed;

if(speed<=0){
speed=0;
}

yield;
}

}

}

task beha(bullet){
//wait(60);
//ObjShot_FadeDelete(bullet)
}

}

task Plane2(movX,movY){
let X=ObjMove_GetX(objEnemy);
let Y=ObjMove_GetY(objEnemy);
let a=GetAngleToPlayer(objEnemy);
SetShotAutoDeleteClip(64*10,64*10,64*10,64*10);
let amod=0;
let vara=rand(-3,3);
let aaim=0;

if(movX<=0){
amod=0;
}else{
amod=180;
}

if(movY<=GetStgFrameHeight/2){
aaim=90;
}else{
aaim=-90;
}

se_kira00;

let bulletObj00=CreateShotA1(movX,movY,7,a,376,10);
ObjMove_SetAngle(bulletObj00,amod+vara);

a=amod+vara;

let warning=CreateStraightLaserA1(movX,movY,a,999,10,0,17,60);

RPlane2(bulletObj00,a,aaim);
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,aaim){
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,1,aaim,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());

}

