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

let objBoss;

let BossX; 
let BossY;

@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	HitSound(objBoss, 80, 450);
	EnemyMarker(objBoss);
	DamageReduction(objBoss, 0);
	DrawName("Aunn Komano", [40,140,90], 12.7);
	MagicRing(objBoss,true);
	RenderCharacter(objBoss);
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2.85, 10, 4);
	
	if(GetCommonData("IsStage", false)==false){
	StageBackground;
	}
	
	mainTask;
	end;
} 

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

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

@Finalize {
} 

task mainTask { 
wait(90);
Pattern;
}

task Pattern{
loop{
Attack(6*16);
ascent(i in 0..16){
	ascent(j in 0..16){
	let obj = CreateShotA2(BossX+25*cos(j*360/16+i*4), BossY+25*sin(j*360/16+i*4), 2, j*360/16+i*7, -0.07, 0,  89, 5);
	Redirect(obj, j*360/16, i, j*360/16);
	}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 80);
	wait(6);
}
Attack(6*16);
descent(i in 0..16){
	ascent(j in 0..16){
	let obj = CreateShotA2(BossX+25*cos(j*360/16+i*4), BossY+25*sin(j*360/16+i*4), 2, j*360/16+i*7, -0.07, 0,  84, 5);
	Redirect(obj, j*360/16-180, i, j*360/16);
	}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 80);
	wait(6);
}
ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+rand(-50, 50), GetStgFrameHeight/4+rand(-25, 25), 15, 3);
}


task Redirect(obj, off, i, off2){
let ang = ObjMove_GetAngle(obj);
wait(60-i);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 60);
ObjMove_AddPatternA2(obj, 0, 2, off2+22.5, -0.02, 0, 0);
wait(60);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 60);
ObjMove_AddPatternA2(obj, 0, 2, ang+off, 0.01, 0, 10);
}

}

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