#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["SP2"]
#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("Hunting Sign &quot;Soul Trap&quot;", [25, 255, 255], GetCurrentScriptDirectory ~ "./default_system/img/Ingame/sarakiel_01.png", 0);
	wait(30);
	ascent(i in 0..22){
	let obj = CreateStraightLaserA1(-50, -10+i*36, 0, 0, 15, 9999999, BEAM_ORANGE, 90);
	let obj2 = CreateStraightLaserA1(-10+i*36, -50, 90, 0, 15, 9999999, BEAM_ORANGE, 90);
	Rotate(obj, -1, false);
	Rotate(obj2, 1, true);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/laser2.wav", 60);
	wait(2);
	}
Bullets;
wait(120);
loop{
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(7);
}
PhantomEye(120);
wait(220);
}

task Bullets{
let dir = 0;
let switcheroo = 1;
wait(60);
	loop{
	ascent(j in 0..2){
	let switch = GetCommonData("Phantom", false);
		if(switch == false){
			ascent(i in 0..11){
			CreateShotA1(-10+i*(36*2)+16+j*36, -10, 1, 90, BALL_M_YELLOW, 15);
			}
		}
		if(switch == true && dir == 1){
			ascent(i in 0..11){
			CreateShotA1(-10, -10+i*(36*2)+16+j*36, 1, 0, BALL_M_YELLOW, 15);
			}
			switcheroo = 0;
		}
		if(switch == true && dir == 0){
			ascent(i in 0..11){
			CreateShotA1(GetStgFrameWidth+10, -10+i*(36*2)+16+j*36, 1, 180, BALL_M_YELLOW, 15);
			}
			switcheroo = 1;
		}
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/labullet.wav", 60);
		wait(60);
	}
	if(switcheroo == 1){dir = 1;}
	if(switcheroo == 0){dir = 0;}
	}
}
	task Shoot(obj, check){
	while(!Obj_IsDeleted(obj)){
	let switch = GetCommonData("Phantom", false);
		if(switch != check){
			ascent(j in 0..2){
				ascent(i in 0..3){
				let shot = CreateShotA2(ObjMove_GetX(obj)+255*cos(ObjStLaser_GetAngle(obj)), ObjMove_GetY(obj)+255*sin(ObjStLaser_GetAngle(obj)), 0.5, ObjStLaser_GetAngle(obj)+(180*j)-10+(i*10), 0.01, 10, RICE_S_ORANGE, 5);
				ObjRender_SetBlendType(shot, BLEND_ADD_ARGB);
				}
			}
		}
		wait(14);
	}
	}
	task Rotate(obj, num, 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());
} 