#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Miyako_NonSpell08"]
#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);
	ObjEnemy_Regist(bossObj);
	SetAutoDeleteObject(true);
	SetCommonData("bossAURA",3);
	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,24);
	yield;}

@Finalize{}

task mainTask{
	ObjMove_SetDestAtWeight(bossObj,CenterX,CenterY,7,6);wait(60);SE(se_ch2);
	MakeConcentrationB1(bossObj,"SAKURA",255,255,255,75);wait(75);SE(se_enep3);
	MakeExplosionA1(bossObj,"SAKURA",255,255,255);
	attack=1;TEtama;
	TBullet;wait(180);damage=1;}

task TBullet{
	SE(se_tan2);
	ascent(ang in 0..8){
		let obj1 = CreateShotA1(bossX+20,bossY,2,ang*45,380,0);
		ObjShot_SetSpellResist(obj1,true);
		bulletManage(obj1);effect(obj1);Shot(obj1);Bullets(obj1);}
		wait(180);SE(se_lazer);

	task bulletManage(object){let move = 0;let trig = 0;
			let angle = ObjMove_GetAngle(object);
		while(!Obj_IsDeleted(bossObj)){
			ObjMove_SetDestAtWeight(object,bossX+240*sin(angle+trig),bossY-240*cos(angle+trig),3,3.5);
			ObjRender_SetAngleZ(object,15*sin(move));
			move+=3;trig+=1;yield;}}

	task Shot(object){
		let laser = CreateStraightLaserA1(bossX,bossY,0,130,10,3000,1016,120);
		while(!Obj_IsDeleted(object)){
		let x = ObjMove_GetX(object);
		let y = ObjMove_GetY(object);
		let angle = GetPointToPointAngle(x,y,bossX,bossY);
			ObjStLaser_SetAngle(laser,angle+110);
			ObjMove_SetPosition(laser,x,y);
			yield;}}
	task Bullets(object){
		wait(120);
		let x; let y; let angle;
		while(!Obj_IsDeleted(object)){
			SE(se_tan2);
			x = ObjMove_GetX(object);
			y = ObjMove_GetY(object);
			angle = atan2(bossY-y,bossX-x);
			let shot = CreateShotA2(x,y,0.1,angle,0.01,2,331,0);
			ObjShot_SetDeleteFrame(shot,180);
			ascent(i in -3..4){
				CreateShotA1(x,y,2,angle+180+i*10,331,0);}
		wait(rand(6,12));}}
	task effect(object){while(!Obj_IsDeleted(object)){
		ShotAura(object,255,255,255);wait(3);}}}

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