#東方弾幕風[Single]
#ScriptVersion[3]
#Title["SP2"]
#Text["Not to be confused with[r]Danmaku Bounded Field"]
#System["./default_system/Default_System.txt"]
#Background["./default_System/Default_Background.txt"]
#include"./default_system/Default_Index.txt"

let objBoss;
	
let BossX;
let BossY;

@Initialize {
	SetPlayerClip(126, 12, 510, 468);
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2-100, 5, 4);

	Initialization;
	
	Main;
	end;
} 

task Initialization{
	//Monochrome;
	RenderGaraiya(objBoss);
	RenderGaraiyaNoShikigami(objBoss);
	MagicRing(objBoss);
	//WaveCircle(true, false, true, 156);
	HitSound(objBoss,60,500);
	TimerCountdown;
	SetArmor(objBoss, [90, 25], 180);
	EnemyMarker(objBoss);
}

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(4000);}
	case(EV_REQUEST_TIMER){SetScriptResult(60);}
	case(EV_REQUEST_SPELL_SCORE){SetScriptResult(10000);}
	//case(EV_REQUEST_IS_DURABLE_SPELL){SetScriptResult(true);}
	//case(EV_REQUEST_IS_LAST_SPELL){SetScriptResult(true);}
} 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	SetCommonData("BossX", BossX);
	SetCommonData("BossY", BossY);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),21);
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),24);
	yield;
} 

@Finalize {
} 


task Main { 
wait(60);
let path = GetCurrentScriptDirectory ~ "./default_system/img/Garaiya.png";
let path2 = GetCurrentScriptDirectory ~ "./default_system/img/Garaiya.png";
SetCommonData("SP", "Garaiya");
SetCommonData("StgFrameColor", [0, 255, 0]);
SpellCard(180, "Hero Card &quot;Orochimaru Slayer&quot;", [25, 200, 25], path, path2, 0, 150, 1);

let a = 1;

	let ran = rand(0,360);
		ascent(i in 0..5){
		let obj = CreateShotA1(BossX, BossY, 0.5, ran+i*360/5, LL4_BUBBLE_GREEN, 0);
		ObjMove_SetAngularVelocity(obj, 0.05*a);
		ObjShot_SetSpellResist(obj, 1);
		ObjShot_SetIntersectionEnable(obj, 0);
		ObjShot_SetAutoDelete(obj, 0);
		Rot(obj, a);
		Orb2(objBoss, obj, i*360/5, 1);
		Shoot(obj);
		}
		ascent(i in 0..5){
		let obj = CreateShotA1(BossX, BossY, 0.5, ran+i*360/5, LL4_BUBBLE_GREEN, 0);
		ObjMove_SetAngularVelocity(obj, 0.05*a);
		ObjShot_SetSpellResist(obj, 1);
		ObjShot_SetIntersectionEnable(obj, 0);
		ObjShot_SetAutoDelete(obj, 0);
		Rot(obj, -a);
		Orb2(objBoss, obj, i*360/5, -1);
		Shoot(obj);
		}
		PlaySound("lenlabullet", 60, 0);
		PlaySound("spirit", 60, 0);
	a = -a;
	wait(60*5);	
	loop{
	wait(60*3);
	ObjMove_SetDestAtWeight(objBoss, GetPlayerX, GetStgFrameHeight/2-125, 5, 4);	
	wait(60);
	}
}

	task Shoot(obj){
	wait(180);
	A;
		loop{
			let obj4 = FireShotA2(GetX(obj), GetY(obj), 12, GetAngleToPlayer(obj)+180, -0.6, -1.25, DB_BULLET_GREY, 15);
			PlaySound("lensmbullet", 70, 15);
			wait(30);
		}
		
		task A{
			loop{
			wait(180);
			let obj3 = CreateStraightLaserA1(GetX(obj), GetY(obj), GetAngleToPlayer(obj), 0, 20, 60, SS_LASER_GREY, 90);
			Length(obj3, 700, 90);
			Follow(obj3);
			PlaySound("warning", 60, 0);
			PlaySound("lenlalaser", 60, 90);
			}
			task Follow(obj3){
			loop{
			ObjMove_SetPosition(obj3, GetX(obj), GetY(obj));
			yield;
			}
			}
		}
	}

	task Rot(obj, mult){
		ascent(j in 0..5){
			let obj2 = FireShotA1(GetX(obj), GetY(obj), 0, 0, CL4_BULLET_GREEN, 120);
			Orb(obj, obj2, j*360/5, mult);
			ObjShot_SetSpellResist(obj2, 1);
			ObjShot_SetAutoDelete(obj2, 0);
		}
		
	}
		task Orb(obj, obj2, off, mult){
		let rad = 0;
		while(!Obj_IsDeleted(obj2) && !Obj_IsDeleted(obj)){
		ObjMove_SetPosition(obj2, GetX(obj)+rad*cos(off), GetY(obj)+rad*sin(off));
		if(rad < 30){rad += 0.1;}
		off+=1*mult;
		yield;
		}
		}
		task Orb2(obj, obj2, off, mult){
		let rad = 0;
		while(!Obj_IsDeleted(obj2) && !Obj_IsDeleted(obj)){
		ObjMove_SetDestAtWeight(obj2, GetPlayerX+rad*cos(off), GetPlayerY+rad*sin(off), 10, 10-rad/20);
		if(rad < 150){rad += 0.8;}
		off+=0.2*mult;
		yield;
		}
		}
		
task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
	NotifyEvent(GetStageID, EV_USER_STAGE, [true, true, true, false, false, false]); //smexplosion, smparticles, items, bigexplosion, bigparticles, shake+slow
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 