#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Midboss2"]
#Text["Woop"]


let objBoss;

let BossX;
let BossY;

#include "./Functions/Index.txt"


@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	whiteUFO(objBoss);
	BossShotSound(objBoss, 100, 600);
	BottomEnemyMarker(objBoss, objBoss);
	ObjEnemy_SetDamageRate(objBoss, 0, 0);
	//ObjMove_SetPosition(objBoss,GetStgFrameWidth/2,200);
	mainTask;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(4500);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(60);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
} 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	
	ObjEnemy_SetIntersectionCircleToShot(objBoss,BossX,BossY,21);
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,BossX,BossY,16);
	yield;
} 

@Finalize {

} 

task mainTask { 
	wait(90);
	SpellCard("&quot;Purified Undefind Danmaku&quot;");
	
	ObjMove_SetDestAtWeight(objBoss,384/2,100,5,2);
	loop(12){
	ascent(i in 0..5){
	let obj = CreateShotA2(BossX, BossY, 0.1, GetAngleToPlayer(objBoss)-90+(i*45), 0.01, 10, ARROW_GRAY, 0);
	}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/spirit.wav", 70);
	wait(5);
	}
	
	wait(70);
	ObjEnemy_SetDamageRate(objBoss, 70, 70);
	ConcentrationA1(objBoss,"CHERRY",60,3,120,[255,255,255]);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/charge.wav", 70);
	
	wait(60);
	ascent(i in 0..50){
		ascent(j in 0..10){
		let obj = CreateShotA2(BossX, BossY, 0.2, 0+(i*360/50), 0.02, 10, ORB_GRAY, 0+(j*10));
		ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
		}
	}
	
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/death.wav", 70);
	wait(160);
	
	let count = 0;
	loop{
	let mult = 0;
	let angle = 0;
	let boop = 0;
	loop(100){
	if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) == 0){loop{yield;}}
		ascent(i in 0..6){
		CreateShotA2(BossX, BossY, 0.8, angle+(i*360/6), 0.02, 50, OVAL_GRAY, 5);
		}
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 70);
		angle+=1*mult;
		if(mult<5){mult+=0.5;}
		boop++;
		if(count>0){
			if(boop == 20 || boop == 40 || boop == 60|| boop == 80 || boop == 100){
			CreateStraightLaserA1(BossX, BossY, GetAngleToPlayer(objBoss), 400, 25, 20, ST_LASER_GRAY, 60);
			SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/laser1.wav", 80);
			}
		}
		wait(1);
	}
	wait(90);
		loop(4){
		let ang = 0;
		let player = GetAngleToPlayer(objBoss);
		if(count>0){
				ascent(i in 0..30){
				if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) == 0){loop{yield;}}
						ascent(j in 0..8){
				CreateShotA2(BossX, BossY, 2, player+ang+(j*360/8), 0.01, 50, PELLET_GRAY, 5);
				CreateShotA2(BossX, BossY, 2, player-ang+(j*360/8), 0.01, 50, PELLET_GRAY, 5);
						}
				if(i>12){ang+=4;}
				SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 50);
				wait(3);
				}

		}
		if(count==0){
			ascent(i in 0..30){
			if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) == 0){loop{yield;}}
			CreateShotA2(BossX, BossY, 3, player+ang, 0.02, 50, PELLET_GRAY, 5);
			CreateShotA2(BossX, BossY, 3, player-ang, 0.02, 50, PELLET_GRAY, 5);
			if(i>12){ang+=4;}
			SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 50);
			wait(2);
			}
		}
		}
	wait(30);
	count++;
	}
}

function SpellCard(name){
	ObjCutin_SetSpellcardS3(name, 25, 25, 25);
	ObjCutin_LaunchS3("KANAKO", 0, "Normal");
	TCallBg2;
	bspell = true;
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);
	wait(210);
}

task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
	Obj_Delete(objBoss);
	SetCommonData("deathsound",1);
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	
	let Dummy;
	Dummy = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(Dummy);
	whiteUFO(Dummy);
	ObjMove_SetPosition(Dummy,BossX,BossY);
	wait(30);
	ObjMove_SetDestAtWeight(Dummy,GetStgFrameWidth+200,150,5,4);
	wait(120);
	
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 
