#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Banquet Sign \"Perfect Festival\" - Ultra"]

#include"./../../Functions/Effects/Effects.txt"
#include"./LoadGraphics.txt"
#include"./LoadSounds.txt"
#include"./Cutin.txt"

let bossObj;
let bossX;
let bossY;
let damage = 0;

#include"./MiyakoDrawBoss.txt"

@Initialize{	
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	SetAutoDeleteObject(true);
	ObjEnemy_Regist(bossObj);
	LoadShotData;
	animateBossT;
	TEnemyMarker;
	mainTask;
	TEnd;}

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(500);}
	case(EV_REQUEST_TIMER){SetScriptResult(50);}
	case(EV_REQUEST_SPELL_SCORE){SetScriptResult(1000000);}
	case(EV_START_BOSS_SPELL){
		let path = GetCurrentScriptDirectory ~ "./../../System/Miyako_System_MagicCircle.txt";
		let id = LoadScript(path);
		StartScript(id);yield;}}

@MainLoop{
	bossX = ObjMove_GetX(bossObj);
	bossY = ObjMove_GetY(bossObj);

	if(damage==0){ObjEnemy_SetDamageRate(bossObj, 0, 0);}
	if(damage==1){ObjEnemy_SetDamageRate(bossObj, 10, 10);}

	ObjEnemy_SetIntersectionCircleToShot(bossObj,bossX,bossY,24);
	ObjEnemy_SetIntersectionCircleToPlayer(bossObj,bossX,bossY,32);
	yield;}

@Finalize{}

task mainTask{
	ObjMove_SetDestAtWeight(bossObj,CenterX,CenterY-120,5,3);
	TEtama;loop(90){
	PlayMusic(GetAreaCommonData("MUSIC","Song",0));yield;}SE(se_spell);
	if(GetCommonData("Replay",0) == 2){
	ObjCutin_SetSpellcardS4("Banquet Sign \"Perfect Festival\"", cutin2, NAZRIN, 240, 104, 104);
	ObjCutin_LaunchS3(MOKOU, cutin2, "Practice");}
	else{
	ObjCutin_SetSpellcardS4("Banquet Sign \"Perfect Festival\"", cutin2, NAZRIN, 240, 104, 104);
	ObjCutin_LaunchS3(NAZRIN, cutin2, "Ultra");}
	TSpellBGMID;SetCommonData("BG",1);
		wait(150);damage=1;attack=1;SE(se_ch2);
		MakeConcentrationB1(bossObj,"HEART",255,25,25,75);
		wait(80);SE(se_enep3);
		MakeExplosionA1(bossObj,"HEART",255,25,25);
		TBanquet(2,180,-0.8);wait(240);SE(se_ch2);
		MakeConcentrationB1(bossObj,"HEART",255,25,25,75);
		wait(80);SE(se_enep3);
		MakeExplosionA1(bossObj,"HEART",255,25,25);
	TBanquet(1,0,0.8);
	return;}

task TBanquet(sp,ang,vel){
	let main = CreateShotA1(bossX,bossY,sp,ang,827,30);
	ObjShot_SetSpellResist(main,true);
	ObjMove_SetAngularVelocity(main,vel);

	ascent(i in 0..15){
		let a = CreateShotA1(bossX,bossY,2,i*24,793,30);
		ObjShot_SetSpellResist(a,true);
		tManage(a,ObjMove_GetAngle(a)); tShot(a);}
	wait(30);SE(se_tan);
	task tManage(obj,angle){let r = 0;let w = 0;
		while(ObjEnemy_GetInfo(bossObj,INFO_LIFE) > 0){
			ObjMove_SetPosition(obj,ObjMove_GetX(main)+r*cos(w+angle),ObjMove_GetY(main)+r*sin(w+angle));
			if(r>=60){r=60;}
			r+=1;w+=2;yield;}}
	task tShot(obj){wait(60);
		while(!Obj_IsDeleted(obj)){SE(se_kira);
			CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),1,ObjMove_GetAngle(obj),rand(871,878),15);
		wait(20);}}}