#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["NS2"]
#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(2500);
     	}
	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);
Movement;
	loop{
	NuclearCharge(objBoss);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/chargelong.wav", 80);
	wait(60);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/explosion.wav", 80);
	RocketBooster1(objBoss);
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth+200, GetStgFrameHeight/3, 10, 7);
	wait(120);
	ascent(j in 0..2){
	ObjMove_SetPosition(objBoss, -50, GetStageDown+75);
	ObjMove_AddPatternA2(objBoss, 0, 1, 270, 0.2, 0.5, 10);
	Bullets;
	wait(180);
	ObjMove_SetPosition(objBoss, GetStageRight+50, GetStageDown+75);
	ObjMove_AddPatternA2(objBoss, 0, 1, 270, 0.2, -0.5, 10);
	Bullets;
	wait(180);
	}
	SetCommonData("BoosterDone", 1);
	yield;
	SetCommonData("BoosterDone", 0);
	ObjMove_SetPosition(objBoss, -70, 200);
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/3, 10, 4);
	wait(180);
	Bullets2;
	wait(120+30);
	}
}

task Bullets2{
	ascent(i in 0..24){
		ascent(j in 0..12){
		FireShotA1(BossX, BossY, 1.5+i/4, GetAngleToPlayer(objBoss)+j*360/12, VORTEX_RED, 10);
		}
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 80);
		wait(7);
	}
}

task Bullets{
wait(30);
	ascent(i in 0..12){
	let random = rand(0, 100);
			ascent(k in 0..2){
			let obj = NuclearBall(BossX, BossY, 1);
			ObjMove_SetDestAtWeight(obj, BossX+50*cos(ObjMove_GetAngle(objBoss)+90+180*k), BossY+50*sin(ObjMove_GetAngle(objBoss)+90+180*k), 10, 3);
			Del(obj, i);
			}
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 80);
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/labullet.wav", 80);
		wait(5);
	}
	task Del(obj, i){
	wait(90+i*10);
	ascent(i in 0..3){
	SmollMikoOrb(ObjMove_GetX(obj), ObjMove_GetY(obj), 0.5, GetAngleToPlayer(obj)+45-45*i, 0.02, 10, 12);
	}
	let random = rand(0,360);
	ascent(j in 0..6){
	let obj2 = FireShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 2, random+j*360/6, BALL_M_YELLOW, 12);
	ObjRender_SetBlendType(obj2, BLEND_ADD_ARGB);
	}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/labullet.wav", 80);
	Obj_Delete(obj);
	}
	
	task SmollMikoOrb(x, y, spd, ang, acc, maspd, del){
	let obj = CreateShotA2(x, y, spd, ang, acc, maspd, MIKO_ORB_ORANGE, del);
	ObjShot_SetIntersectionEnable(obj, 0);
	ObjRender_SetScaleXYZ(obj, 0.5, 0.5, 1);
	let obj2 = CreateShotA2(x, y, spd, ang, acc, maspd, BALL_S_BLUE, del);
	Obj_SetVisible(obj2, 0);
	loop{
	if(Obj_IsDeleted(obj2)){Obj_Delete(obj);}
	yield;
	}
	}
}

task Movement{
	loop{
	if(GetMouseState(MOUSE_RIGHT)>0){
	ObjMove_SetDestAtWeight(objBoss, GetMouseX-30, GetMouseY-10, 13, 7);
	}
	yield;
	}
}

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