#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Miyako_UltraNonSpell06"]
#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);
	ObjEnemy_Regist(bossObj);
	SetCommonData("bossAURA",2);
	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",64,64,255,75);wait(75);SE(se_enep3);
	MakeExplosionA1(bossObj,"SAKURA",64,64,255);
	attack=1;damage=1;TEtama;
	while(ObjEnemy_GetInfo(bossObj, INFO_LIFE) > 0){
		TBullet;wait(180);}}

task TBullet{
	let r = rand(0,60);
	SE(se_tan2);
	ascent(ang in 0..6){
		let obj1 = CreateShotA1(bossX,bossY,2,ang*60+r,380,0);
		ObjShot_SetSpellResist(obj1,true);
		bulletManage(obj1);Shot(obj1);
		effect(obj1);reflect(obj1);}
	wait(120);
	ascent(i in 0..60){
		CreateShotA1(bossX,bossY,0.5,i*6,334,0);}
		
	task bulletManage(object){
		let move = 0;
		while(!Obj_IsDeleted(object)){
			ObjRender_SetAngleZ(object,15*sin(move));
			move+=0.6;yield;}}

	task Shot(object){
		let a; let b; let del = 0;
		ShotAura(object,64,64,255);
		while(ObjMove_GetX(object) > 0 && ObjMove_GetX(object) < 384 && ObjMove_GetY(object) > 0 && ObjMove_GetY(object) < 448){
			a = CreateShotA1(ObjMove_GetX(object),ObjMove_GetY(object),8,ObjMove_GetAngle(object)+143,334,0);
			b = CreateShotA1(ObjMove_GetX(object),ObjMove_GetY(object),8,ObjMove_GetAngle(object)-143,334,0);
			ObjShot_SetDeleteFrame(a,del); ObjShot_SetDeleteFrame(b,del);
		del+=2;wait(4);SE(se_tan2);}
		SE(se_kira2);}
	
	task effect(object){
		while(!Obj_IsDeleted(object)){
			ShotAura(object,64,64,255);
			wait(3);}}}

	task reflect(object){
	while(!Obj_IsDeleted(object)){
	if(ObjMove_GetX(object) <= 0){
		ascent(i in 0..15){CreateShotA1(ObjMove_GetX(object),ObjMove_GetY(object),0.5,i*24,334,0);}break;}
	if(ObjMove_GetX(object) >= GetStgFrameWidth){
		ascent(i in 0..15){CreateShotA1(ObjMove_GetX(object),ObjMove_GetY(object),0.5,i*24,334,0);}break;}
	if(ObjMove_GetY(object) <= 0){
		ascent(i in 0..15){CreateShotA1(ObjMove_GetX(object),ObjMove_GetY(object),0.5,i*24,334,0);}break;}
	if(ObjMove_GetY(object) >= GetStgFrameHeight){
		ascent(i in 0..15){CreateShotA1(ObjMove_GetX(object),ObjMove_GetY(object),0.5,i*24,334,0);}break;}
	yield;}}