#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Scrapped 2"]
#Text["(Scrapped) Asterism Creation \"Rise of 28 Mansions\""]

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,GetCenterY/2,5);
	SFXload;
	mainTask;
} 

@Event { 
	alternative(GetEventType()) 
	case(EV_REQUEST_LIFE) { 
		SetScriptResult(3656);
	}
	case(EV_REQUEST_TIMER) { 
		SetScriptResult(999);
	}
} 

@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());
	
wait(60);
	
PlaySE(charge4);
BFX_FocusA1(bossX,bossY,100,VFX_Smoke,VFX_Beams,45);

wait(120);

Fire;

}

task Fire{
	let F1_time = 60;
	let F1_time2 = 30;
	let F1_bull_wave = 7;
	let F1_bull_wave2 = 1;
	let F1_bull_num = 7;
	let F1_min_spd = 1.5;
	let F1_max_spd = 3;
	
	
	let F2_num = 15;
	let F2_min_spd = 1;
	let F2_max_spd = 3;
	let F2_time = 240;
	let F2_angadd = 20;
	let F2_trailnum = 10;
	
	let F5_num = 15;
	let F5_spd = 20;
	let F5_time = 240;
	let F5_angadd = 20;
	
	wait(120);
	
	
	//Fire1A(F1_time, F1_time2, F1_bull_wave, F1_bull_wave2, F1_bull_num, F1_min_spd, F1_max_spd);
	
	
	Fire2_loop(F2_num, F2_min_spd, F2_max_spd, F2_time, F2_angadd, F2_trailnum);
	Fire5_loop(F5_num, F5_spd, F5_time, F5_angadd);
	
	

}

task Fire1A(time, time2, bull_wave, bull_wave2, bull_num, min_spd, max_spd){
	let ang = 90;
	
	loop{	
	loop(bull_wave){
			Fire1_Shot(ang, time2, bull_wave2, bull_num, min_spd, max_spd);
			ang+=360/bull_wave;
			}
			wait(time*1.5);
	ang+= (360/bull_wave) / 2;
	}
}

task Fire1_Shot(angle, time, bull_wave2, bullnum, min_spd, max_spd){
	let randang = 30;
	let randang2 = randang;
	let spd = min_spd;
	loop(bullnum){
		PlaySE(shot2);
		loop(bull_wave2){
			CreateShotA2(GetCenterX, 0, spd, angle + rand(-randang, randang), -(spd*0.01), spd*0.3, round(rand(121,122)), 10);
		}
		randang -= randang2/bullnum;
		spd += max_spd/(min_spd*bullnum);
		wait(time/bullnum)
	}
}

task Fire2_loop(F2_num, F2_min_spd, F2_max_spd, F2_time, F2_angadd, F2_trailnum){
	//while (bossHP !== Something){wait(240);}
	loop{
		Fire_2(F2_num, F2_min_spd, F2_max_spd, F2_time, F2_angadd, F2_trailnum, false);
		wait(240);
		Fire_2(F2_num, F2_min_spd, F2_max_spd, F2_time, F2_angadd, F2_trailnum, true);
		wait(240);
	}
}

task Fire_2(num, min_spd, max_spd, time, angadd, trailnum, rev){
	 
	 
	PlaySE(shot4);

	
	let ang = 0;
	let a = 1;
	
	if(rev == true){ang = 180; a = -1;}
	ang+= rand(-angadd,angadd);
	PlaySE(boon1);
	let color = round(rand(0,1));
	loop(num){
		
		
		ascent(i in 1 .. trailnum + 1){
		CreateShotA2((GetStgFrameWidth/2)+(80*cos(ang)),0+(30*sin(ang)),0.1,ang+angadd*a,(min_spd * i / max_spd)* 0.01, 1 + (min_spd * i / max_spd), 123+color, 30);
		}
		CreateShotA2((GetStgFrameWidth/2)+(80*cos(ang)),0+(30*sin(ang)),0.1,ang+angadd*a,(max_spd+1) * 0.01, 1 + max_spd, 131+color, 30);
		
		ang+= (180/num)*a;
		color++;
		if(color > 1){color = 0;}
	wait(time/num);
	}
}

task Fire5_loop(F5_num, F5_spd, F5_time, F5_angadd){
	//while (bossHP !== Something){wait(240);}
	loop{
		Fire_5(F5_num, F5_spd, F5_time, F5_angadd,true);
		wait(240);
		Fire_5(F5_num, F5_spd, F5_time, F5_angadd,false);
		wait(240);
	}
}

task Fire_5(num, spd, time, angadd, rev){
	
	let ang = 0;
	let a = 1;
	
	if(rev == true){ang = 180; a = -1;}
	ang+= rand(-angadd,angadd);
	PlaySE(boon1);
	loop(num){
		PlaySE(laser5);
	CreateLooseLaserA1((GetStgFrameWidth/2)+(80*cos(ang)),0+(30*sin(ang)),spd,ang+angadd*a,1000,20,72,60);
	let delay = CreateStraightLaserA1((GetStgFrameWidth/2)+(80*cos(ang)),0+(30*sin(ang)),ang+angadd*a,400,10,30,48,60);
	ObjDelete_Delay(delay,59);
		ang+= (180/num)*a;
	wait(time/num);
	}
}

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