#東方弾幕風[Single]
#ScriptVersion[3]
#Title["SP1"]
#Text["Inb4[r]Fujiyama volcano"]
#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, "Battle Card &quot;Wind, Forest, Fire, Mountain&quot;", [25, 200, 25], path, path2, 0, 150, 1);
Lasers;
wait(120);
let a = 1;
	loop{
	let ran = rand(0,360);
		ascent(i in 0..1){
		let obj = CreateShotA1(BossX, BossY, 0, 0, 0, 0);
		ObjMove_SetAngularVelocity(obj, 0.05*a);
		ObjShot_SetSpellResist(obj, 1);
		ObjShot_SetIntersectionEnable(obj, 0);
		ObjShot_SetAutoDelete(obj, 0);
		ObjMove_SetDestAtWeight(obj, GetPlayerX, GetPlayerY, 5, 5);
		Rot(obj, a, 1, SL4_BUBBLE_GREEN);
		Rot(obj, -a, 1.5, CL4_BULLET_GREEN);
		a = -a;
		PlaySound("lenlabullet", 75, 10);
		wait(30);
		}
	wait(60*3);
	ran = rand(0,360);
		ascent(i in 0..2){
		let obj = CreateShotA1(BossX, BossY, 0, 0, 0, 0);
		ObjMove_SetAngularVelocity(obj, 0.05*a);
		ObjShot_SetSpellResist(obj, 1);
		ObjShot_SetIntersectionEnable(obj, 0);
		ObjShot_SetAutoDelete(obj, 0);
		ObjMove_SetDestAtWeight(obj, GetPlayerX, GetPlayerY, 5, 5);
		Rot(obj, a, 1, SL4_BUBBLE_GREEN);
		Rot(obj, -a, 1.5, CL4_BULLET_GREEN);
		a = -a;
		PlaySound("lenlabullet", 75, 10);
		wait(60);
		}
	wait(60*4);
	}
}

task Lasers{
wait(60*6);
let a = 0;
	loop{
	let ang = GetAngleToPlayer(objBoss);
	let obj = CreateStraightLaserA1(BossX, BossY, ang+120*sin(a*5), 0, 25, 20, SS_LASER_GREY, 90);
	Length(obj, 500, 30);
	a++;
	PlaySound("lensmlaser", 25, 90);
	wait(3);
	}
}

	task Rot(obj, mult, spd, graph){
		ascent(j in 0..12){
			let obj2 = FireShotA1(GetX(obj), GetY(obj), 0, 0, graph, 120);
			Orb(obj, obj2, j*360/12, spd, mult);
		}
		wait(120);
		PlaySound("spirit", 60, 0);
		ascent(i in 0..5){
		Particle(GetX(obj), GetY(obj), rand(0.5, 3), rand(0,360), 0.25, rand(0,360), "Cherry", [255, 255, 255], 4);
		}
	
		task Orb(obj, obj2, off, spd, mult){
		let rad = 10*spd*3;
		let a = 0;
		let b = 0;
		while(!Obj_IsDeleted(obj2) && !Obj_IsDeleted(obj)){
		ObjMove_SetPosition(obj2, GetX(obj)+rad*cos(off), GetY(obj)+rad*sin(off));
		if(a > 120){
			if(b < spd){
			rad+=b;
			b+=0.05
			}
			if(b > spd){
			rad+=b;
			}
		}
		off+=0.4*mult;
		a++;
		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());
} 