#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Musical Present \"White Gold\" - 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);
	SetCommonData("ForceLifebar",0);
	SetCommonData("explosion",0);
	SetAutoDeleteObject(true);
	ObjEnemy_Regist(bossObj);
	LoadShotData;
	animateBossT;
	TEnemyMarker;
	mainTask;
	TEnd;}

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(500);}
	case(EV_REQUEST_TIMER){SetScriptResult(60);}
	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{
	musicRestartEnable(GetAreaCommonData("MUSIC","Song",0),1);
	PlayMusic(GetAreaCommonData("MUSIC","Song",0));}

task mainTask{wait(30);
	ObjMove_SetDestAtWeight(bossObj,CenterX,CenterY-120,5,3);
	TEtama;wait(90);SE(se_spell);
	if(GetCommonData("Replay",0) == 2){
	ObjCutin_SetSpellcardS4("Musical Present \"White Gold\"", cutin2, NAZRIN, 240, 104, 104);
	ObjCutin_LaunchS3(MOKOU, cutin2, "Practice");}
	else{
	ObjCutin_SetSpellcardS4("Musical Present \"White Gold\"", cutin2, NAZRIN, 240, 104, 104);
	ObjCutin_LaunchS3(NAZRIN, cutin2, "Ultra");}
	TSpellBGMID;SetCommonData("BG",1);
	
	while(ObjEnemy_GetInfo(bossObj,INFO_LIFE) > 0){
	ObjMove_SetDestAtWeight(bossObj,CenterX,120,8,1);
	wait(120);damage=1;Heart(4);wait(120);
		let r = rand(-20,0);
		ascent(i in 0..24){
			let s = CreateShotA2(bossX,bossY,5,r+i*15,-0.1,0,737,30);
			ObjShot_SetSpellResist(s,true);
			laser(s);wait(3);}
	ObjMove_SetDestAtWeight(bossObj,CenterX-60,150,8,1);
	wait(180);Heart(0);wait(120);
	ObjMove_SetDestAtWeight(bossObj,CenterX+60,150,8,1);
	wait(40);
		ascent(i in 0..24){
			let s = CreateShotA2(bossX,bossY,5,r+i*15,-0.1,0,737,30);
			ObjShot_SetSpellResist(s,true);
			laser(s);}
	wait(180);Heart(0);wait(20);
	ObjMove_SetDestAtWeight(bossObj,CenterX-60,150,8,1);
	wait(120);}
	
	task laser(obj){
		while(ObjMove_GetSpeed(obj) > 0){yield;}
		CreateStraightLaserA1(ObjMove_GetX(obj),ObjMove_GetY(obj),ObjMove_GetAngle(obj),550,10,120,1003,60);
		CreateStraightLaserA1(ObjMove_GetX(obj),ObjMove_GetY(obj),ObjMove_GetAngle(obj)+80,550,10,120,1003,60);
		CreateStraightLaserA1(ObjMove_GetX(obj),ObjMove_GetY(obj),ObjMove_GetAngle(obj)-80,550,10,120,1003,60);
		wait(60); SE(se_lazer2);
		wait(60); ObjShot_FadeDelete(obj);}}

