#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell2 Ea"]
#Text["Resistance 'Okpo Harbor Counter Attack'"]
#Background["./Background.txt"]
#System["./System test/SystemMain.txt"]
#BGM ["./BGM/The Whirlwind of Seven Evil Samurais.mp3"]
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"
#include"./Cutin/Cutin.txt"
@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);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
} 

@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);
	ObjEnemyBossScene_StartSpell(GetEnemyBossSceneObjectID());
	Start;
	BossRender;
	movement;
	end;
} 


task Start{
	let BossImg = GetCurrentScriptDirectory ~ "img/Cut-ins/Yi/YSS Normal.png";
	ObjCutin_SetSpellcardS4("Resistance \"Okpo Harbor Counter Attack\"", BossImg, KANAKO, 240, 104, 104);
	ObjCutin_LaunchS3(NAZRIN, BossImg, "Easy Extra");
}


task movement {
wait(60);
let X = GetStgFrameWidth;
let N = 10;
PlaySE(charge2);
BossConcentrateA1(82,30);
	loop(N){
		BFX_FocusA1(X,GetStgFrameHeight,100,VFX_Smoke,VFX_Beams,90);
		X-=GetStgFrameWidth/(N-1);
	}
	wait(120);
	PlaySE(Eff1);
	loop(N+3){
		explode(X);
		BFX_ExplosionA1(X,GetStgFrameHeight,1,VFX_Smoke,5);
		X+=GetStgFrameWidth/(N);
	}
	wait(30);
	PlaySE(slash);
	let laserX = CreateStraightLaserA1(-30,bossY,0,999,30,30,160,9999) ;
	let de2 = CreateStraightLaserA1(-30,bossY,0,999,30,0,160,0) ;
	ObjRender_SetColor(de2,255,255,255);
	wait(30);
	Boat(laserX);
	Antisafe(laserX);

}

task explode(X){
	loop{
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	BFX_ExplosionA1(X,GetStgFrameHeight+20,1,VFX_Smoke,1);
	wait(15);
	}
	
}

task Boat(laserX){
	wait(120);
	ObjEnemy_SetDamageRate(bossObj,75,50);
	let N = 10;
	let X2 = 0;
	loop{
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		
		loop(4){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		Acencharge(GetPlayerX,laserX);
		ObjMove_SetDestAtSpeed(bossObj,GetPlayerX+rand(-25,25),rand(50,75),3);
		wait(120);
		}
		
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		
		let X = 0;
		PlaySE(charge2);
		BossConcentrateB1(120);
		loop(N){
		BFX_FocusA1(X2,GetStgFrameHeight+50,100,VFX_Smoke,VFX_Beams,90);
		X2+=GetStgFrameWidth/(N-1);
		}
		
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return}
		
		loop(5){
			if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
			Acencharge(X,laserX);
			X+=GetStgFrameWidth/4;
			wait(45);
		}
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		
		wait(300);
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		
		loop(4){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		Acencharge(GetPlayerX,laserX);
		ObjMove_SetDestAtSpeed(bossObj,GetPlayerX+rand(-25,25),rand(50,75),3);
		wait(120);
		}
		
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		PlaySE(charge2);
		BossConcentrateB1(120);
		loop(N){
		BFX_FocusA1(X2,GetStgFrameHeight+50,100,VFX_Smoke,VFX_Beams,90);
		X2-=GetStgFrameWidth/(N-1);
	}
		
		loop(5){
			if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
			X-=GetStgFrameWidth/4;
			Acencharge(X,laserX);
			wait(45);
		}
		
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		wait(300);
}
}

task Acencharge(shootX,laserX){
	PlaySE(charge5);
	let delay = 10;
	let a = 30;
	let b = a/19;
	BFX_FocusA1(shootX,GetStgFrameHeight,50,VFX_Smoke,VFX_Beams,20);
	loop(20){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		loop(2){
        let lasA = CreateStraightLaserA1(shootX+a,-40,90,GetStgFrameHeight+100,60,30,152,delay);
        let lasB = CreateStraightLaserA1(shootX-a,-40,90,GetStgFrameHeight+100,60, 30,152,delay);
		AmoveLas(lasA,delay);
		AmoveLas(lasB,delay);
		}
		delay+= 1;
		a-=b;
		wait(1);
    }
	bombshot(shootX,laserX);
}
task AmoveLas(las,delay){wait(delay-1);Obj_Delete(las);}

