#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell 3 H"]
#Text["White Card \"Heavenly Tiger's Net\""]
#Background["./Background.txt"] 

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"
#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(2500);
	}
	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);
	ObjCutin_Name("White Card \"Heavenly Tiger's Net\"");
	BossRender;
	movement;
	end;
} 


task movement {
ObjEnemyBossScene_StartSpell(GetEnemyBossSceneObjectID());


let F2_Las_No = 10;
let F2_Las_Width = 25;
let F2_time = 30; 
let F2_delay_time = 45; 
let F2_delete_time = 60;
let F2_repeat = 3;
let F2_repeat_time = 120;
let F2_Bulspd = 1;
let F2_Bulspd_2 = 0.5;

//F1 Placed here because ORDER
let F1_min_spd = 1;
let F1_max_spd = 3;
let F1_Bul_Time =  F2_repeat_time*3 + F2_time + F2_delete_time;
let F1_Bul_Num = 24;
let F1_Bul_Num_B = 10;
let F1_Yadd = 50;

let F3_Las_No = 9;
let F3_Las_Width = 30;
let F3_angplus = 30;
let F3_time = 180; 
let F3_delay_time = 45; 
let F3_delete_time = 60;
let F3_repeat = 3;
let F3_repeat_time = 120;
let F3_trailnum = 8;
let F3_min_spd = 1;
let F3_max_spd = 3;

wait(120);

begin_wave;
wait(60);
PlaySE(laser5);

Fire1_A(F1_min_spd, F1_max_spd, F1_Bul_Time, F1_Bul_Num);
Fire1_B(F1_min_spd, F1_max_spd, F1_Bul_Time, F1_Bul_Num_B, F1_Yadd);

wait(180);

Fire2_Loop(F2_Las_No, F2_Las_Width, F2_time, F2_delay_time, F2_delete_time, F2_repeat, F2_repeat_time, F2_Bulspd, F2_Bulspd_2);

wait(F2_repeat_time*3 + F2_time + F2_delete_time);

PlaySE(charge2);
Fire3(F3_Las_No, F3_Las_Width, 0, F3_time, F3_delay_time, F3_delete_time, F3_trailnum, F3_min_spd, F3_max_spd, false);

ObjEnemy_SetDamageRate(bossObj,25,25);

loop{

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

Fire1_A(F1_min_spd, F1_max_spd, F1_Bul_Time, F1_Bul_Num);
Fire1_B(F1_min_spd, F1_max_spd, F1_Bul_Time, F1_Bul_Num_B, F1_Yadd);

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

Fire2_Loop(F2_Las_No, F2_Las_Width, F2_time, F2_delay_time, F2_delete_time, F2_repeat, F2_repeat_time, F2_Bulspd, F2_Bulspd_2);

wait(F2_repeat_time*3 + F2_time + F2_delete_time);
if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}

PlaySE(charge2);
Fire3(F3_Las_No, F3_Las_Width, 0, F3_time, F3_delay_time, F3_delete_time, F3_trailnum, F3_min_spd, F3_max_spd, true);


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

Fire1_A(F1_min_spd, F1_max_spd, F1_Bul_Time, F1_Bul_Num);
Fire1_B(F1_min_spd, F1_max_spd, F1_Bul_Time, F1_Bul_Num_B, F1_Yadd);

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

Fire2_Loop(F2_Las_No, F2_Las_Width, F2_time, F2_delay_time, F2_delete_time, F2_repeat, F2_repeat_time, F2_Bulspd, F2_Bulspd_2);

wait(F2_repeat_time*3 + F2_time + F2_delete_time);
if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}

PlaySE(charge2);
Fire3(F3_Las_No, F3_Las_Width, 0, F3_time, F3_delay_time, F3_delete_time, F3_trailnum, F3_min_spd, F3_max_spd, false);

}

}

task begin_wave{
	Acencharge_X(0);
	Acencharge_X(GetStgFrameWidth);
	Acencharge_Y(0);
	Acencharge_Y(GetStgFrameHeight);
	wait(20);
	
}

task Acencharge_X(shootX){
	PlaySE(charge5);
	let time = 5;
	let Laser_no = 20;
	let delay = 10;
	let addX = 30;
	
	
	let addX_dist = addX/Laser_no;
	loop(Laser_no){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		loop(2){
        let lasA = CreateStraightLaserA1(shootX+addX,-40,90,GetStgFrameHeight+100,60,30,152,delay);
        let lasB = CreateStraightLaserA1(shootX-addX,-40,90,GetStgFrameHeight+100,60, 30,152,delay);
		ObjDelete_Delay(lasA,delay-1);
		ObjDelete_Delay(lasB,delay-1);
		}
		addX-=addX_dist;
		wait(time/Laser_no);
    }
	wait(45);
	CreateStraightLaserA1(shootX,-40,90,GetStgFrameHeight+100,60,9999,161,0);

}

