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

@Event { 
	alternative(GetEventType()) 
	case(EV_REQUEST_LIFE) { 
		SetScriptResult(2173);
	}
	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;}
	MFireA;
	wait(270);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	PlaySE(charge5);
	BossConcentrateB1(40);
	BFX_FocusA1(bossX,bossY,100,VFX_Smoke,VFX_Beams,20);
	wait(30);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	MFireB;
	wait(60);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	ObjEnemy_SetDamageRate(bossObj,50,40);
	loop{
		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;}
	MFireA;
	wait(270);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	PlaySE(charge5);
	BossConcentrateB1(40);
	BFX_FocusA1(bossX,bossY,100,VFX_Smoke,VFX_Beams,20);
	wait(30);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	MFireB;
	wait(60);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	}
}

task MFireA{
	let AngA = 135;
	let AngB = 45;
	let num = 17.5;
	let Aadd = num;
	let Badd = -num;
	let spd = 4.5;
	let spdA = 0.05;
	loop(17){
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	BFX_ShockwaveA1(bossX,bossY,VFX_Sparkle,rand(0,360),999,5,5,100,10,BLEND_ADD_ARGB,0,10,10);
	//x,y,spritepath,angle,alpha,xscale,yscale,radius,time,blending,angvel,hue,saturation
	PlaySE(Eff2);
	let MfObjA = CreateShotA2(bossX,bossY,spd,AngA,-0.1,0,32,0)	;
	let MfObjB = CreateShotA2(bossX,bossY,spd,AngB,-0.1,0,32,0)	;
	ObjShot_SetSpellResist(MfObjA,true);
	ObjShot_SetSpellResist(MfObjB,true);
	AObjFire(MfObjA);
	AObjFire(MfObjB);
	AngA+=Aadd;
	AngB+=Badd;
	if((AngA >= 270 || AngB <= -270)){Aadd = Aadd*-1;Badd = Badd*-1;}
	if((AngB >= 45 || AngA <= 135)){Aadd = Aadd*-1;Badd = Badd*-1;}
	spd+=spdA;
	spdA+=0.005;
	wait(10);
	}
	
}

task AObjFire(obj){
	wait(60);
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	if(Obj_IsDeleted(obj)){break;}
	let Angfire = 90+rand(-20,20);
	let num2 = 11;//----
	BFX_ExplosionA1(ObjMove_GetX(obj),ObjMove_GetY(obj),100,VFX_Smoke,1.25);
	PlaySE(shot1);
	loop(num2){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		let ran = rand(2,4);
	ascent(i in 1..3){
	CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),(ran*i)/3,Angfire,80,0);
	}
	Angfire+=360/num2;
	}
	Obj_Delete(obj);
}

task MFireB{
	let ang = 0;
	loop(2){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	let objB1 = CreateShotA2(bossX, bossY,3,ang,-0.1,0,165,30);
	ObjRender_SetBlendType(objB1,BLEND_ALPHA);
	Fire1objB1(objB1);
	ObjShot_SetSpellResist(objB1,true);
	objB1move(objB1);
	ang+=180;
	}
	}

task objB1move(objB1){
	wait(30);
	PlaySE(shot9);
	loop(5){
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		PlaySE(water);
		ObjMove_SetSpeed(objB1,3);
		wait(61);
	}
	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 Fire1objB1(objB1){	
wait(60);
let ang = GetAngleToPlayer(bossObj);
loop(4){//----

if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}

	descent(i in 4..10){
		PlaySE(shot1);
		let num = 10;
		loop(num){
			BFX_ShockwaveA1(ObjMove_GetX(objB1), ObjMove_GetY(objB1),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(objB1), ObjMove_GetY(objB1),(i/2)+0.5,ang,-0.0075*i,1,9,0);
		ang += 360/num;
		}
		yield;
	}
	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());
}