#東方弾幕風[Single]
#ScriptVersion[3]
#Title["NS1"]
#Text["No, This isn't[r]a 3d sphere"]
#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, 80], 180);
	EnemyMarker(objBoss);
}

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(6000);}
	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 ColorChange{
wait(120);
ascent(i in 0..64){
SetCommonData("StgFrameColor", [255-i*4, 255, 255-i*4]);
yield;
}
}

task Main { 
SetCommonData("BackgroundSpeed", 4);
wait(120);

let a = 1;
	loop{
	let ran = rand(0,360);
		ascent(i in 0..12){
		let obj = CreateShotA1(BossX, BossY, 0.5, ran+i*360/12, 0, 0);
		ObjMove_SetAngularVelocity(obj, 0.05*a);
		ObjShot_SetSpellResist(obj, 1);
		ObjShot_SetIntersectionEnable(obj, 0);
		ObjShot_SetAutoDelete(obj, 0);
		Rot(obj, a);
		}
	Charge;
	PlaySound("lenlabullet", 75, 15);
	a = -a;
	wait(60*5);
		ascent(k in 0..8){
		let ran = rand(0,360);
			ascent(i in 0..4){
				ascent(j in 0..24){
				FireShotA1(BossX, BossY, 2.5, j*360/24+ran, DB_BULLET_GREEN, 15);
				}
			PlaySound("lensmbullet", 75, 10);
				wait(5);
			}
			wait(10);
		}
	wait(60*4);
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+rand(-100, 100), GetStgFrameHeight/2-100, 5, 4);	
	wait(60);
	}
}

	task Charge{
	wait(60*3);
	Vortex(BossX, BossY, 2, -0.06, 122, -5, [5, 255, 5], 6);
	PlaySound("charge", 80, 0);
	wait(60*4);
	Vortex(BossX, BossY, 2, -0.06, 122, -5, [5, 255, 5], 6);
	PlaySound("charge", 80, 0);
	}

	task Rot(obj, mult){
		ascent(j in 0..14){
			let obj2 = FireShotA1(GetX(obj), GetY(obj), 0, 0, CL4_BULLET_GREEN, 10);
			Orb(obj, obj2, j*360/14, mult);
			Grow(obj2);
		}
		
		task Grow(obj2){
		wait(60*4);
		PlaySound("spirit", 60, 1);
		ObjShot_SetGraphic(obj2, SL4_BUBBLE_GREEN);
		wait(60*4);
		PlaySound("spirit", 60, 1);
		ObjShot_SetGraphic(obj2, LL4_BUBBLE_GREEN);
		}
		
		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 < 200){rad += 0.5;}
		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());
} 