#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Non3 ExAB"]
#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,GetStgFrameWidth/2,GetStgFrameHeight/4,5);
	SFXload;
	mainTask;
} 

@Event { 
	alternative(GetEventType()) 
	case(EV_REQUEST_LIFE) { 
		SetScriptResult(2392);
	}
	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(45,45*2);
	BFX_FocusA1(bossX,bossY,100,VFX_Smoke,VFX_Beams,45);
	wait(60);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	MFireA2;
	wait(260);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	PlaySE(charge5);
	BossConcentrateB1(30);
	BFX_FocusA1(bossX,bossY,100,VFX_Smoke,VFX_Beams,45);
	wait(60);
	MFireB;
	wait(300);
	ObjEnemy_SetDamageRate(bossObj,50,45);
	loop{
	wait(60);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	PlaySE(charge5);
	BossConcentrateA1(45,45*2);
	BFX_FocusA1(bossX,bossY,100,VFX_Smoke,VFX_Beams,45);
	wait(60);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	MFireA1;
	wait(260);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	PlaySE(charge5);
	BossConcentrateB1(30);
	BFX_FocusA1(bossX,bossY,100,VFX_Smoke,VFX_Beams,45);
	wait(60);
	MFireB;
	wait(300);// - - - - -
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	PlaySE(charge5);
	BossConcentrateA1(45,45*2);
	BFX_FocusA1(bossX,bossY,100,VFX_Smoke,VFX_Beams,45);
	wait(60);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	MFireA2;
	wait(260);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	PlaySE(charge5);
	BossConcentrateB1(30);
	BFX_FocusA1(bossX,bossY,100,VFX_Smoke,VFX_Beams,45);
	wait(60);
	MFireB;
	wait(300);
	}
}

task MFireA1{
	let angA = rand(0,360);
	loop(20){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		PlaySE(Eff2);
	loop(2){
	let objMFA = CreateShotA2(bossX,bossY,4.5,angA,-0.1,0,32,0)	;
	AobjFire(objMFA);
	angA+=180;	
	}
	angA+=17.5;
	wait(10);
	}
	
	}
	
task MFireA2{
	let angA = rand(0,360);
	loop(20){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		PlaySE(Eff2);
	loop(2){
	let objMFA = CreateShotA2(bossX,bossY,4.5,angA,-0.1,0,32,0)	;
	AobjFire(objMFA);
	angA+=180;	
	}
	angA-=17.5;
	wait(10);
	}
	
	}
	

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

task MFireB{
	let ang = 0;
	let ang2 = 45;
	let angadd = 20;
	loop(2){
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	let objB1 = CreateShotA2(bossX, bossY,3,ang,-0.1,0,168,30);
	let objB2 = CreateShotA2(bossX, bossY,3,ang2,-0.1,1,167,30);
	ObjShot_SetSpellResist(objB1,true);
	objB1move(objB1);
	FireobjB2(objB2,angadd);
	ang+=180;
	ang2+=90;
	angadd = angadd*-1;
	}
	}

task objB1move(objB1){
	wait(30);
	PlaySE(shot9);
	loop(5){
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	BFX_ExplosionA1(ObjMove_GetX(objB1),ObjMove_GetY(objB1),100,VFX_Smoke,5);
		ObjMove_SetSpeed(objB1,3);
		wait(61);
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		FireobjB1(objB1);
	}
	BFX_ShockwaveA1(ObjMove_GetX(objB1),ObjMove_GetY(objB1),VFX_Sparkle,90,255,5,5,100,60,BLEND_ADD_ARGB,250,10,10);
	//x,y,spritepath,angle,alpha,xscale,yscale,radius,time,blending,angvel,hue,saturation
	Obj_Delete(objB1);
	}
	
task FireobjB1(objB1){
	let ang = rand(0,360);
	loop(15){//----
		PlaySE(wave);
		let objBa1 = CreateShotA2(ObjMove_GetX(objB1),ObjMove_GetY(objB1),10,ang,-0.5,1,100,0);
		let objBa2 = CreateShotA2(ObjMove_GetX(objB1),ObjMove_GetY(objB1),10,ang,-0.5,1,100,0);
		
		objmoveobjBa(objBa1,3);
		objmoveobjBa(objBa2,-3);
		ang+=360/15;//----
	}
}

task FireobjB2(objB2,angadd){
	wait(60);
	let ang = rand(0,360);
	loop{//----
	if(Obj_IsDeleted(objB2)){break;}
	PlaySE(shot1);
		descent(i in 3..8){
		let num = 2;
		loop(num){
			BFX_ShockwaveA1(ObjMove_GetX(objB2), ObjMove_GetY(objB2),VFX_Sparkle,rand(0,360),255,1,1,30,10,BLEND_ADD_ARGB,0,0,100);
			//x,y,spritepath,angle,alpha,xscale,yscale,radius,time,blending,angvel,hue,saturation
        CreateShotA2(ObjMove_GetX(objB2), ObjMove_GetY(objB2),(i/2)+0.5,ang,-0.0075*i,1.5, 11,0);
		ang += 360/num;
		}
	}
		ang+=angadd;//----
		wait(6);
	}
}


task objmoveobjBa(obj,angvel){
	ObjMove_SetAngularVelocity(obj,angvel);
	ObjShot_SetAutoDelete(obj,false);
	wait(45);
	ObjMove_SetAngularVelocity(obj,0);
	wait(180);ObjShot_SetAutoDelete(obj,true);
}

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