#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Miyako_NonSpell05"]
#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);
	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,255,255,75);wait(75);SE(se_enep3);
	MakeExplosionA1(bossObj,"SAKURA",64,255,255);
	attack=1;TEtama;
	TEffect;wait(60);TStar;}

task TStar{
	let obj1 = CreateShotA1(bossX,bossY,0,0,380,0);
	let obj2 = CreateShotA1(bossX,bossY,0,0,380,0);
	let obj3 = CreateShotA1(bossX,bossY,0,0,380,0);
	let obj4 = CreateShotA1(bossX,bossY,0,0,380,0);
	let obj5 = CreateShotA1(bossX,bossY,0,0,380,0);
	let listObj = [obj1,obj2,obj3,obj4,obj5];
	TLanternMove;
	
	ascent(i in 0..length(listObj)){
		ObjShot_SetSpellResist(listObj[i],true);
		ObjShot_SetAutoDelete(listObj[i],false);
		bulletManage2(listObj[i]);effect(listObj[i]);}
	
	task TLanternMove{
		let move = 0;
		let r = 500;
		while(ObjEnemy_GetInfo(bossObj,INFO_LIFE) > 0){
			ObjMove_SetPosition(obj1,GetPlayerX+r*sin(move),GetPlayerY+r*cos(move));
			ObjMove_SetPosition(obj2,GetPlayerX+r*sin(move+72*1),GetPlayerY+r*cos(move+72*1));
			ObjMove_SetPosition(obj3,GetPlayerX+r*sin(move+72*2),GetPlayerY+r*cos(move+72*2));
			ObjMove_SetPosition(obj4,GetPlayerX+r*sin(move+72*3),GetPlayerY+r*cos(move+72*3));
			ObjMove_SetPosition(obj5,GetPlayerX+r*sin(move+72*4),GetPlayerY+r*cos(move+72*4));
			if(r <= 150){r = 150;}
		move+=2;r-=2;yield;}}

	wait(120);
	let laser1 = CreateStraightLaserA1(0,0,0,270,20,50*60,1024,60);
	let laser2 = CreateStraightLaserA1(0,0,0,270,20,50*60,1024,60);
	let laser3 = CreateStraightLaserA1(0,0,0,270,20,50*60,1024,60);
	let laser4 = CreateStraightLaserA1(0,0,0,270,20,50*60,1024,60);
	let laser5 = CreateStraightLaserA1(0,0,0,270,20,50*60,1024,60);
	ObjShot_SetAutoDelete(laser1,false);
	ObjShot_SetAutoDelete(laser2,false);
	ObjShot_SetAutoDelete(laser3,false);
	ObjShot_SetAutoDelete(laser4,false);
	ObjShot_SetAutoDelete(laser5,false);
	TLaserManage;
	wait(60);SE(se_lazer2);
	SE(se_ch2);
	MakeConcentrationB1(bossObj,"SAKURA",64,255,255,75);
	wait(50);damage=1;
	
	let circle = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(circle);
	ObjEnemy_SetLife(circle,1);
	ObjPrim_SetTexture(circle, halo);
	Obj_SetRenderPriorityI(circle,50);
	ObjRender_SetAlpha(circle,200);
	ObjRender_SetPosition(circle,bossX,bossY,0);
	ObjRender_SetBlendType(circle,BLEND_ADD_ARGB);
	ObjSprite2D_SetSourceRect(circle,0,0,256,256);
	ObjSprite2D_SetDestCenter(circle);
	ObjRender_SetScaleXYZ(circle,0.6,0.6,0);
	ObjRender_SetColor(circle,64,255,255);
	
	wait(30);
	ring(circle);
	while(ObjEnemy_GetInfo(bossObj,INFO_LIFE) > 0){
		loop(90){
			ObjMove_SetDestAtWeight(circle,ObjMove_GetX(obj1),ObjMove_GetY(obj1),5,12);
			yield;}
		loop(90){
			ObjMove_SetDestAtWeight(circle,ObjMove_GetX(obj3),ObjMove_GetY(obj3),5,12);
			yield;}
		loop(90){
			ObjMove_SetDestAtWeight(circle,ObjMove_GetX(obj5),ObjMove_GetY(obj5),5,12);
			yield;}
		loop(90){
			ObjMove_SetDestAtWeight(circle,ObjMove_GetX(obj2),ObjMove_GetY(obj2),5,12);
			yield;}
		loop(90){
			ObjMove_SetDestAtWeight(circle,ObjMove_GetX(obj4),ObjMove_GetY(obj4),5,12);
			yield;}}
	
	task TLaserManage{
		while(ObjEnemy_GetInfo(bossObj,INFO_LIFE) > 0){
			ObjMove_SetPosition(laser1,ObjMove_GetX(obj1),ObjMove_GetY(obj1));
			ObjMove_SetPosition(laser2,ObjMove_GetX(obj2),ObjMove_GetY(obj2));
			ObjMove_SetPosition(laser3,ObjMove_GetX(obj3),ObjMove_GetY(obj3));
			ObjMove_SetPosition(laser4,ObjMove_GetX(obj4),ObjMove_GetY(obj4));
			ObjMove_SetPosition(laser5,ObjMove_GetX(obj5),ObjMove_GetY(obj5));
			ObjStLaser_SetAngle(laser1,110+GetPointToPointAngle(ObjMove_GetX(obj1),ObjMove_GetY(obj1),ObjMove_GetX(obj2),ObjMove_GetY(obj2)));
			ObjStLaser_SetAngle(laser2,110+GetPointToPointAngle(ObjMove_GetX(obj2),ObjMove_GetY(obj2),ObjMove_GetX(obj3),ObjMove_GetY(obj3)));
			ObjStLaser_SetAngle(laser3,110+GetPointToPointAngle(ObjMove_GetX(obj3),ObjMove_GetY(obj3),ObjMove_GetX(obj4),ObjMove_GetY(obj4)));
			ObjStLaser_SetAngle(laser4,110+GetPointToPointAngle(ObjMove_GetX(obj4),ObjMove_GetY(obj4),ObjMove_GetX(obj5),ObjMove_GetY(obj5)));
			ObjStLaser_SetAngle(laser5,110+GetPointToPointAngle(ObjMove_GetX(obj5),ObjMove_GetY(obj5),ObjMove_GetX(obj1),ObjMove_GetY(obj1)));
		yield;}}}

task ring(o){ wait(30);
	while(!Obj_IsDeleted(o)){
		SE(se_tan2);
		ascent(i in 0..30){
		ascent(a in 0..2){
			CreateShotA1(ObjMove_GetX(o),ObjMove_GetY(o),1+a/2,i*12,335,0);}}
		wait(90);}}

function GetPointToPointAngle(x1,y1,x2,y2){	//Helepolis
	let dir = atan2(y1-y2,x1-x2);
	return dir;}

task TEffect{
	SE(se_tan2);
	ascent(i in 0..5){
		let obj1 = CreateShotA1(bossX,bossY,5,-200+rand(40,60)*i,380,0);
		ObjShot_SetSpellResist(obj1,true);
		bulletManage(obj1);effect(obj1);}}
		
task bulletManage(object){
	let move = 0;
	loop(90){
		ObjRender_SetAngleZ(object,15*sin(move));
		move+=3;yield;}
	Obj_Delete(object);}
	
task bulletManage2(object){
	let move = 0;
	while(!Obj_IsDeleted(object)){
		ObjRender_SetAngleZ(object,15*sin(move));
		move+=3;yield;}
	Obj_Delete(object);}

task effect(object){
	while(!Obj_IsDeleted(object)){
		ShotAura(object,64,255,255);
		wait(3);}}