#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Non5 Ex"]
#Text["Admiral Yi"]
#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"

@Initialize {
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(bossObj);
	ObjMove_SetDestAtSpeed(bossObj,GetCenterX,GetStgFrameHeight/4,5);
	SFXload;
	mainTask;
} 

@Event { 
	alternative(GetEventType()) 
	case(EV_REQUEST_LIFE) { 
		SetScriptResult(1312);
	}
	case(EV_REQUEST_TIMER) { 
		SetScriptResult(61);
	}
} 

@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);
	BossRender;
	movement;
	end;
} 


task movement {
	wait(60);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	PlaySE(charge5);
	BossConcentrateA1(55,45*2);
	BFX_FocusA1(bossX,bossY,100,VFX_Smoke,VFX_Beams,45);
	wait(60);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	firecycle1;
	wait(120);
	firecycle2;
	wait(60);
	ObjEnemy_SetDamageRate(bossObj,50,100);
}

task firecycle1 {
loop{
if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
MFireA;
wait(300);
}
}

task MFireA{
	let objA1 = CreateShotA2(bossX, bossY,3,GetAngleToPlayer(bossObj),-0.1,0,25,0);
	ObjShot_SetSpellResist(objA1,true);
	objB1move(objA1);
	
	let ang = GetAngleToPlayer(bossObj);
	Fire2objB1(objA1);
	loop(4){
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		loop(6){
        FireobjB1(objA1,ang);
		ang+=360/6;
		}	
		wait(60);
		ang = GetAngleToPlayer(bossObj);
	}
	}

task objB1move(objA1){
	PlaySE(shot9);
	wait(30);
	loop(3){
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
if(Obj_IsDeleted(objA1)){return;}
		PlaySE(water);
		ObjMove_SetAngle(objA1,GetAngleToPlayer(objA1));
		ObjMove_SetSpeed(objA1,3);
		wait(61);
	}
	PlaySE(famdiefx);
	BFX_ExplosionA1(ObjMove_GetX(objA1),ObjMove_GetY(objA1),100,VFX_Smoke,2);
	Obj_Delete(objA1);
	}
	
task FireobjB1(objA1,ang){
	wait(30);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
if(Obj_IsDeleted(objA1)){return;}
		PlaySE(shot2);
		ascent(i in -2..3){
        let objB2 = CreateShotA1(ObjMove_GetX(objA1), ObjMove_GetY(objA1), 3,ang+(i*6), 65,0);
		}
		wait(60);
	}

task Fire2objB1(objA1){	
wait(30);
let ang = rand(0,360);
loop(9){//----
if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
if(Obj_IsDeleted(objA1)){return;}
	PlaySE(shot1);
	loop(17){
        CreateShotA1(ObjMove_GetX(objA1), ObjMove_GetY(objA1), 3,ang, 41,0);
		ang += 360/17;
	}
	ang+=(360/17)/2;
	wait(20);//----
}
}

//-- --- -----

task firecycle2 {
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	PlaySE(charge2);
	BossConcentrateA1(100,60);
	BFX_FocusA1(bossX,bossY,250,VFX_Smoke,VFX_Beams,60);
	BossConcentrateB1(30);
	wait(90);
	let angAdd = 21;
	loop{
		let angA = rand(0,360);
		let spd = 1;
	loop(20){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		PlaySE(Eff2);
	let objMFA = CreateShotA2(bossX,bossY,spd,angA,-0.1,0,32,0)	;
	AobjFire(objMFA);
	angA+=angAdd;
	spd+=0.25;
	wait(10);
	}
	wait(30);
	ObjMove_SetDestAtSpeed(bossObj,GetCenterX + rand(-30,30),rand(-20,0)+GetStgFrameHeight/4,2);
	wait(60);
	angAdd = angAdd*-1;
	}
}

task AobjFire(obj){
	wait(60);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	if(Obj_IsDeleted(obj)){return;}
	PlaySE(shot4);
	BFX_ExplosionA1(ObjMove_GetX(obj),ObjMove_GetY(obj),100,VFX_Smoke,1);
	ascent(i in 1..6){//----
		let ang = GetAngleToPlayer(obj);
		loop(8){
	CreateShotA2(ObjMove_GetX(obj),ObjMove_GetY(obj),0.1,ang,0.05,i*0.95,80,0);
	ang+=360/8;
		}
	}
	Obj_Delete(obj);
}


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