#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell3 Ea"]
#Text["Myeongyang 'Battle of the Roaring Straight' "]
#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;

let rivermove = false;
let straightup = true;

#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(4706);
	}
	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("Myeongyang \"Battle of the Roaring Straight\"", BossImg, MOKOU, 240, 104, 104);
	ObjCutin_LaunchS3(NAZRIN, BossImg, "Absurdly Extra");
}


task movement {
wait(60);

BossConcentrateB1(45);
PlaySE(charge5);
BFX_FocusA1(bossX,bossY,100,VFX_Smoke,VFX_Beams,45);
wait(60);
ObjEnemy_SetDamageRate(bossObj,50,50);
BossConcentrateB1(45);
PlaySE(charge5);
loop(60){
BFX_FocusA1(GetPlayerX,GetPlayerY,100,VFX_Smoke,VFX_Beams,2.5);
wait(1);
}
rivermove = true;
moverivertask;
}

task moveplayer{
	let player = GetPlayerObjectID;
	let A = 1;
	loop(300){
		if(rivermove == true){
			if(straightup == true){ObjMove_SetY(player,GetPlayerY-A);}
			else if(straightup == false){ObjMove_SetY(player,GetPlayerY+A);}
		}
		yield;
	}
}

task moverivertask{
		straightup = true;
		FakeRiverUp;
		BossShot;
		RiverUp;
		moveplayer;
		wait(300);
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		loop{
			if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
			RiverDown;
		straightup = false;
		moveplayer;
		KoreaShip;
		wait(300);
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		RiverUp;
		straightup = true;
		moveplayer;
		wait(300);
		}
}

task FakeRiverUp{
	let N = 20;//----
	let delay = 270;
	PlaySE(Eff1);
	loop(N){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	let objriver1 = CreateShotA1(rand(0,GetCenterX-100),GetStgFrameHeight,3,270+rand(0,-15),260,10);
	let objriver2 = CreateShotA1(rand(GetCenterX+100,GetStgFrameWidth),GetStgFrameHeight,3,270-rand(-15,0),260,10);
	ObjMove_AddPatternB2(objriver1,delay,NO_CHANGE,NO_CHANGE,0,0.1,0,3);
	ObjMove_AddPatternB2(objriver2,delay,NO_CHANGE,NO_CHANGE,0,0.1,0,3);
	delay-=270/N;
	wait(270/N);
	}
}


task RiverUp{
	wait(180);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	let X = GetStgFrameWidth;
	let N = 10;
	PlaySE(charge2);
	BossConcentrateA1(82,30);
	loop(N){
		BFX_FocusA1(X,GetStgFrameHeight,50,VFX_Smoke,VFX_Beams,90);
		X-=GetStgFrameWidth/(N-1);
	}
	wait(120);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	PlaySE(Eff1);
	loop(N+3){
		explodeDown(X);
		BFX_ExplosionA1(X,GetStgFrameHeight,1,VFX_Smoke,5);
		X+=GetStgFrameWidth/(N);
	}
	let N2 = 30;
	let delay = 270;
	loop(N2){
	let objriver1 = CreateShotA1(rand(0,GetStgFrameWidth),0,3,90+rand(0,-15),260,10);
	ObjMove_AddPatternB2(objriver1,delay,NO_CHANGE,NO_CHANGE,0,-0.1,0,-3);
	delay-=270/N2;
	wait(270/N2);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	}
	
}

task explodeUp(X){
	loop(300/15){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	BFX_ExplosionA1(X,-20,1,VFX_Smoke,1);
	wait(15);
	}
}

task RiverDown{
	wait(180);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	let X = GetStgFrameWidth;
	let N = 10;
	PlaySE(charge2);
	BossConcentrateA1(82,30);
	loop(N){
		BFX_FocusA1(X,0,50,VFX_Smoke,VFX_Beams,90);
		X-=GetStgFrameWidth/(N-1);
	}
	wait(120);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	PlaySE(Eff1);
	loop(N+3){
		explodeUp(X);
		BFX_ExplosionA1(X,0,1,VFX_Smoke,5);
		X+=GetStgFrameWidth/(N);
	}
	let N2 = 30;
	let delay = 270;
	loop(N2){
	let objriver1 = CreateShotA1(rand(0,GetStgFrameWidth),GetStgFrameHeight,3,270+rand(0,-15),260,10);
	ObjMove_AddPatternB2(objriver1,delay,NO_CHANGE,NO_CHANGE,0,0.1,0,3);
	delay-=270/N2;
	wait(270/N2);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	}
	
	}
	
task KoreaShip{
	let X = GetStgFrameWidth;
	let N = 5;
	let Lo = 5; 
	let delay = 300+260;
	loop(Lo){
		PlaySE(shot3);
	loop(N){
		let Boat = CreateShotA1(X,0,3.5,90,25,00);
		delete_boat(Boat);
		ObjShot_SetSpellResist(Boat,true);
		ObjShot_SetAutoDelete(Boat,false);
		ObjMove_AddPatternB2(Boat,delay,rand(-1,1),NO_CHANGE,0,-0.1,rand(-3,3),-3);
		ObjMove_AddPatternB2(Boat,delay+200,NO_CHANGE,NO_CHANGE,0,0.1,NO_CHANGE,3);
		X-=GetStgFrameWidth/(N-1);
	}
	delay-=270/(Lo);
	wait(270/(Lo*2));
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	PlaySE(shot3);
	loop(N){
		let Boat = CreateShotA1(X+(GetStgFrameWidth/(N-1))/2,0,3.5,90,25,0);
		delete_boat(Boat);
		ObjMove_AddPatternB2(Boat,delay,rand(-1,1),NO_CHANGE,0,-0.1,rand(-3,3),-3);
		ObjMove_AddPatternB2(Boat,delay+200,NO_CHANGE,NO_CHANGE,0,0.1,NO_CHANGE,3);
		ObjShot_SetSpellResist(Boat,true);
		ObjShot_SetAutoDelete(Boat,false);
		X+=GetStgFrameWidth/(N-1);
	}
	delay-=270/(Lo);
	wait(270/(Lo*2));
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	}
}

task delete_boat(Boat){wait(470);ObjShot_SetAutoDelete(Boat,true);}

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

task BossShot{
	wait(660);
	BossConcentrateB1(45);
PlaySE(charge5);
BFX_FocusA1(bossX,bossY,100,VFX_Smoke,VFX_Beams,45);
wait(60);
	loop{
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		PlaySE(shot1);
		ascent(i in 2..5){
			ascent(ang in -2..3){
			CreateShotA2(bossX,bossY,0.1,GetAngleToPlayer(bossObj)+ang*40,0.1,i,24,10);
			}
		}
		wait(60);
		
	}
}

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