#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["SP5"]
#Text["Baaaaaaaaaap"]
#System["./default_system/Default_System.txt"]
#include "./default_system/MS_Index.txt"

let objBoss;

let BossX; 
let BossY;

@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	HitSound(objBoss, 80, 450);
	EnemyMarker(objBoss);
	DamageReduction(objBoss, 1);
	DrawName("Utsuho Reiuji", [255,25,25], 12.7);
	MagicRing(objBoss,true);
	FlameAura(objBoss,[199, 5, 5],3);
	RenderCharacter(objBoss);
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/3, 10, 4);
	
	SetCommonData("BossAlpha",255);
	SetCommonData("ForceLifebar", 1);
	
	if(GetCommonData("IsStage", false)==false){
	LoadAssets;
	StageBackground;
	}
	
	mainTask;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(1);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(90);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
	case(EV_REQUEST_IS_DURABLE_SPELL){
		SetScriptResult(true);
	}
} 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	//if(GetCommonData("Spell", 0)==1){ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),21);}
	yield;
} 

@Finalize {
} 

task mainTask { 
wait(90);
SetCommonData("Flare",1);
SetCommonData("FlareIntensity", 2);
SetCommonData("BossScale",1);
ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, -150, 10, 6);
SpellCard("Meltdown &quot;Planetary Buster&quot;", [255,10,0], GetCurrentScriptDirectory ~ "./default_system/img/Ingame/Emotions/uts.png", 100, "Utsuho");
SetCommonData("BossScale",0.2);
GetCommonData("BossRender",25);
ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2, 10, 2);
wait(210);
loop(2){
	let rad = GetObjectDistance(objBoss, GetPlayerObjectID);
	let obj = Sun3dZ(BossX, BossY-28, 5000, 25, 1, 0.1, 200);
	ObjMove_AddPatternA1(obj, 0, rad/200, GetAngleToPlayer(objBoss));
	let obj2 = NuclearBall(GetPlayerX, GetPlayerY, 2);
	Del(obj2);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/explosion.wav", 30);
	wait(180);
}
loop(6){
	let rad = GetObjectDistance(objBoss, GetPlayerObjectID);
	let obj = Sun3dZ(BossX, BossY-28, 5000, 25, 1, 0.1, 200);
	ObjMove_AddPatternA1(obj, 0, rad/200, GetAngleToPlayer(objBoss));
	let obj2 = NuclearBall(GetPlayerX, GetPlayerY, 2);
	Del(obj2);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/explosion.wav", 30);
	wait(60);
	loop(1){
	let obj = NuclearBall(GetPlayerX, GetPlayerY, 1);
	Del2(obj);
		ascent(i in 0..24){
		let obj2 = CreateShotA1(BossX, BossY, 2, i*360/24, MIKO_ORB_YELLOW, 10);
		ObjShot_SetIntersectionEnable(obj2, 0);
		ObjRender_SetScaleXYZ(obj2, 0.2, 0.2, 1);
		Obj_SetRenderPriorityI(obj2, 28);
		ObjRender_SetAlpha(obj2, 199);
		}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 30);
	wait(30);
	}
	wait(60);
}
loop(6){
	let rad = GetObjectDistance(objBoss, GetPlayerObjectID);
	let obj = Sun3dZ(BossX, BossY-28, 5000, 25, 1, 0.1, 200);
	ObjMove_AddPatternA1(obj, 0, rad/200, GetAngleToPlayer(objBoss));
	let obj2 = NuclearBall(GetPlayerX, GetPlayerY, 2);
	Del(obj2);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/explosion.wav", 30);
	wait(100);
	loop(2){
	let obj = NuclearBall(GetPlayerX, GetPlayerY, 1);
	Del2(obj);
		ascent(i in 0..24){
		let obj2 = CreateShotA1(BossX, BossY, 2, i*360/24, MIKO_ORB_YELLOW, 10);
		ObjShot_SetIntersectionEnable(obj2, 0);
		ObjRender_SetScaleXYZ(obj2, 0.2, 0.2, 1);
		Obj_SetRenderPriorityI(obj2, 28);
		ObjRender_SetAlpha(obj2, 199);
		}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 30);
	wait(10);
	}
}
loop(6){
	let rad = GetObjectDistance(objBoss, GetPlayerObjectID);
	let obj = Sun3dZ(BossX, BossY-28, 5000, 25, 1, 0.1, 200);
	ObjMove_AddPatternA1(obj, 0, rad/200, GetAngleToPlayer(objBoss));
	let obj2 = NuclearBall(GetPlayerX, GetPlayerY, 2);
	Del(obj2);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/explosion.wav", 30);
	wait(60);
	loop(4){
	let obj = NuclearBall(GetPlayerX, GetPlayerY, 1);
	Del2(obj);
		ascent(i in 0..24){
		let obj2 = CreateShotA1(BossX, BossY, 2, i*360/24, MIKO_ORB_YELLOW, 10);
		ObjShot_SetIntersectionEnable(obj2, 0);
		ObjRender_SetScaleXYZ(obj2, 0.2, 0.2, 1);
		Obj_SetRenderPriorityI(obj2, 28);
		ObjRender_SetAlpha(obj2, 199);
		}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 30);
	wait(15);
	}
	wait(60);
}
loop(7){
	let rad = GetObjectDistance(objBoss, GetPlayerObjectID);
	let obj = Sun3dZ(BossX, BossY-28, 5000, 25, 1, 0.1, 200);
	ObjMove_AddPatternA1(obj, 0, rad/200, GetAngleToPlayer(objBoss));
	let obj2 = NuclearBall(GetPlayerX, GetPlayerY, 2);
	Del(obj2);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 30);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/explosion.wav", 30);
	wait(60);
	loop(1){
	let obj = NuclearBall(GetPlayerX, GetPlayerY, 1);
	Del2(obj);
		ascent(i in 0..24){
		let obj2 = CreateShotA1(BossX, BossY, 2, i*360/24, MIKO_ORB_YELLOW, 10);
		ObjShot_SetIntersectionEnable(obj2, 0);
		ObjRender_SetScaleXYZ(obj2, 0.2, 0.2, 1);
		Obj_SetRenderPriorityI(obj2, 28);
		ObjRender_SetAlpha(obj2, 199);
		}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 30);
	wait(30);
	}
}
wait(180);
loop(3){
let random = rand(0,360);
	ascent(i in 0..3){
		ascent(j in 0..5){
		let obj2 = NuclearBall(GetCenterX+i*100*cos(i*360/16+j*360/5+random), GetCenterY+i*100*sin(i*360/16+j*360/5+random), 3);
		Del3(obj2);
		let rad = GetObjectDistance(objBoss, obj2);
		let obj = Sun3dZ(BossX, BossY-28, 5000, 25, 1, 0.1, 200);
		ObjMove_AddPatternA1(obj, 0, rad/200, GetAngleToObject(objBoss, obj2)+180);
		}
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 30);
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/explosion.wav", 30);
		wait(20);
	}
	wait(120);