task bombshot(X,laserX){
	PlaySE(shot3);
	let Y = GetStgFrameHeight+40;
	let BoatMain = CreateShotA1(X,Y,3,270,22,30);
	ObjShot_SetAutoDelete(BoatMain,false);
	ObjShot_SetSpellResist(BoatMain,true);
	let angleT = 270;
	
	loop(20){
	let Boatrim = CreateShotA1(X+10*cos(angleT),Y+35*sin(angleT),3,270,8,30);
	delete_rim(Boatrim,BoatMain);
	ObjShot_SetAutoDelete(Boatrim,false);
	ObjShot_SetSpellResist(Boatrim,true);
	angleT+=360/20;
	}
	
	Upshot(BoatMain);
	while(ObjMove_GetY(BoatMain)>ObjMove_GetY(laserX)){yield;}
	delete_boat(BoatMain);
}

task delete_boat(Main){
	let XMain = ObjMove_GetX(Main);
	let YMain = ObjMove_GetY(Main);
	PlaySE(slash);
	let angleT = rand(-15,15);
	let de2 = CreateStraightLaserA1(XMain+500*cos(angleT),YMain+500*sin(angleT),angleT-180,999,10,10,160,5) ;
	ObjRender_SetColor(de2,255,255,255);
	BFX_ExplosionA1(XMain,YMain,10,VFX_Smoke,5);
	fireA1(XMain,YMain,Main);
	yield;
	Obj_Delete(Main);
}
task delete_rim(Rim,Main){
	while(!Obj_IsDeleted(Main)){yield;}
	Obj_Delete(Rim);
}

task Upshot(obj){//----
	wait(rand(0,30));
	loop{
		if(Obj_IsDeleted(obj)){return;}
		let ang = 0; 
		loop(2){
		CreateShotA2(ObjMove_GetX(obj),ObjMove_GetY(obj),0.1,ang,0.01,3,48,5);
		ang+=360/2;
		}
		wait(15);
	}
	
}

task fireA1(X,Y,obj){//----
	PlaySE(shot1);
	let ang = GetAngleToPlayer(obj);
	loop(7){
		ascent(i in 1..9){
		let shotdest = CreateShotA2(X,Y,0,ang,0.025,i/2,16,0);
					ObjRender_SetBlendType(shotdest,BLEND_ADD_ARGB);
		}
		ang+=360/7;
	}
	ascent(i in -10..10){
	let MfBObjA = CreateShotA2(X,Y,i*3,0,-0.030*i,0,25,0);	
	let MfBObjB = CreateShotA2(X,Y,i*3,180,-0.030*i,0,26,0);	
	ObjShot_SetSpellResist(MfBObjA,true);
	ObjShot_SetAutoDelete(MfBObjA,false);
	ObjShot_SetSpellResist(MfBObjB,true);
	ObjShot_SetAutoDelete(MfBObjB,false);
	MoveObj(MfBObjA,90+40);
	MoveObj(MfBObjB,90-40);
	}
	
	}

task MoveObj(obj,ang){//----
	wait(120);
	PlaySE(Eff1);
	ObjMove_SetAngle(obj,ang);
	ObjMove_SetAcceleration(obj,0);
	ObjMove_SetMaxSpeed(obj,10);
	ObjMove_SetSpeed(obj,2);
	wait(180);
	ObjShot_SetAutoDelete(obj,true);
}

task Antisafe(lasY){
	loop{
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		let angleT = rand(-45,45);
	if(GetPlayerY< ObjMove_GetY(lasY)){
		PlaySE(slash);
		CreateStraightLaserA1(GetPlayerX+500*cos(angleT),GetPlayerY+500*sin(angleT),angleT-180,999,10,30,153,30); 
		wait(10);
	}
	yield;
	}
}

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