#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["SP3"]
#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);
	HitSound(objBoss, 75, 450);
	RenderCharacter(objBoss);
	
	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(105);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
}

let appear = false; 

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

	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),21);
	yield;
} 

@Finalize {
} 

task mainTask { 
	SpellCard("Soul Reaping &quot;Scythe of Abunant Harvest&quot;", [25, 255, 255], GetCurrentScriptDirectory ~ "./default_system/img/Ingame/sarakiel_01.png", 0);
	wait(30);
	loop{
		loop(2){
		let radius = rand(100, 200);
		ascent(i in 0..3){
		let obj = ScytheSlash(BossX+radius*cos(i*360/3), BossY+radius*sin(i*360/3), i*360/3, 1);
		Shoot(obj, radius, i, 1, rand(0,360)+i*360/3);
		}
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/slash.wav", 60);
		radius = rand(100, 200);
		wait(60);
		ascent(i in 0..3){
		let obj = ScytheSlash(BossX+radius*cos(i*360/3), BossY+radius*sin(i*360/3), i*360/3, -1);
		Shoot(obj, radius, i, -1, rand(0,360));
		}
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/slash.wav", 60);
		wait(60);
		}
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/charge.wav", 255);
		Attack(60);
		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(160);
			
		let count = 0;
		loop(8){
		let obj = ScytheSlash(BossX+count*25*cos(GetAngleToPlayer(objBoss)), BossY+count*25*sin(GetAngleToPlayer(objBoss)), GetAngleToPlayer(objBoss), 1);
		Shoot2(obj);
		count++;
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/slash.wav", 60);
		wait(5);
		let obj2 = ScytheSlash(BossX+count*25*cos(GetAngleToPlayer(objBoss)), BossY+count*25*sin(GetAngleToPlayer(objBoss)), GetAngleToPlayer(objBoss), -1);
		Shoot2(obj2);
		count++;
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/slash.wav", 60);
		wait(5);
		}
		wait(180);
	}
	
	task Shoot(obj, rad, off, mult, random){
		ascent(i in 0..24){
		let shot = CreateShotA2(BossX+rad*cos(off*360/3+i*6*mult), BossY+rad*sin(off*360/3+i*6*mult), 0, ObjMove_GetAngle(obj)+random+i*6*mult, 0.01, 3, RICE_S_YELLOW, 5);
		yield;
		}
	}
	
	task Shoot2(obj){
	let random = rand(0,360);
	let las = CreateStraightLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj), random, 0, 15, 180+60, BEAM_PURPLE, 0);
	PhantomCheck(las, true);
		ascent(i in 0..16){
		let shot = CreateShotA2(ObjMove_GetX(obj)+100*cos(ObjMove_GetAngle(obj)-random+i*360/16), ObjMove_GetY(obj)+25*sin(ObjMove_GetAngle(obj)-random+i*360/16), 0, ObjMove_GetAngle(obj)+i*360/16, 0.00, 100, RICE_S_PURPLE, 5);
		ObjMove_AddPatternA2(shot, 120-i, 0, NO_CHANGE, 0.01, 0, 100);
		PhantomCheck(shot, true);
		yield;
		}
	}
	
	task PhantomCheck(obj, check){
	let counter = 0;
	let laslength = 0;
		while(!Obj_IsDeleted(obj)){
		let switch = GetCommonData("Phantom", false);
		ObjLaser_SetLength(obj, laslength*10);
		if(switch == check){
		ObjRender_SetBlendType(obj, BLEND_SUBTRACT);
		ObjShot_SetIntersectionEnable(obj, 0);
		}
		else{
		ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
		ObjShot_SetIntersectionEnable(obj, 1);
		}
		if(laslength < 100){laslength++;}
		yield;
		}
	}
}

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