#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["NS2"]
#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(2000);
     	}
	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);
	ascent(i in 0..12){
	let obj = Bat(BossX+100*cos(i*360/12), BossY+100*sin(i*360/12), 300, [122, 15, 122], true);
	Shoot(obj,i);
	Shoot2(obj, i);
	Move(obj, i, random);
	}
	wait(180+(210*3)-60);
	Attack(60);
	loop(10){
	Concentrate(BossX, BossY, 0, 4, 3, 0.6, "Cherry", 150, -2, [125, 15, 125]);
	Concentrate(BossX, BossY, 0, 4, 3, 0.6, "Cherry", 150, 2, [255, 255, 255]);
	wait(6);
	}
	ascent(j in 0..5){
		ascent(i in 0..32){
		let obj = CreateShotA2(BossX, BossY, 4, i*360/32+j*360/64, -0.05, 1, RICE_M_PURPLE, 2);
		ObjMove_AddPatternA2(obj, 50, 1+(j/2), NO_CHANGE, 0, 0, 5);
		}
	}
	wait(60);
}
	
	task Move(obj, i, random){
	let off = i*360/12;
		while(!Obj_IsDeleted(obj)){
		ObjMove_SetDestAtWeight(obj, BossX+100*cos(off), BossY+100*sin(off), 10, 4);
		yield;
		off+=random;
		}
	}
	
	task Shoot2(obj, i){
	wait(180);
		while(!Obj_IsDeleted(obj)){
		ascent(i in 0..2){
		if(Obj_IsDeleted(obj)){break;}
		CreateLooseLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 3, GetAngleToPlayer(obj), 200, 25, LASER_PURPLE, 5);
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/laser2.wav", 60);
		wait(210);
		}
		ascent(j in 0..2){
		if(Obj_IsDeleted(obj)){break;}
		CreateLooseLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 3, GetAngleToPlayer(obj)+i*360/12, 200, 25, LASER_PURPLE, 5);
		CreateLooseLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 3, GetAngleToPlayer(obj)+i*360/12+180, 200, 25, LASER_PURPLE, 5);
		if(j == 1){ObjEnemy_SetLife(obj, 5);}
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/laser2.wav", 60);
		wait(210);
		}
		}
	}
	
	
	task Shoot(obj, i){
	wait(60+(i+5));
		while(!Obj_IsDeleted(obj)){
		ascent(j in 0..6){
		CreateShotB2(ObjMove_GetX(obj), ObjMove_GetY(obj), -3+i/2, -1+(j/20), 0, 0.02, 5, 5, DOT, 10);
		}
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 60);
		wait(32);
		}
	}
}

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