#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["NS3"]
#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(3500);
     	}
	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", 2);
loop{
ascent(i in 0..8){
let obj = NuclearSign(BossX+75*cos(i*360/8), BossY+75*sin(i*360/8), 0.7);
Circle(BossX+75*cos(i*360/8), BossY+75*sin(i*360/8));
Fire(obj);
Firelas(obj);
Move(obj, i*360/8, BossX, BossY);
}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 60);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/explosion.wav", 60);

	loop(4){
	Movement;
	wait(90);
	}
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+rand(-10, 10), GetStgFrameHeight/5+rand(-45, 5), 10, 4);
	Attack(180+60);
	wait(60);
	SetCommonData("FireLaser",1);
	yield;
	SetCommonData("FireLaser",0);
	wait(120);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spark.wav", 60);
	IntensityIncrease;
	Bullets;
	wait(120);
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/3, 10, 4);
	wait(60);
}

task Move(obj, off, x, y){
let rad = 75;
ascent(i in 0..60*4){
ObjMove_SetDestAtWeight(obj, x+rad*cos(off), y+rad*sin(off), 10, 4);
off+=0.2;
rad+=0.2;
yield;
}
ascent(i in 0..60*4){
ObjMove_SetDestAtWeight(obj, x+rad*cos(off), y+rad*sin(off), 10, 4);
off+=0.2;
rad-=0.2;
yield;
}
ascent(i in 0..60*8){
ObjMove_SetDestAtWeight(obj, x+rad*cos(off), y+rad*sin(off), 10, 4);
off+=0.4;
rad+=0.6;
yield;
}
Obj_Delete(obj);
}

}

task Bullets{
	ascent(j in 0..4){
		let random = rand(0,360);
		ascent(i in 0..16){
		FireShotA2(BossX, BossY-28, 7, random+i*360/16, -0.07, 2, MIKO_ORB_RED, 20);
		}
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 60);
		wait(15);
	}
}

task IntensityIncrease{
ascent(i in 0..60){
SetCommonData("FlareIntensity", 2+i/30);
yield;
}
SetCommonData("FlareIntensity", 2);
}

task Fire(obj){
wait(60);
while(!Obj_IsDeleted(obj)){
ascent(i in 0..3){
let obj2 = CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 3, GetAngleToObject(obj, objBoss)+45-i*45, ARROWHEAD_YELLOW, 10);
ObjRender_SetBlendType(obj2, BLEND_ADD_ARGB);
}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 60);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 60);
wait(45);
}
}

task Firelas(obj){
	while(!Obj_IsDeleted(obj)){
		if(GetCommonData("FireLaser",0)==1){
		NuclearLaser(ObjMove_GetX(obj), ObjMove_GetY(obj), GetAngleToObject(obj, objBoss), 600, 25, 100, 50, 120);
		}
	yield;
	}
}

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


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