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

let objBoss;

let BossX; 
let BossY;

SetCommonData("BossAlpha",255);
SetCommonData("ForceLifebar", 0);

@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	HitSound(objBoss, 80, 450);
	EnemyMarker(objBoss);
	DamageReduction(objBoss, 0);
	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);
	
	if(GetCommonData("IsStage", false)==false){
	LoadAssets;
	StageBackground;
	}
	
	mainTask;
	end;
} 

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

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),21);
	yield;
} 

@Finalize {
} 


task mainTask { 
//SpellCard("Atomic Fire &quot;Uncontainable Nuclear Reaction&quot;", [255,10,0], GetCurrentScriptDirectory ~ "./default_system/img/Ingame/Emotions/uts.png", 100, "Utsuho");
wait(90);
SetCommonData("Flare",1);
SetCommonData("FlareIntensity", 4);
	loop{
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/chargelong.wav", 80);
	wait(60);
	let random = rand(0,360);
	let angle = 0;
	Attack(60*3+30);
		ascent(k in 1..5){
			ascent(i in 0..10){
				ascent(j in 0..24){
				let obj = CreateShotA1(BossX, BossY-28, 2, random+j*360/24+angle, BALL_M_YELLOW, 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);
			}
			angle=k*8
		}
		Movement;
		wait(120);
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/chargelong.wav", 80);
		wait(60);
		random = rand(0,360);
		angle = 0;
		Attack(60*3+30);
		ascent(k in 1..5){
			ascent(i in 0..12){
				ascent(j in 0..12){
				let obj = CreateShotA1(BossX, BossY-28, 2, random+j*360/12+angle, BALL_M_YELLOW, 10);
				ObjMove_AddPatternA2(obj, 0, NO_CHANGE, NO_CHANGE, 0, 0.7, 10);
				ObjMove_AddPatternA2(obj, 60, NO_CHANGE, NO_CHANGE, 0.2, 1, 10);
				ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
				let obj2 = CreateShotA1(BossX, BossY-28, 2, random+j*360/12+angle, BALL_M_YELLOW, 10);
				ObjMove_AddPatternA2(obj2, 0, NO_CHANGE, NO_CHANGE, 0, -0.7, 10);
				ObjMove_AddPatternA2(obj2, 60, NO_CHANGE, NO_CHANGE, 0.2, -1, 10);
				ObjRender_SetBlendType(obj2, BLEND_ADD_ARGB);
				}
			PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 80);
			PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 80);
			wait(3);
			}
			wait(5);
			angle=k*360/24;
		}
		Movement;
		wait(120);
	}
}

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

/* Utsuho's First Spell
loop{
	ascent(i in 0..8){
	let obj = Sun3d(BossX, BossY, 1, 0.1, 75);
	ObjMove_AddPatternA1(obj, 0, 1, GetAngleToPlayer(objBoss)+i*360/8);
	SizeDown(obj);
	}
	wait(90);
	ascent(i in 0..8){
	let obj = Sun3d(BossX, BossY, 1, 0.1, 75);
	ObjMove_AddPatternA1(obj, 0, 1, GetAngleToPlayer(objBoss)+i*360/8);
	SizeDown(obj);
	}
Bullets;
wait(60*4);
}

task Bullets{
	ascent(i in 0..60*3){
		ascent(j in 0..3){
		FireShotA1(BossX, BossY-25, rand(1, 2), j*360/3+i*2, BALL_S_BLUE, 10);
		}
		yield;
	}
}

	task SizeDown(obj){
	let scale = 1;
	wait(10);
	Obj_SetValue(obj, "SunSizeSpeed", 0.0005);
		loop{
		Obj_SetValue(obj, "SunSize", scale);
		scale-=0.0005;
		yield;
		}
	}
*/


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