task Heart(w){
	let gr = 19;
	SE(se_tan2);
	let obj = CreateShotA1(bossX,bossY-10,0,270,gr,10);
	wait(w);
	SE(se_tan2);
	let obj1 = CreateShotA1(bossX,bossY,2,255,gr,10);
	ObjMove_AddPatternA3(obj1,13,0,NO_CHANGE,0,0,0,NO_CHANGE);
	let obj2 = CreateShotA1(bossX,bossY,2,285,gr,10);
	ObjMove_AddPatternA3(obj2,13,0,NO_CHANGE,0,0,0,NO_CHANGE);
	wait(w);
	SE(se_tan2);
	let obj3 = CreateShotA1(bossX,bossY,2,240,gr,10);
	ObjMove_AddPatternA3(obj3,20,0,NO_CHANGE,0,0,0,NO_CHANGE);
	let obj4 = CreateShotA1(bossX,bossY,2,300,gr,10);
	ObjMove_AddPatternA3(obj4,20,0,NO_CHANGE,0,0,0,NO_CHANGE);
	wait(w);
	SE(se_tan2);
	let obj5 = CreateShotA1(bossX,bossY,2,225,gr,10);
	ObjMove_AddPatternA3(obj5,26,0,NO_CHANGE,0,0,0,NO_CHANGE);
	let obj6 = CreateShotA1(bossX,bossY,2,315,gr,10);
	ObjMove_AddPatternA3(obj6,26,0,NO_CHANGE,0,0,0,NO_CHANGE);
	wait(w);
	SE(se_tan2);
	let obj7 = CreateShotA1(bossX,bossY,2,210,gr,10);
	ObjMove_AddPatternA3(obj7,30,0,NO_CHANGE,0,0,0,NO_CHANGE);
	let obj8 = CreateShotA1(bossX,bossY,2,330,gr,10);
	ObjMove_AddPatternA3(obj8,30,0,NO_CHANGE,0,0,0,NO_CHANGE);
	wait(w);
	SE(se_tan2);
	let obj9 = CreateShotA1(bossX,bossY,2,195,gr,10);
	ObjMove_AddPatternA3(obj9,30,0,NO_CHANGE,0,0,0,NO_CHANGE);
	let obj10 = CreateShotA1(bossX,bossY,2,345,gr,10);
	ObjMove_AddPatternA3(obj10,30,0,NO_CHANGE,0,0,0,NO_CHANGE);
	wait(w);
	SE(se_tan2);
	let obj11 = CreateShotA1(bossX,bossY,2,180,gr,10);
	ObjMove_AddPatternA3(obj11,28,0,NO_CHANGE,0,0,0,NO_CHANGE);
	let obj12 = CreateShotA1(bossX,bossY,2,360,gr,10);
	ObjMove_AddPatternA3(obj12,28,0,NO_CHANGE,0,0,0,NO_CHANGE);
	wait(w);
	SE(se_tan2);
	let obj13 = CreateShotA1(bossX,bossY,2,165,gr,10);
	ObjMove_AddPatternA3(obj13,25,0,NO_CHANGE,0,0,0,NO_CHANGE);
	let obj14 = CreateShotA1(bossX,bossY,2,15,gr,10);
	ObjMove_AddPatternA3(obj14,25,0,NO_CHANGE,0,0,0,NO_CHANGE);
	wait(w);
	SE(se_tan2);
	let obj15 = CreateShotA1(bossX,bossY,2,148,gr,10);
	ObjMove_AddPatternA3(obj15,23,0,NO_CHANGE,0,0,0,NO_CHANGE);
	let obj16 = CreateShotA1(bossX,bossY,2,33,gr,10);
	ObjMove_AddPatternA3(obj16,23,0,NO_CHANGE,0,0,0,NO_CHANGE);
	wait(w);
	SE(se_tan2);
	let obj17 = CreateShotA1(bossX,bossY,2,131,gr,10);
	ObjMove_AddPatternA3(obj17,23,0,NO_CHANGE,0,0,0,NO_CHANGE);
	let obj18 = CreateShotA1(bossX,bossY,2,50,gr,10);
	ObjMove_AddPatternA3(obj18,23,0,NO_CHANGE,0,0,0,NO_CHANGE);
	wait(w);
	SE(se_tan2);
	let obj19 = CreateShotA1(bossX,bossY,2,114,gr,10);
	ObjMove_AddPatternA3(obj19,25,0,NO_CHANGE,0,0,0,NO_CHANGE);
	let obj20 = CreateShotA1(bossX,bossY,2,67,gr,10);
	ObjMove_AddPatternA3(obj20,25,0,NO_CHANGE,0,0,0,NO_CHANGE);
	wait(w);
	SE(se_tan2);
	let obj21 = CreateShotA1(bossX,bossY,2,100,gr,10);
	ObjMove_AddPatternA3(obj21,28,0,NO_CHANGE,0,0,0,NO_CHANGE);
	let obj22 = CreateShotA1(bossX,bossY,2,80,gr,10);
	ObjMove_AddPatternA3(obj22,28,0,NO_CHANGE,0,0,0,NO_CHANGE);
	wait(w);
	SE(se_tan2);
	let obj23 = CreateShotA1(bossX,bossY,2,90,gr,10);
	ObjMove_AddPatternA3(obj23,33,0,NO_CHANGE,0,0,0,NO_CHANGE);
	wait(30);
	SE(se_ch2);
	THeartExplosion;
	MakeConcentrationB1(bossObj,"SAKURA",255,55,55,70);
	MakeConcentrationB1(bossObj,"SAKURA",255,55,55,70);
	wait(60);
	SE(se_enep3);
	SetCommonData("explosion",1);
	MakeExplosionA1(bossObj,"SAKURA",255,55,55);

	task THeartExplosion{
	let angle2 = rand(0,360);
	let angle = 0;
	let asd = 2;
		loop(360){
		if(GetCommonData("explosion",1)){
		let g = 519;
		
		loop(10){
			if(!Obj_IsDeleted(obj)){let ob1 = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),asd,angle+angle2,g,10);TReflection(ob1);}
			if(!Obj_IsDeleted(obj1)){let ob2 = CreateShotA1(ObjMove_GetX(obj1),ObjMove_GetY(obj1),asd,angle+angle2,g,10);TReflection(ob2);}
			if(!Obj_IsDeleted(obj2)){let ob3 = CreateShotA1(ObjMove_GetX(obj2),ObjMove_GetY(obj2),asd,angle+angle2,g,10);TReflection(ob3);}
			if(!Obj_IsDeleted(obj3)){let ob4 = CreateShotA1(ObjMove_GetX(obj3),ObjMove_GetY(obj3),asd,angle+angle2,g,10);TReflection(ob4);}
			if(!Obj_IsDeleted(obj4)){let ob5 = CreateShotA1(ObjMove_GetX(obj4),ObjMove_GetY(obj4),asd,angle+angle2,g,10);TReflection(ob5);}
			if(!Obj_IsDeleted(obj5)){let ob6 = CreateShotA1(ObjMove_GetX(obj5),ObjMove_GetY(obj5),asd,angle+angle2,g,10);TReflection(ob6);}
			if(!Obj_IsDeleted(obj6)){let ob7 = CreateShotA1(ObjMove_GetX(obj6),ObjMove_GetY(obj6),asd,angle+angle2,g,10);TReflection(ob7);}
			if(!Obj_IsDeleted(obj7)){let ob8 = CreateShotA1(ObjMove_GetX(obj7),ObjMove_GetY(obj7),asd,angle+angle2,g,10);TReflection(ob8);}
			if(!Obj_IsDeleted(obj8)){let ob9 = CreateShotA1(ObjMove_GetX(obj8),ObjMove_GetY(obj8),asd,angle+angle2,g,10);TReflection(ob9);}
			if(!Obj_IsDeleted(obj9)){let ob10 = CreateShotA1(ObjMove_GetX(obj9),ObjMove_GetY(obj9),asd,angle+angle2,g,10);TReflection(ob10);}
			if(!Obj_IsDeleted(obj10)){let ob11 = CreateShotA1(ObjMove_GetX(obj10),ObjMove_GetY(obj10),asd,angle+angle2,g,10);TReflection(ob11);}
			if(!Obj_IsDeleted(obj11)){let ob12 = CreateShotA1(ObjMove_GetX(obj11),ObjMove_GetY(obj11),asd,angle+angle2,g,10);TReflection(ob12);}
			if(!Obj_IsDeleted(obj12)){let ob13 = CreateShotA1(ObjMove_GetX(obj12),ObjMove_GetY(obj12),asd,angle+angle2,g,10);TReflection(ob13);}
			if(!Obj_IsDeleted(obj13)){let ob14 = CreateShotA1(ObjMove_GetX(obj13),ObjMove_GetY(obj13),asd,angle+angle2,g,10);TReflection(ob14);}
			if(!Obj_IsDeleted(obj14)){let ob15 = CreateShotA1(ObjMove_GetX(obj14),ObjMove_GetY(obj14),asd,angle+angle2,g,10);TReflection(ob15);}
			if(!Obj_IsDeleted(obj15)){let ob16 = CreateShotA1(ObjMove_GetX(obj15),ObjMove_GetY(obj15),asd,angle+angle2,g,10);TReflection(ob16);}
			if(!Obj_IsDeleted(obj16)){let ob17 = CreateShotA1(ObjMove_GetX(obj16),ObjMove_GetY(obj16),asd,angle+angle2,g,10);TReflection(ob17);}
			if(!Obj_IsDeleted(obj17)){let ob18 = CreateShotA1(ObjMove_GetX(obj17),ObjMove_GetY(obj17),asd,angle+angle2,g,10);TReflection(ob18);}
			if(!Obj_IsDeleted(obj18)){let ob19 = CreateShotA1(ObjMove_GetX(obj18),ObjMove_GetY(obj18),asd,angle+angle2,g,10);TReflection(ob19);}
			if(!Obj_IsDeleted(obj19)){let ob20 = CreateShotA1(ObjMove_GetX(obj19),ObjMove_GetY(obj19),asd,angle+angle2,g,10);TReflection(ob20);}
			if(!Obj_IsDeleted(obj20)){let ob21 = CreateShotA1(ObjMove_GetX(obj20),ObjMove_GetY(obj20),asd,angle+angle2,g,10);TReflection(ob21);}
			if(!Obj_IsDeleted(obj21)){let ob22 = CreateShotA1(ObjMove_GetX(obj21),ObjMove_GetY(obj21),asd,angle+angle2,g,10);TReflection(ob22);}
			if(!Obj_IsDeleted(obj22)){let ob23 = CreateShotA1(ObjMove_GetX(obj22),ObjMove_GetY(obj22),asd,angle+angle2,g,10);TReflection(ob23);}
			if(!Obj_IsDeleted(obj23)){let ob24 = CreateShotA1(ObjMove_GetX(obj23),ObjMove_GetY(obj23),asd,angle+angle2,g,10);TReflection(ob24);}
			angle+=360/10;}angle2+=17;
		Obj_Delete(obj);
		Obj_Delete(obj1);
		Obj_Delete(obj2);
		Obj_Delete(obj3);
		Obj_Delete(obj4);
		Obj_Delete(obj5);
		Obj_Delete(obj6);
		Obj_Delete(obj7);
		Obj_Delete(obj8);
		Obj_Delete(obj9);
		Obj_Delete(obj10);
		Obj_Delete(obj11);
		Obj_Delete(obj12);
		Obj_Delete(obj13);
		Obj_Delete(obj14);
		Obj_Delete(obj15);
		Obj_Delete(obj16);
		Obj_Delete(obj17);
		Obj_Delete(obj18);
		Obj_Delete(obj19);
		Obj_Delete(obj20);
		Obj_Delete(obj21);
		Obj_Delete(obj22);
		Obj_Delete(obj23);
		yield;
		SetCommonData("explosion",0);
		break;}
		yield;}}}
		
task TReflection(obj){
	let r = 70;
	let s = 1;
	while(!Obj_IsDeleted(obj)){
		if(ObjMove_GetX(obj) > 384){
			ObjMove_SetAngle(obj,180-ObjMove_GetAngle(obj)+rand(-r,r));
			ObjShot_SetGraphic(obj,839);
			ObjShot_SetDelay(obj,20);
			ObjMove_SetSpeed(obj,s);
			break;}
		if(ObjMove_GetX(obj) < 0){
			ObjMove_SetAngle(obj,180-ObjMove_GetAngle(obj)+rand(-r,r));
			ObjShot_SetGraphic(obj,839);
			ObjShot_SetDelay(obj,20);
			ObjMove_SetSpeed(obj,s);
			break;}
		if(ObjMove_GetY(obj) < 0){
			ObjMove_SetAngle(obj,-ObjMove_GetAngle(obj)+rand(-r,r));
			ObjShot_SetGraphic(obj,839);
			ObjShot_SetDelay(obj,20);
			ObjMove_SetSpeed(obj,s);
			break;}
	yield;}}