#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["SP2"]
#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("Fallout &quot;Scorched Earth&quot;", [255,10,0], GetCurrentScriptDirectory ~ "./default_system/img/Ingame/Emotions/uts.png", 100, "Utsuho");
Pattern;
}

task Pattern{
loop{
Attack(60);
Bullets;
	ascent(i in 0..3){
	let random = rand(0,360);
		ascent(j in 0..12){
		let obj = CreateShotA2(BossX, BossY-28, 1, random+j*360/12, 0.02, 10, MIKO_ORB_RED, 10);
		Boop(obj);
		}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/labullet.wav", 80);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 80);
	wait(20);
	}
	wait(120);
}

task Bullets{
	ascent(i in 0..24){
	let random = rand(0,360);
		ascent(j in 0..6){
		let obj = CreateShotA2(BossX, BossY-28, 1, random+j*360/6, 0.04, 10, BALL_S_BLUE, 10);
		ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
		}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 80);
	wait(5);
	}
}
	
	task Boop(obj){
	while(!Obj_IsDeleted(obj)){
	if(ObjMove_GetY(obj)>GetStageDown){boom(obj); yield; Obj_Delete(obj);}
	yield;
	}
	
	task boom(obj){
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/explosion.wav", 80);
	Circle(ObjMove_GetX(obj), ObjMove_GetY(obj));
	Explosion(ObjMove_GetX(obj), ObjMove_GetY(obj), 2);
	ScreenShake(5,15);
	NuclearLaser(ObjMove_GetX(obj), ObjMove_GetY(obj), 270, 600, 25, 60, 50, 120);
	}
}
}

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