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

let objBoss;

let BossX; 
let BossY;

@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);
	
	SetCommonData("BossAlpha",255);
	SetCommonData("ForceLifebar", 0);
	
	if(GetCommonData("IsStage", false)==false){
	LoadAssets;
	StageBackground;
	}
	
	mainTask;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(5000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(90);
	}
	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 { 
wait(90);
SetCommonData("Flare",1);
SetCommonData("FlareIntensity", 3);
SetCommonData("BossScale",1);
SpellCard("Energy Star &quot;White Dwarf&quot;", [255,10,0], GetCurrentScriptDirectory ~ "./default_system/img/Ingame/Emotions/uts.png", 100, "Utsuho");
Attack(999999);
Stage;
loop{
	if(GetCommonData("Stage", 0) == 0){
	ascent(i in 0..8){
	let obj = Sun3d(BossX, BossY-28, 0.2, 0.02, 125);
	ObjMove_AddPatternA1(obj, 0, 1.2, GetAngleToPlayer(objBoss)+i*360/8);
	Blep(obj);
	Blep2(obj);
	}
	}
	else{
	ascent(i in 0..10){
	let obj = Sun3d(BossX, BossY-28, 0.2, 0.02, 125);
	ObjMove_AddPatternA1(obj, 0, 1.2, GetAngleToPlayer(objBoss)+i*360/10);
	Blep(obj);
	Blep3(obj);
	}	
	}
	wait(120);
}

}

task Stage{
let switch = 0;
loop{
if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) < 2500 && switch == 0){
SetCommonData("Stage", 1);
}
yield;
}
}

task Blep(obj){
Gravity(obj);
GravityAura(obj);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/explosion.wav", 70);
ascent(i in 0..122){
Obj_SetValue(obj, "SunIntensity", 0+i*2);
yield;
}
}

task Gravity(obj){
let succ = 0.75;
while(!Obj_IsDeleted(obj)){
let dist = GetObjectDistance(obj, GetPlayerObjectID);
if(dist<75){
ObjMove_SetPosition(GetPlayerObjectID, ObjMove_GetX(obj)+(dist-succ)*cos(GetAngleToPlayer(obj)), ObjMove_GetY(obj)+(dist-succ)*sin(GetAngleToPlayer(obj)));
}
yield;
}
}

task Blep2(obj){
wait(60);
ascent(i in 0..6){
let obj2 = FireShotA2(ObjMove_GetX(obj), ObjMove_GetY(obj), 1, GetAngleToPlayer(obj)+i*360/6, 0.01, 10, BALL_S_BLUE, 20);	
ObjRender_SetBlendType(obj2, BLEND_ADD_ARGB);
}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 80);
}

task Blep3(obj){
wait(60);
ascent(i in 0..12){
let obj2 = FireShotA2(ObjMove_GetX(obj), ObjMove_GetY(obj), 1, GetAngleToPlayer(obj)+i*360/12, 0.01, 10, BALL_S_BLUE, 20);	
ObjRender_SetBlendType(obj2, BLEND_ADD_ARGB);
}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 80);
wait(60);
ascent(i in 0..12){
let obj2 = FireShotA2(ObjMove_GetX(obj), ObjMove_GetY(obj), 1, i*360/12, 0.01, 10, BALL_S_RED, 20);	
ObjRender_SetBlendType(obj2, BLEND_ADD_ARGB);
}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 80);
}

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