#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["SP1"]
#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, 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);
	
	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);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),21);
	yield;
} 

@Finalize {
} 

task mainTask { 
SetCommonData("Flare",1);
SetCommonData("FlareIntensity", 2);
SpellCard("Explosion Sign &quot;Omega Flare&quot;", [255,10,0], GetCurrentScriptDirectory ~ "./default_system/img/Ingame/Emotions/uts.png", 100, "Utsuho");
Attack(60*99999);
let counter = 2;

	ascent(i in 0..6){
	let obj = Sun3d(BossX, BossY-28, 1, 0.1, 125);
	ObjMove_AddPatternA1(obj, 0, 2, GetAngleToPlayer(objBoss)+i*360/6);
	}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/explosion.wav", 80);
	wait(120);
	loop{
	ascent(i in 0..6){
	let obj = Sun3d(BossX, BossY-28, 1, 0.1, 125);
	ObjMove_AddPatternA1(obj, 0, 2, GetAngleToPlayer(objBoss)+i*360/6);
	}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/explosion.wav", 80);
	
	Shoot(counter);
	if(counter<6){counter++;}
	wait(120);
	}
}

task Shoot(time){
	let random = rand(0,360);
	ascent(i in 0..time){
		ascent(j in 0..32){
		let obj = FireShotA1(BossX, BossY-28, rand(2, 3), GetAngleToPlayer(objBoss)+random+j*360/32, BALL_S_BLUE, 10);
		ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
		}
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 80);
		wait(20);
	}
}

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