task Acencharge_Y(shootY){
	PlaySE(charge5);
	let time = 5;
	let Laser_no = 20;
	let delay = 10;
	let addY = 30;
	
	
	let addY_dist = addY/Laser_no;
	loop(Laser_no){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		loop(2){
        let lasA = CreateStraightLaserA1(-40,shootY+addY,0,GetStgFrameWidth+100,60,30,152,delay);
        let lasB = CreateStraightLaserA1(-40,shootY-addY,0,GetStgFrameWidth+100,60, 30,152,delay);
		ObjDelete_Delay(lasA,delay-1);
		ObjDelete_Delay(lasB,delay-1);
		}
		addY-=addY_dist;
		wait(time/Laser_no);
    }
	wait(45);
	CreateStraightLaserA1(-40,shootY,0,GetStgFrameWidth+100,60, 9999,161,0);

}

task Fire1_A(min_spd, max_spd, Bul_Time, Bul_Num){
	
	loop(Bul_Num){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		let spd = rand(min_spd,max_spd);
		
		let F1_ShotCloudA = CreateShotA2(GetStgFrameWidth, rand(0,GetStgFrameHeight), 0, 180, spd*0.01, spd, round(rand(121,127)), 0);    
		let F1_ShotCloudB = CreateShotA2(0, rand(0,GetStgFrameHeight), 0, 0, spd*0.01, spd, round(rand(121,127)), 0);
	
		ObjRender_SetBlendType(F1_ShotCloudA, BLEND_ADD_ARGB);	
		ObjRender_SetBlendType(F1_ShotCloudB, BLEND_ADD_ARGB);	
		wait(Bul_Time/Bul_Num);
		}
		
}

task Fire1_B(min_spd, max_spd, Bul_Time, Bul_Num, Yadd){
		
	loop(Bul_Num){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){return;}
		let spd = rand(min_spd,max_spd);
		
		let F1_ShotCloudA = CreateShotA2(GetStgFrameWidth, GetPlayerY + rand(-Yadd,Yadd), 0, 180, spd*0.01, spd, round(rand(129,135)), 0);    
		let F1_ShotCloudB = CreateShotA2(0, GetPlayerY + rand(-Yadd,Yadd), 0, 0, spd*0.01, spd, round(rand(129,135)), 0);
	
		ObjRender_SetBlendType(F1_ShotCloudA, BLEND_ADD_ARGB);	
		ObjRender_SetBlendType(F1_ShotCloudB, BLEND_ADD_ARGB);	
		wait(Bul_Time/Bul_Num);
		}
}

task Fire2_Loop(F2_Las_No, F2_Las_Width, F2_time, F2_delay_time, F2_delete_time, F2_repeat, F2_repeat_time, F2_Bulspd, F2_Bulspd_2){
	
	loop(F2_repeat){
		PlaySE(Eff1);
		Fire2(F2_Las_No, F2_Las_Width, F2_time, F2_delay_time, F2_delete_time, F2_Bulspd, F2_Bulspd_2);
		wait(F2_repeat_time);
}
}

task Fire2(Las_No, Las_Width, time, delay_time, delete_time, spd, spd2){
	
	let color = round(rand(1,7));
	
	loop(Las_No){
		let PosX = GetPlayerX;
		PlaySE_Delay(laser4,delay_time);
		CreateStraightLaserA1(PosX,-40,90,GetStgFrameHeight+100,Las_Width,delete_time,152+color,delay_time);

		color++;
		if(color > 7){color = 1;}
		wait(time/Las_No);
	}
	
}

task Fire3(Las_No, Las_Width, angplus, time, delay_time, delete_time, trailnum,  min_spd, max_spd, rev){
	let PosX = rand(-40,0);
	let PosY = -40;
	let ang = 90;
	let PosAdd =  GetStgFrameWidth/(Las_No-2);
	
	let color = round(rand(1,7));
	
	if(rev == true){
		ang = 270; 
		PosY = GetStgFrameHeight+40; 
		PosX = GetStgFrameWidth + rand(0,40);
		PosAdd = (GetStgFrameWidth/(Las_No-2)) * -1;
		}
	
	loop(Las_No){
		let angadd = rand(-angplus, angplus);
		
		PlaySE_Delay(laser4,delay_time);
		CreateStraightLaserA1(PosX,PosY,ang,GetStgFrameHeight+100,Las_Width,delete_time,152 + color,delay_time);
		
		let spd = min_spd;
		loop(trailnum){
		CreateShotA2(PosX, PosY, 0, ang, spd*0.01, spd, 240+color, 30);
		spd += (max_spd/min_spd)/trailnum;
		}
		
		color++;
		if(color > 7){color = 1;}
		PosX += PosAdd;
		wait(time/Las_No);
	}
	
}


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