#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Midboss1"]
#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);
	ObjMove_SetPosition(objBoss,GetStgFrameWidth/2,-50);
	ObjMove_SetDestAtWeight(objBoss,384/2,100,5,2);
	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);
	loop{
	ObjEnemy_SetDamageRate(objBoss, 100, 100);
	while(!Obj_IsDeleted(objBoss)){
	let random = rand(0, 360);
		ascent(i in 0..24){
		CreateShotA2(BossX, BossY, 0.9, random+(i*360/24), 0.01, 50, PELLET_GRAY, 5);
		}
		random+=360/42;
		ascent(i in 0..24){
		CreateShotA2(BossX, BossY, 0.9, random+(i*360/24), 0.015, 50, PELLET_GRAY, 5);
		}
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 70);
		wait(40);
		ObjMove_SetDestAtWeight(objBoss,384/2,500,5,0.7);
		if(ObjMove_GetY(objBoss)>300){break;}
	}
	ObjMove_SetDestAtWeight(objBoss,384/2,100,5,4);
	ObjEnemy_SetDamageRate(objBoss, 20, 20);
	wait(60);
	loop(3){
	let random = rand(0, 360);
		ascent(i in 0..14){
			ascent(j in 0..12){
			let obj = CreateShotA2(BossX, BossY, 0.9, random+(j*360/12)+(i*2), 0.01, 50, FIRE_GRAY, 5);
			ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
			}
			SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 70);
			wait(2);
		}
		ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2+rand(-100,100),100,5,4);
		wait(20);
		ascent(i in 0..14){
			ascent(j in 0..12){
			let obj = CreateShotA2(BossX, BossY, 0.9, random+(j*360/12)-(i*2), 0.01, 50, FIRE_GRAY, 5);
			ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
			}
			SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 70);
			wait(2);
		}
		ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2+rand(-100,100),100,5,4);
		wait(30);
	}
		//wait(30);
	}
}

task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
    Obj_Delete(objBoss);
	wait(1);
	SetCommonData("deathsound",1);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 
