#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["SP6"]
#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,false);
	FlameAura(objBoss,[199, 5, 5],3);
	RenderCharacter(objBoss);
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/3, 10, 4);
	
	SetCommonData("BossAlpha",255);
	SetCommonData("ForceLifebar", 1);
	SetCommonData("BossScale",0.2);
	GetCommonData("BossRender",25);
	SetCommonData("Spell", 0);
	SetCommonData("Stage", 0);
	
	if(GetCommonData("IsStage", false)==false){
	LoadAssets;
	StageBackground;
	}
	
	mainTask;
	end;
} 

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

@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", 1);
ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, -150, 10, 6);
wait(210);
SetCommonData("BossScale",1);
GetCommonData("BossRender",29);
ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2, 10, 2);
wait(180);
Attack(160);
ZoomIn;
wait(20);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/chargebig.wav", 80);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/chargelong.wav", 80);
ascent(i in 0..140){
SetCommonData("FlareIntensity", 1+i/20);
yield;
}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/burst2.wav", 70);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/explosion.wav", 80);
let obj = Sun3d(BossX, BossY-28, 3, 0.01, 151);
ObjMove_SetDestAtWeight(obj, GetStgFrameWidth/2, -150, 10, 2);
ScreenShake(210,5);
wait(80);
SpellCardInstant("Core Expansion &quot;Red Giant&quot;", [255,10,0], GetCurrentScriptDirectory ~ "./default_system/img/Ingame/Emotions/uts.png", 100, "Utsuho");
SetCommonData("ForceLifebar", 0);
SetCommonData("Spell", 1);
Stage;
wait(210);
Ring(obj);
loop{
Attacker(obj);
if(GetCommonData("Stage", 0) == 1){
Attacker2(obj);
}
wait(120*2);
}
}

task Ring(obj){
let ang = 0;
loop{
loop(40){
let random = rand(-5, 5);
ascent(i in 0..12){
let obj2 = FireShotA2(ObjMove_GetX(obj)+300*cos(ang+i*360/12+random), ObjMove_GetY(obj)+300*sin(ang+i*360/12+random), -3, ang+i*360/12+random, 0.05, 4, MIKO_ORB_BLUE, 10);
ObjMove_AddPatternA2(obj2, 120, NO_CHANGE, NO_CHANGE, -0.05, 0, 2.5);
ObjRender_SetBlendType(obj2, BLEND_SUBTRACT);
}
ang+=3;
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 60);
wait(8);
}
loop(40){
let random = rand(-5, 5);
ascent(i in 0..12){
let obj2 = FireShotA2(ObjMove_GetX(obj)+300*cos(ang+i*360/12+random), ObjMove_GetY(obj)+300*sin(ang+i*360/12+random), -3, ang+i*360/12+random, 0.05, 4, MIKO_ORB_BLUE, 10);
ObjMove_AddPatternA2(obj2, 120, NO_CHANGE, NO_CHANGE, -0.05, 0, 2.5);
ObjRender_SetBlendType(obj2, BLEND_SUBTRACT);
}
ang-=3;
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 60);
wait(8);
}
}
}

task Attacker(obj){
let random = rand(0,360);
	ascent(j in 0..24){
	NuclearLaser(ObjMove_GetX(obj)+200*cos(j*360/24+random), ObjMove_GetY(obj)+200*sin(j*360/24+random), j*360/24+random, 600, 50, 120, 100, 120);
	}
wait(120);
ScreenShake(120,5);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spark.wav", 80);
}

task Attacker2(obj){
	ascent(i in 0..5){
	let red = 22.5/1.5;
		ascent(j in 0..3){
		NuclearLaser(BossX, BossY-28,  GetAngleToPlayer(objBoss)+red-i*red/2, 600, 50, 120, 60, 120);
		}
	}
wait(120);
ScreenShake(120,15);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/burst.wav", 80);
}

task Stage{
let switch = 0;
loop{
if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) < 2500 && switch == 0){
SetCommonData("Stage", 1); switch++;
SetCommonData("FlareIntensity", 5);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/burst2.wav", 70);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/explosion.wav", 80);
ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2-50, 10, 2);
Attack(99999);
}
yield;
}
}

task ZoomIn{
ascent(i in 0..140){
Set2DCameraRatio(1+i/140);
yield;
}
}

task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
	SetCommonData("BossAlpha",255);
	SetCommonData("ForceLifebar", 0);
	StartSlow(TARGET_ALL, 15);
	loop(45){
	ExplodeEffectT(BossX, BossY, rand(1, 20), 1, "Cherry", [255, 10, 10], 10);
	ExplodeEffectT(BossX, BossY, rand(1, 20), 1, "Cherry", [155, 10, 155], 10);
	yield;
	}
	SetCommonData("bossx", BossX);
	SetCommonData("bossy", BossY);
	SetCommonData("UtsuhoIsDed", 1);
	StopSlow(TARGET_ALL);
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
}