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

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

@Initialize{	
	objPlayer = GetPlayerObjectID();
	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,7,6);wait(60);SE(se_ch2);
	MakeConcentrationB1(bossObj,"SAKURA",255,64,255,75);wait(75);SE(se_enep3);
	MakeExplosionA1(bossObj,"SAKURA",255,64,255);attack=1;TEtama;
	TBullet;wait(450);damage=1;}

task TBullet{
	SE(se_tan2);
	ascent(ang in 0..7){SE(se_ophide);
		let obj1 = CreateShotA1(bossX+20,bossY,2,ang*360/7,380,0);
		ObjShot_SetSpellResist(obj1,true);
		bulletManage(obj1);Shot(obj1);
		effect(obj1);wait(360/14);}
		wait(45);SetCommonData("shot",1);

	task bulletManage(object){let move = 0;let trig = 0;
		while(ObjEnemy_GetInfo(bossObj, INFO_LIFE) > 0){
			ObjMove_SetDestAtWeight(object,GetPlayerX+(360/7)*sin(trig),GetPlayerY-(360/7)*cos(trig),2,3);
			ObjRender_SetAngleZ(object,15*sin(move));
			move+=3;trig+=2;yield;}}

	task Shot(object){let ang = 0;
		while(GetCommonData("shot",0)==0){yield;}
		while(!Obj_IsDeleted(object)){
			SE(se_tan2);
			let x = ObjMove_GetX(object);
			let y = ObjMove_GetY(object);
			let shot = CreateShotA1(x,y,5,GetAngleToPlayer(object)+180+ang,333,10);
			reflect(shot);wait(18);}}
	task effect(object){while(!Obj_IsDeleted(object)){ShotAura(object,255,64,255);wait(10);}}

	task reflect(object){
	while(!Obj_IsDeleted(object)){
	if(ObjMove_GetY(object) <= 0){
		ObjMove_SetSpeed(object,1);
		ObjMove_SetAngle(object,90);
		Obj_SetRenderPriorityI(object,51);break;}
	if(ObjMove_GetY(object) >= GetStgFrameHeight){
		ObjMove_SetSpeed(object,1);
		ObjMove_SetAngle(object,270);
		Obj_SetRenderPriorityI(object,51);break;}
	if(ObjMove_GetX(object) <= 0){
		ObjMove_SetSpeed(object,1);
		ObjMove_SetAngle(object,0);
		Obj_SetRenderPriorityI(object,51);break;}
	if(ObjMove_GetX(object) >= GetStgFrameWidth){
		ObjMove_SetSpeed(object,1);
		ObjMove_SetAngle(object,180);
		Obj_SetRenderPriorityI(object,51);break;}
	yield;}}}