#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 bg = LoadScript("script/LOCAA7 - The Forgot Warship/script/DPStg2BG.txt");
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);
	wait(120);
	ObjEnemy_SetDamageRate(objEnemy, 4, 4);
	StartSpell();
}
//----------------------------------------------------------------//

task StartSpell(){

ObjEnemyBossScene_StartSpell(objScene);
	StartBG();
	ObjCutin_SetSpellcardS4("25mm Twin \""~"Autocanon Mount"~"\"", cut, NAZRIN, 240, 104, 104);
	ObjCutin_LaunchS3(NAZRIN, cut, "Lunatic");
	se_cat00;
	spellStart=true;
	frame=0;
	frame2=0;
	frame3=0;
}

//Handles the enemy's actions
task TEnemyWork()
{
	//ObjMove_SetPosition(objEnemy,GetCommonData("Boss X",GetStgFrameWidth() / 2), GetCommonData("Boss X",130));
	
	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 == 6)
		{
			RotateShot();
			RotateShot();
			//Move(objEnemy,80);
			frame=0;
		}
		
		if(frame3==80){
		se_charge;
		ConcentrationF4(objEnemy,40);
		}

		if(frame2 == 100)
		{
			RotateShot2((cos(GetAngleToPlayer(objEnemy)+90)*30),(sin(GetAngleToPlayer(objEnemy)+90)*30));
			RotateShot2(-(cos(GetAngleToPlayer(objEnemy)+90)*30),(-sin(GetAngleToPlayer(objEnemy)+90)*30));
			Move(objEnemy,120);
			frame2=0;
			frame3=0;
		}
		
		}


		yield;
	}
}


task Move(obj, delay){
wait(delay);
ObjMove_SetDestAtWeight(objEnemy,(GetStgFrameWidth()/2)+rand(-70,70),130+rand(-30,30),30,5);

}

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

}

task RotateShot(){
let X=ObjMove_GetX(objEnemy);
let Y=ObjMove_GetY(objEnemy);
let density=2;
let a=rand(0,360);
let dist=0;
let speed=rand(1,2);


loop(density){
se_tan00;
let bulletObj00=CreateShotA1(X+(cos(a)*dist),Y+(sin(a)*dist),speed,a,269,10);
let bulletObj01=CreateShotA1(X+(cos(-a)*dist),Y+(sin(-a)*dist),speed,-a,269,10);
a=rand(0,360);
}

}

task RotateShot2(movX,movY){
let X=ObjMove_GetX(objEnemy);
let Y=ObjMove_GetY(objEnemy);
let density=30;
let a=GetAngleToPlayer(objEnemy)+rand(-6,6);
let dist=0;
se_don00;
let Ball=CreateShotA1(X+(cos(a)*dist),Y+(sin(a)*dist),5,a+rand(-15,15),355,10);
let Ball2=CreateShotA1(X+(cos(a)*dist),Y+(sin(a)*dist),5,a+rand(-15,15),355,10);
loop(density){
se_kira00;
let bulletObj00=CreateShotA1(X+movX,Y+movY,5,a,187,10);
a=GetAngleToPlayer(objEnemy)+rand(-6,6);
yield;
}

}

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

}

