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

let BossX;
let BossY;
let objBoss;

@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	RenderCharacter(objBoss);
	SetCommonData("ForceLifebar", 1);
	
	if(GetCommonData("IsStage", false)==true){
	MagicRing(objBoss,false);
	}
	else{
	MagicRing(objBoss,true);
	SetCommonData("BossAlpha", 255);
	StageBackground;
	}
	
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/3, 10, 4);
	mainTask;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(6000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(79);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
	case(EV_REQUEST_IS_DURABLE_SPELL){
		SetScriptResult(true);
	}
}

let appear = false; 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	yield;
} 

@Finalize {
} 

let proceed = 0;

task mainTask { 
	SpellCard("&quot;Angel Hunting Season&quot;", [25, 255, 255], GetCurrentScriptDirectory ~ "./default_system/img/Ingame/sarakiel_01.png", 0);
	
	ascent(i in 0..45){
	let ang = rand(0,360);
	let obj = Bat(BossX+300*cos(ang), BossY+300*sin(ang), 1000, [rand(100, 150), rand(15, 30), rand(100, 150)], false);
	BatFly(obj);
	wait(2);
	}
	wait(180);
	ObjMove_SetDestAtWeight(objBoss, BossX, BossY-600, 10, 6);
	
	wait(60);
	
	ascent(i in 0..4){
	let obj = Bat(GetStgFrameWidth/2+200*cos(i*360/4+45), GetStgFrameHeight/2+200*sin(i*360/4+45), 999999999, [255,255,255], true);
	Move(obj, i);
	Dormant(obj, i);
		if(i==0 || i==2){
		Shoot1(obj, true);
		}
		else{
		Shoot1(obj, false);
		}
	}

	loop(3){
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/charge.wav", 255);
	loop(10){
	Concentrate(GetStgFrameWidth/2, GetStgFrameHeight/6, 0, 4, 3, 0.6, "Cherry", 150, -2, [125, 15, 125]);
	Concentrate(GetStgFrameWidth/2, GetStgFrameHeight/6, 0, 4, 3, 0.6, "Cherry", 150, 2, [255, 255, 255]);
	wait(6);
	}
	PhantomEye(120);
	wait(160);
	}
	
	wait(120);
	loop(3){
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/charge.wav", 255);
	loop(10){
	Concentrate(GetStgFrameWidth/2, GetStgFrameHeight/6, 0, 4, 3, 0.6, "Cherry", 150, -2, [125, 15, 125]);
	Concentrate(GetStgFrameWidth/2, GetStgFrameHeight/6, 0, 4, 3, 0.6, "Cherry", 150, 2, [255, 255, 255]);
	wait(6);
	}
	PhantomEye(200);
	wait(400);
	}
	
	proceed++;
	
	wait(120);
	
	let count = 0;
	ascent(i in 0..30){
	let obj = ScytheSlash(-10+i*25, 0, 0, 1);
	Shoot2(obj);
	count++;
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/slash.wav", 60);
	wait(5);
	let obj2 = ScytheSlash(-10+i*25, 0, 0, -1);
	Shoot2(obj2);
	count++;
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/slash.wav", 60);
	wait(5);
	}
	ascent(i in 0..20){
	let obj = ScytheSlash(GetStgFrameWidth, i*25, 90, 1);
	Shoot2(obj);
	count++;
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/slash.wav", 60);
	wait(5);
	let obj2 = ScytheSlash(GetStgFrameWidth, i*25, 90, -1);
	Shoot2(obj2);
	count++;
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/slash.wav", 60);
	wait(5);
	}
	ascent(i in 0..30){
	let obj = ScytheSlash(GetStgFrameWidth-i*25, GetStgFrameHeight, 180, 1);
	Shoot2(obj);
	count++;
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/slash.wav", 60);
	wait(5);
	let obj2 = ScytheSlash(GetStgFrameWidth-i*25, GetStgFrameHeight, 180, -1);
	Shoot2(obj2);
	count++;
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/slash.wav", 60);
	wait(5);
	}
	ascent(i in 0..20){
	let obj = ScytheSlash(0, GetStgFrameHeight-i*25, 270, 1);
	Shoot2(obj);
	count++;
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/slash.wav", 60);
	wait(5);
	let obj2 = ScytheSlash(0, GetStgFrameHeight-i*25, 270, -1);
	Shoot2(obj2);
	count++;
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/slash.wav", 60);
	wait(5);
	}
	
	wait(60*8-30);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/charge.wav", 255);
		loop(10){
		Concentrate(BossX, BossY, 0, 4, 3, 0.8, "Cherry", 150, -2, [125, 15, 125]);
		Concentrate(BossX, BossY, 0, 4, 3, 0.8, "Cherry", 150, 2, [255, 255, 255]);
		wait(6);
		}
	PhantomEye(300);
	
	task Shoot2(obj){
	let shot = CreateStraightLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj), ObjMove_GetAngle(obj)+90+rand(-2,2), 0, 25, 120, BEAM_PURPLE, 120);
	Enlarge(shot);
	}
	
	task Shoot1(obj, check){
	wait(60);
	let count = 0;
	while(!Obj_IsDeleted(obj)){
		ascent(i in 0..4){
		let shot = CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 1.5, count+i*360/4, VORTEX_PURPLE, 10);
		PhantomCheck(shot, check);
			if(count >= 15*30){
			let shot = CreateStraightLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj), count+i*360/4, 0, 25, 30, VORTEX_PURPLE, 120);
			PhantomCheck(shot, check);
			Enlarge(shot);
			PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/laser2.wav", 60);
			}
		}
	if(proceed==1){break;}
	count+=15;
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/labullet.wav", 255);
	wait(40);
	}
	wait(60);
	loop(13){
	let shot = CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 1.5, GetAngleToPlayer(obj), VORTEX_PURPLE, 25);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/labullet.wav", 255);
	wait(100);
	}
	let time = 0;
	loop{
	let shot = CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 1.5, GetAngleToPlayer(obj)+rand(-25,25), VORTEX_PURPLE, 25);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/labullet.wav", 255);
	PhantomCheck(shot, true);
	wait(40-time);
	if(time<30){time+=5;}
	}
	
	}
	
	task Move(obj, i){
	let count = 0;
	loop(60*15){
	ObjMove_SetDestAtWeight(obj, GetStgFrameWidth/2+200*cos(i*360/4+45+count), GetStgFrameHeight/2+300*sin(i*360/4+45+count), 5, 2);
	count+=0.5;
	yield;
	}
	}
	task Dormant(obj, i){
	let count = 0;
	wait(60*60);
	loop(60*15){
	ObjMove_SetDestAtWeight(obj, GetStgFrameWidth/2+200*cos(i*360/4+45+count), GetStgFrameHeight/2+300*sin(i*360/4+45+count), 10, 5);
	count+=2;
	yield;
	}
	}
	task PhantomCheck(obj, check){
		while(!Obj_IsDeleted(obj)){
		let switch = GetCommonData("Phantom", false);
		if(switch == check){
		ObjRender_SetBlendType(obj, BLEND_SUBTRACT);
		ObjShot_SetIntersectionEnable(obj, 0);
		}
		else{
		ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
		ObjShot_SetIntersectionEnable(obj, 1);
		}
		yield;
		}
	}
	
	task Enlarge(obj){
	let counter = 0;
	let laslength = 0;
		while(!Obj_IsDeleted(obj)){
		ObjLaser_SetLength(obj, laslength*10);
		if(laslength < 100){laslength++;}
		yield;
		}
	}
	
	task BatFly(obj){
	wait(30);
	let angle = rand(0,360);
	loop(180){
	ObjMove_SetDestAtWeight(obj, BossX+rand(0, 50)*cos(angle), BossY+rand(0, 50)*sin(angle), 10, 4);
	yield}
	ObjMove_SetDestAtWeight(obj, BossX, BossY-600, 10, 6);
	wait(180);
	Obj_Delete(obj);
	}
	
}

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