#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Miyako_NonSpell09"]
#include"./../../Functions/Effects/Effects.txt"
#include"./LoadGraphics.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);
	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{
	SetCommonData("Non9Effect",1);}

function MyStageID{ return GetCommonData("Main Stage Script ID", 0); }

task mainTask{
	let b = 0;
	loop(61){
		Set2DCameraRatioX(b);
		b+=1/60;yield;}
	ObjMove_SetDestAtWeight(bossObj,CenterX,CenterY,7,6);wait(60);SE(se_ch);
		MakeConcentrationB1(bossObj,"SAKURA",64,64,255,120);
		MakeConcentrationB1(bossObj,"SAKURA",64,255,64,120);
		MakeConcentrationB1(bossObj,"SAKURA",255,64,64,120);
		wait(120);SE(se_enep3);
		MakeExplosionA1(bossObj,"SAKURA",64,64,255);
		MakeExplosionA1(bossObj,"SAKURA",64,255,64);
		MakeExplosionA1(bossObj,"SAKURA",255,64,64);
	attack=1;TEtama;wait(3);
	NotifyEvent(MyStageID, EV_USER_STAGE, NULL);
	TLantern(255,64,64,0);
	TLantern(64,255,64,120);
	TLantern(64,64,255,240);}

task TLantern(r,g,b,vel){
	let v = 0;
	let s = CreateShotA1(bossX,bossY,0,0,1,0);
	ObjShot_SetIntersectionEnable(s,false);
	ObjShot_SetSpellResist(s,true);
	Obj_SetVisible(s,false);
	ascent(ang in 0..3){
		let obj = CreateShotA1(bossX,bossY,0,ang*120,380,0);
		ObjShot_SetAutoDelete(obj,false);
		ObjShot_SetSpellResist(obj,true);
		bulletManage(obj,ang*120);Shot(obj);}
		
		while(ObjEnemy_GetInfo(bossObj, INFO_LIFE) > 0){
			ObjMove_SetPosition(s,bossX+v*sin(vel),bossY+v*cos(vel));
			if(v > 200){v = 200;}
			v+=0.6; vel+=0.5; yield;}

	task bulletManage(object,angle){
		let rad = 0;
		while(ObjEnemy_GetInfo(bossObj, INFO_LIFE) > 0){
			let x = ObjMove_GetX(s);
			let y = ObjMove_GetY(s);
			ObjMove_SetPosition(object,x+rad*sin(angle),y+rad*cos(angle));
			ObjRender_SetAngleZ(object,15*sin(angle));
			if(rad > 60){rad = 60;}
			angle+=3; rad+=0.5; yield;}}

	task Shot(object){
		let ang = 0;
		wait(360);damage=1;
		while(!Obj_IsDeleted(object)){
			let x = ObjMove_GetX(object);
			let y = ObjMove_GetY(object);
			let angle = ObjMove_GetAngle(object);
				let a = CreateShotA1(x,y,0,angle+ang,rand(331,338),30);
				speedVEL(a);
			ang+=5; wait(8);SE(se_tan2);}
		task speedVEL(obj){
			wait(120);
			loop(30){
				ObjMove_SetSpeed(obj,ObjMove_GetSpeed(obj)+0.05);
			yield;}}}}