random = rand(0,360);
	ascent(i in 0..3){
		ascent(j in 0..5){
		let obj2 = NuclearBall(GetCenterX+i*100*cos(-i*360/16+j*360/5+random), GetCenterY+i*100*sin(-i*360/16+j*360/5+random), 3);
		Del3(obj2);
		let rad = GetObjectDistance(objBoss, obj2);
		let obj = Sun3dZ(BossX, BossY-28, 5000, 25, 1, 0.1, 200);
		ObjMove_AddPatternA1(obj, 0, rad/200, GetAngleToObject(objBoss, obj2)+180);
		}
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 30);
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/explosion.wav", 30);
		wait(20);
	}
	wait(120);
}

	task Del(obj){
	let X = ObjMove_GetX(obj);
	let Y = ObjMove_GetY(obj);
	wait(60*4-30);
	Obj_Delete(obj);
	}
	task Del2(obj){
	let X = ObjMove_GetX(obj);
	let Y = ObjMove_GetY(obj);
	Ring;
	wait(60*6+30);
	Obj_Delete(obj);
		task Ring{
		wait(60*4-30);
			ascent(j in 0..8){
			let obj = CreateShotA2(X+500*cos(j*360/8), Y+500*sin(j*360/8), 7, j*360/8+180, -0.1, 2, MIKO_ORB_YELLOW, 10);
			Deletion(obj);
			}
		}
	}
	task Del3(obj){
	let X = ObjMove_GetX(obj);
	let Y = ObjMove_GetY(obj);
	wait(60*4-30);
	Obj_Delete(obj);
		ascent(j in 0..8){
		let obj = CreateShotA2(X+50*cos(j*360/8), Y+50*sin(j*360/8), 0.5, j*360/8, 0.01, 3, BALL_M_YELLOW, 0);
		ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
		}
	}
	task Deletion(obj){
	ObjShot_SetAutoDelete(obj, 0);
	wait(60*3);
	ObjShot_SetAutoDelete(obj, 1);
	}
}

task Movement{ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+rand(-150, 150), GetStgFrameHeight/3+rand(-25, 25), 10, 4);}

task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 