#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Miyako_UltraNonSpell01"]

#include"./../../Functions/Effects/Effects.txt"
#include"./LoadSounds.txt"

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

@Initialize{
	SetCommonData("Music",1);
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	SetCommonData("ForceLifebar",0);
	SetCommonData("bossAURA",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-120,7,6);wait(60);SE(se_ch2);
	MakeConcentrationB1(bossObj,"SAKURA",255,64,64,75);wait(70);SE(se_enep3);
	MakeExplosionA1(bossObj,"SAKURA",255,64,64);
	TEtama;
	damage=1;attack=1;
	TBullet;wait(240);
	while(ObjEnemy_GetInfo(bossObj,INFO_LIFE) > 0){wait(240);
		ObjMove_SetDestAtWeight(bossObj,rand(100,382-100),rand(60,120),5,1);}}

task TBullet{
	let m = 0;
	let ang = 0;
	let move = 0;
		let obj1 = CreateShotA1(bossX+20,bossY,3,210,380,0);
		ObjShot_SetSpellResist(obj1,true);
		bulletManage(obj1);effect(obj1);
		
	while(ObjEnemy_GetInfo(bossObj,INFO_LIFE) > 0){
		shot(ang+m,13,3);SE(se_tan);
	ang+=23.5;m++;wait(1);}
	
	task shot(ang,q,int){ loop(q){
		if(ObjEnemy_GetInfo(bossObj,INFO_LIFE) > 0){
			CreateShotA2(ObjMove_GetX(obj1),ObjMove_GetY(obj1),3,ang,0.1,4,332,15);}
		wait(int);}}

	task effect(object){
		while(ObjEnemy_GetInfo(bossObj,INFO_LIFE) > 0){
			ShotAura(object,255,64,64);wait(3);}}
	task bulletManage(object){let r = 0;
		while(ObjEnemy_GetInfo(bossObj,INFO_LIFE) > 0){
			ObjMove_SetPosition(object,bossX+r*cos(move),bossY+r*sin(move));
			ObjRender_SetAngleZ(object,15*sin(move));
			if(r>=60){r=60;}
			move+=2;r++;yield;}
		Obj_Delete(object);}}