#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Scrapped 1 E"]
#Text["White Card \"Heavenly Tiger's Net\""]

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(3656);
	}
	case(EV_REQUEST_TIMER) { 
		SetScriptResult(60);
	}
} 

@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);
	//Insert Cut-in task
	BossRender;
	movement;
	end;
} 


task movement {
ObjEnemyBossScene_StartSpell(GetEnemyBossSceneObjectID());

let F1_Bul_Num = 1;
let F1_Bul_Time = 9;

let F2_loop_delay = 120;
let F2_Bul_num = 5;
let F2_Bul_spd = 2;
let F2_Bul_length_time = 10;
let F2_Bul_time_delay = 30;

let F3_spd = 5;
let F3_acc = -0.01*5;
let F3_max_spd = 2;
let F3_time = 60;

																																																			
wait(120);
PlaySE(charge4);
BFX_FocusA1(bossX,bossY,100,VFX_Smoke,VFX_Beams,45);
Fire1(F1_Bul_Num, F1_Bul_Time);
wait(60);

wait(60*5);

PlaySE(charge4);
BFX_FocusA1(bossX,bossY,100,VFX_Smoke,VFX_Beams,45);
wait(60);

ObjEnemy_SetDamageRate(bossObj,100,100);

Fire2_loop(F2_loop_delay, F2_Bul_num, F2_Bul_spd, F2_Bul_length_time, F2_Bul_time_delay);

wait(F2_loop_delay * 4);

PlaySE(charge4);
BFX_FocusA1(bossX,bossY,100,VFX_Smoke,VFX_Beams,45);
wait(60);

Fire3(F3_time, F3_spd, F3_acc, F3_max_spd);



}

task Fire1(Bul_Num, Bul_Time){
	let posX_A = GetCenterX + 50;
	let posX_B = GetCenterX - 50;
	
	let X_Fin = 0;
	let Cloud_Num = 5;
	let Cloud_time = 30;

		loop(15){
		loop(Cloud_Num){	
			
		let F1_CloudA = CreateShotA1(posX_A + X_Fin,rand(0,GetStgFrameHeight), 0, 0, 8, 30);
		let F1_CloudB = CreateShotA1(posX_B - X_Fin,rand(0,GetStgFrameHeight), 0, 0, 8, 30);
		let F1_CloudC = CreateShotA1(posX_A + X_Fin,rand(0,GetStgFrameHeight), 0, 0, round(rand(1,8)), 30);
		let F1_CloudD = CreateShotA1(posX_B - X_Fin,rand(0,GetStgFrameHeight), 0, 0, round(rand(1,8)), 30);
		
		ObjDelete_Delay(F1_CloudA, 29);
		ObjDelete_Delay(F1_CloudB, 29);
		ObjDelete_Delay(F1_CloudC, 29);
		ObjDelete_Delay(F1_CloudD, 29);
		}
		
		X_Fin += ((GetCenterY-50)/20);
	wait(Cloud_time/Cloud_Num);
	}
	
	PlaySE(Eff1);
	
	Fire1_Shot(posX_A + X_Fin, posX_B - X_Fin, Bul_Time, Bul_Num);
	
	loop{
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	loop(Cloud_Num){
		let F1_CloudA = CreateShotA1(posX_A + X_Fin + rand(-30,0),rand(0,GetStgFrameHeight), 0, 0, 8, 30);
		let F1_CloudB = CreateShotA1(posX_B - X_Fin + rand(0,30),rand(0,GetStgFrameHeight), 0, 0, 8, 30);
		
		ObjDelete_Delay(F1_CloudA, 29);
		ObjDelete_Delay(F1_CloudB, 29);
		
		}
		wait(Cloud_time/Cloud_Num);
	}
	
}

task Fire1_Shot(posX_A, posX_B, Bul_Time, Bul_Num){
	loop{
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
	loop(Bul_Num){
		let XRandA = rand(-50,0);
		let XRandB = rand(0,50);
		
		let PosY_A = rand(0,GetStgFrameHeight);
		let PosY_B = rand(0,GetStgFrameHeight);
		
		let spd = rand(1,3);
		
		let F1_ShotCloudA = CreateShotA2(posX_A + XRandA, PosY_A, 0, 180, spd*0.01, spd, round(rand(121,127)), 30);    
		let F1_ShotCloudB = CreateShotA2(posX_B + XRandB, PosY_B, 0, 0, spd*0.01, spd, round(rand(121,127)), 30);
	
		}
		wait(Bul_Time);
	}
}

task Fire2_loop(loop_delay, F2_Bul_num, F2_Bul_spd, F2_Bul_length_time, F2_Bul_time_delay){
	loop{
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		PlaySE(shot4);
		Fire2(false, F2_Bul_num, F2_Bul_spd, F2_Bul_length_time, F2_Bul_time_delay);
		wait(loop_delay);
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		PlaySE(shot4);
		Fire2(true, F2_Bul_num, F2_Bul_spd, F2_Bul_length_time, F2_Bul_time_delay);
		wait(loop_delay);
	}
}

task Fire2(rev, Bul_num, Bul_spd, Bul_length_time, Bul_time_delay){
	let X_add = GetCenterX/3;
	let posX = X_add;
	
	if(rev == true){posX = GetStgFrameWidth - X_add}
	
	let Fire2_Obj = CreateShotA2(posX, -10, 3, 90, -0.05, 1, 136, 0);
	
	ObjShot_SetSpellResist(Fire2_Obj,true);
	/*ObjShot_SetAutoDelete(Fire2_Obj,false);
	ObjDelete_Delay(Fire2_Obj, 60*9);
	*/
	Fire2_Obj_Shot(Fire2_Obj, Bul_num, Bul_spd, Bul_length_time, Bul_time_delay);
	}
	
task Fire2_Obj_Shot(Fire2_Obj, Bul_num, Bul_spd, Bul_length_time, Bul_time_delay){
	wait(3/0.05);
	let angadd = 60;
	loop{
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		if(Obj_IsDeleted(Fire2_Obj)){return;}
	loop(Bul_num){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		if(Obj_IsDeleted(Fire2_Obj)){return;}
		let ang = 270 - (angadd * (2)) + ((angadd)/2);
	loop(4){
		let F2obj_shot = CreateShotA2(ObjMove_GetX(Fire2_Obj), ObjMove_GetY(Fire2_Obj), 0, ang, Bul_spd*0.025, Bul_spd, 48, 0);
		
		ang += angadd;
			}
	wait(Bul_length_time/Bul_num);
	}
	wait(Bul_time_delay);
	}
}

task Fire3(time, spd, acc, max_spd){
	
	let color = 165;
	PlaySE(shot7);
	
	loop{
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		PlaySE(shot7);
		CreateShotA2(bossX, bossY, spd, GetAngleToPlayer(bossObj), acc, max_spd,color,0 );
		wait(time);
		color++;
		if(color >= 172){ color = 165; }
	}
}

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