#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["NS3"]
#Text["Baaaaaaaaaap"]
#System["./default_system/Default_System.txt"]
#include "./default_system/MS_Index.txt"


let BossX;
let BossY;
let objBoss;



@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	HitSound(objBoss, 75, 450);
	RenderCharacter(objBoss);
	
	if(GetCommonData("IsStage", false)==true){
	MagicRing(objBoss,false);
	}
	else{
	MagicRing(objBoss,true);
	SetCommonData("BossAlpha", 255);
	StageBackground;
	}
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/4, 10, 4);
	mainTask;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(4000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(105);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
}

let appear = false; 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);

	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),21);
	yield;
} 

@Finalize {
} 

task mainTask { 
wait(100);
loop{
let random = rand(-2, 2);
ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+rand(-75, 75), GetStgFrameHeight/4, 10, 4);
	ascent(i in 0..8){
	let obj = Bat(0+rand(0,150), GetStgFrameHeight+10, 100, [122, 15, 122], true);
	let obj2 = Bat(GetStgFrameWidth-rand(0,150), GetStgFrameHeight+10, 100, [122, 15, 122], true);
	Move(obj2, -1);
	Move(obj, 1);
	Shoot(obj, i);
	Shoot(obj2, i);
	wait(10);
	}
	wait(260);
	ascent(i in 0..32){
		ascent(j in 0..3){
		CreateShotA2(BossX, BossY, 4-i/8, GetAngleToPlayer(objBoss)-54+i*4+j*360/3, 0.01, 10, RICE_M_PURPLE, 5);
		}
	yield;
	}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 60);
	ascent(i in 0..32){
		ascent(j in 0..3){
		CreateShotA2(BossX, BossY, 4-i/8, GetAngleToPlayer(objBoss)+54-i*4+j*360/3, 0.01, 10, RICE_M_PURPLE, 5);
		}
	yield;
	}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 60);
	wait(60);
	
}

	task Move(obj, mult){
	ObjMove_SetAngle(obj, 270);
	ObjMove_SetSpeed(obj, 3);
	wait(30);
	ObjMove_SetAngularVelocity(obj, 1*mult);
	wait(60);
	ObjMove_SetAngularVelocity(obj, 0);
	wait(360);
	ObjEnemy_SetLife(obj, 5); //basically death
	}
	
	task Shoot(obj, i){
	wait(60+(i+5));
		while(!Obj_IsDeleted(obj)){
		ascent(j in 0..3){
		CreateShotA2(ObjMove_GetX(obj), ObjMove_GetY(obj), 1, 90-22.5+j*22.5, 0.01, 10, DOT, 10);
		}
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 60);
		wait(45);
		}
	}
}

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