#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["And Something else."]
#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);
	
	EnemyMarker(objBoss);
	HitSound(objBoss, 50, 450);
	RenderCharacter(objBoss);
	DamageReduction(objBoss, 320);
	
	SetCommonData("ForceLifebar", 1);
	SetCommonData("RenderTimer", 0);
	
	ObjMove_SetPosition(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/4+10);
	
	if(GetCommonData("IsStage", false)==false){
	LoadAssets;
	}
	
	mainTask;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(125012951285912859);
     	}
	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 { 
	let door = DoorCena(GetStgFrameWidth/2, GetStgFrameHeight/2-100);
	wait(120);
	Obj_SetValue(door, "Open", 1);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/creak.wav", 90, 0);
	EnemyMarker(objBoss);
	wait(50);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/ANDHISNAMEIS.ogg", 90, 0);
	Set2DCameraFocusX(GetStgFrameWidth/2);
	Set2DCameraFocusY(GetStgFrameHeight/2-100);
	ScreenShakeCena(120,15);
	wait(100);
	Eyelasers;
	loop{
	let random = rand(0,360);
	ascent(i in 0..16){
	let obj = FireShotA1(BossX+100*cos(random + i*360/16), BossY+100*sin(random + i*360/16), 7, random+i*360/16, ORB_L2_BLUE_ADD, 25);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 60, 0);
	wait(5);
	}
}

task Eyelasers{
let obj = FireShotA1(BossX+10, BossY-2, 0, 0, ORB_M_RED_ADD, 25);
ObjShot_SetSpellResist(obj, 1);
let obj2 = FireShotA1(BossX-10, BossY-2, 0, 0, ORB_M_RED_ADD, 25);
ObjShot_SetSpellResist(obj2, 1);
wait(60);
loop{
let random = rand(0,360);
CreateStraightLaserA1(BossX+10, BossY-2, GetAngleToPlayer(objBoss), 600, 15, 120, LASER_RED, 50);
CreateStraightLaserA1(BossX-10, BossY-2, GetAngleToPlayer(objBoss), 600, 15, 120, LASER_RED, 50);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/laser1.wav", 50, 50);
if(GetObjectDistance(GetPlayerObjectID, objBoss) < 100){
	ascent(i in 0..16){
	let obj = FireShotA1(BossX+2*cos(random + i*360/16), BossY+2*sin(random + i*360/16), 7, random+i*360/16, ORB_L2_RED_ADD, 25);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	}
wait(2);}
else{wait(20);}
}
}

task ScreenShakeCena(duration,range) {
let shake = range;
	loop(duration) {
		Set2DCameraFocusX(GetStgFrameWidth/2 -15 + rand(-shake, shake));
		Set2DCameraFocusY(GetStgFrameHeight/2-100 + rand(-shake, shake));
		Set2DCameraRatio(2);
		shake-=range/duration;
		yield;
		Reset2DCamera;
	}
}

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