#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["SP3"]
#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(4000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(60);
	}
	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", 2);
Pattern;
}

task Bullets{
wait(60*5);
	loop{
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/chargelong.wav", 80);
	wait(60);
	let random = rand(0,360);
	let angle = 0;
	Attack(60*3+30);
		ascent(i in 0..20){
			ascent(j in 0..12){
			let obj = CreateShotA1(BossX, BossY-28, 2, random+j*360/12+angle, MIKO_ORB_GRAY+i, 10);
			ObjMove_AddPatternA2(obj, 60, NO_CHANGE, NO_CHANGE, 0.2, 0, 10);
			ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
			}
			PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 80);
			PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 80);
			wait(3);
		}
	wait(60*3);
	}
}

task Speed{
wait(180);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/explosion.wav", 80);
let spd = 0;
loop{
SetCommonData("StarSpeed", spd);
if(spd<0.75){spd+=0.005;}
yield;
}
}

task Stars{
ascent(j in 0..5){
	ascent(i in -6..6){
	let obj = CreateShotA1(0, 10+j*50, 0, 0, STAR_M_GRAY+i, 10);
	ObjShot_SetIntersectionEnable(obj, 0);
	ObjShot_SetAutoDelete(obj, 0);
	Obj_SetRenderPriorityI(obj, 45);
	MoveStar(obj, i*20, j, j);
	}
}
ascent(j in 0..5){
	ascent(i in -6..6){
	let obj = CreateShotA1(0, 10+j*50, 0, 0, STAR_M_GRAY+i, 10);
	ObjShot_SetIntersectionEnable(obj, 0);
	ObjShot_SetAutoDelete(obj, 0);
	Obj_SetRenderPriorityI(obj, 45);
	MoveStar2(obj, -i*20, j, j);
	}
}

	task MoveStar(obj, off, off2, off3){
	let rad = 150;
		loop{
		ObjMove_SetPosition(obj, GetCenterX+rad*tan(off), -85+off2*150);
		off+=GetCommonData("StarSpeed", 0);
		off2+=GetCommonData("StarSpeed", 0)*0.02;
		if(GetCommonData("StarSpeed", 0)>0){ObjShot_SetIntersectionEnable(obj, 1);}
		if(off2>4.6){off2=-0.4;}
		yield;
		}
	}
	task MoveStar2(obj, off, off2, off3){
	let rad = 150;
		loop{
		ObjMove_SetPosition(obj, GetCenterX+rad*tan(off), -10+off2*150);
		off-=GetCommonData("StarSpeed", 0);
		off2+=GetCommonData("StarSpeed", 0)*0.02;
		if(GetCommonData("StarSpeed", 0)>0){ObjShot_SetIntersectionEnable(obj, 1);}
		if(off2>4.6){off2=-0.4;}
		yield;
		}
	}
}

task Pattern{
Attack(60*7);
	let obj = Sun3dExplode(BossX, BossY-28, 3, 0.01, 125);
	Move(obj);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/explosion.wav", 80);
}

task Move(obj){
wait(60);
ObjMove_SetDestAtWeight(obj, GetStgFrameWidth/2, -100, 10, 0.1);
wait(60*3);
let spd = 0.01;
let size = 3;
let intensity = 0;
ascent(i in 0..60*4){
Obj_SetValue(obj, "SunSizeSpeed", spd);
Obj_SetValue(obj, "SunSize", size);
Obj_SetValue(obj, "SunIntensity", intensity);
spd-=i/1000000;
size+=i/100;
intensity+=i/100;
yield;
}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/chargebig.wav", 80);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/chargelong.wav", 80);
SpellCardInstant("Core Collapse &quot;Supernova&quot;", [255,10,0], GetCurrentScriptDirectory ~ "./default_system/img/Ingame/Emotions/uts.png", 100, "Utsuho");
ascent(i in 0..60*2){
Obj_SetValue(obj, "SunSizeSpeed", spd);
Obj_SetValue(obj, "SunSize", size);
Obj_SetValue(obj, "SunIntensity", intensity);
spd+=i/1000000;
size-=i/100;
intensity+=i/100;
yield;
}
ascent(i in 0..60){
Obj_SetValue(obj, "SunSizeSpeed", spd);
Obj_SetValue(obj, "SunSize", size);
Obj_SetValue(obj, "SunIntensity", intensity);
spd+=i/100000;
size-=i/10;
intensity+=i/100;
yield;
}
Obj_SetValue(obj, "SunHitbox", false);

ascent(i in 0..27){
Obj_SetValue(obj, "SunSizeSpeed", spd);
Obj_SetValue(obj, "SunSize", size);
Obj_SetValue(obj, "SunIntensity", intensity);
spd+=i/10000;
size-=i/9;
intensity+=i/100;
yield;
}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/burst2.wav", 70);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/explosion.wav", 80);
ascent(i in 0..30){
Obj_SetValue(obj, "SunSizeSpeed", spd);
Obj_SetValue(obj, "SunSize", size);
Obj_SetValue(obj, "SunIntensity", intensity);
spd+=i/10000;
size+=i;
intensity+=i/100;
yield;
}
wait(90);
Obj_SetValue(obj, "Nova", 1);
Background3;
SetCommonData("ForceLifebar", 0);
SetCommonData("Spell", 1);
Stars;
Speed;
Bullets;
}

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());
} 