#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Miyako_NonSpell03"]
#include"./../../Functions/Effects/Effects.txt"
#include"./LoadSounds.txt"

let bossObj;
let bossX;
let bossY;
let damage = 0;
#include"./MiyakoDrawBoss.txt"

@Initialize{	
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	SetCommonData("ForceLifebar",0);
	ObjEnemy_Regist(bossObj);
	SetAutoDeleteObject(true);
	LoadShotData;
	animateBossM;
	TEnemyMarker;
	mainTask;
	TEnd;}

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(1000);}
	case(EV_REQUEST_TIMER){SetScriptResult(50);}}

@MainLoop{
	bossX = ObjMove_GetX(bossObj);
	bossY = ObjMove_GetY(bossObj);

	if(damage==0){ObjEnemy_SetDamageRate(bossObj, 0, 0);}
	if(damage==1){ObjEnemy_SetDamageRate(bossObj, 30, 30);}

	ObjEnemy_SetIntersectionCircleToShot(bossObj,bossX,bossY,24);
	ObjEnemy_SetIntersectionCircleToPlayer(bossObj,bossX,bossY,32);
	yield;}

@Finalize{}

task mainTask{
	ObjMove_SetDestAtWeight(bossObj,CenterX,CenterY-90,7,4);wait(60);SE(se_ch2);
	MakeConcentrationB1(bossObj,"SAKURA",255,255,64,75);wait(70);SE(se_enep3);
	MakeExplosionA1(bossObj,"SAKURA",255,255,64);
	TEtama;
	damage=1;attack=1;TFire;wait(90);
	while(!Obj_IsDeleted(bossObj)){
		TBullet;wait(90);}}

task TFire{
	let r;
	while(ObjEnemy_GetInfo(bossObj, INFO_LIFE) > 0){
		r = rand(0,9);
		loop(5){
			ascent(i in 0..45){
				CreateShotA2(bossX,bossY,5,i*9+r,-0.1,1,337,10);}
				SE(se_kira);
			wait(10);}
		wait(20);}}

task TBullet{
	let angle = 0;
	let move = 0;
	SE(se_tan2);
		let obj1 = CreateShotA1(bossX+20,bossY,3,GetAngleToPlayer(bossObj),380,0);
		let obj2 = CreateShotA1(bossX+20,bossY,3,GetAngleToPlayer(bossObj)+30,380,0);
		let obj3 = CreateShotA1(bossX+20,bossY,3,GetAngleToPlayer(bossObj)-30,380,0);
		ObjShot_SetSpellResist(obj1,true);
		ObjShot_SetSpellResist(obj2,true);
		ObjShot_SetSpellResist(obj3,true);
		bulletManage(obj1);
		bulletManage(obj2);
		bulletManage(obj3);
		effect(obj1);
		effect(obj2);
		effect(obj3);

	task effect(object){
		while(!Obj_IsDeleted(object)){
			ShotAura(object,255,255,64);wait(3);}}
	task bulletManage(object){
		while(!Obj_IsDeleted(object)){
			ObjRender_SetAngleZ(object,15*sin(move));
			move+=3;yield;}}}