#東方弾幕風[Single]
#ScriptVersion[3]
#Title["NS2"]
#Text["Suddenly, Slugs"]
#System["./default_system/Default_System.txt"]
#Background["./default_System/Default_Background.txt"]
#include"./default_system/Default_Index.txt"

let objBoss;
let objEn;
let objEn2;
	
let BossX;
let BossY;

@Initialize {
	SetPlayerClip(126, 12, 510, 468);
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	objEn = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(objEn);
	objEn2 = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(objEn2);
	
	ObjMove_SetPosition(objEn, GetCommonData("BossX", 0), GetCommonData("BossY", 0));
	ObjMove_SetDestAtWeight(objEn, GetStgFrameWidth/2, GetStgFrameHeight/2-100, 5, 4);

	Initialization;
	
	Main;
	end;
} 

task Initialization{
	RenderGaraiya(objEn);
	RenderGaraiyaNoShikigami(objEn);
	MagicRing(objEn);
	HitSound(objEn,60,500);
	TimerCountdown;
	SetArmor(objEn, [90, 80], 180);
	EnemyMarker(objEn);
	ColorChange;
}

@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{
SetCommonData("StgFrameColor", [0, 255, 0]);
wait(60*6);
ascent(i in 0..64){
SetCommonData("StgFrameColor", [0, 255-i*2, 0+i*4]);
yield;
}
}

task Main { 
wait(120);

let obj = Spirit(GetX(objEn), GetY(objEn)-25);
let obj2 = Spirit(GetX(objEn)-20, GetY(objEn)-4);
GaraiyaSwitch;
	ascent(i in 0..7){
	Particle(GetX(objEn), GetY(objEn)-25, rand(1, 8), rand(0,360), 0.5, rand(0,360), "Cherry", [12, 255, 12], 4);
	Particle(GetX(objEn)-20, GetY(objEn)-4, rand(1, 8), rand(0,360), 0.5, rand(0,360), "Cherry", [12, 255, 12], 4);
	}
PlaySound("spirit", 60, 0);
wait(60);
ObjMove_SetDestAtWeight(obj, GetStgFrameWidth/2-125, GetStgFrameHeight/2-100, 8, 2);
ObjMove_SetDestAtWeight(obj2, GetStgFrameWidth/2+125, GetStgFrameHeight/2-100, 8, 2);
wait(90);
	ascent(i in 0..1){
	Vortex(GetX(obj2), GetY(obj2), 0.1, 0.06+i/50, 255, -10, [122, 122, 255], 6+i);}
	ascent(i in 0..10){
	Particle(GetX(obj2), GetY(obj2), rand(1, 8), rand(0,360), 0.5, rand(0,360), "Cherry", [122, 122, 255], 4);
	}
	ascent(i in 0..1){
	Vortex(GetX(obj), GetY(obj), 0.1, 0.06+i/50, 255, -10, [255, 122, 12], 6+i);}
	ascent(i in 0..10){
	Particle(GetX(obj), GetY(obj), rand(1, 8), rand(0,360), 0.5, rand(0,360), "Cherry", [255, 122, 12], 4);
	}
PlaySound("spirit", 60, 0);
ObjMove_SetPosition(objBoss, GetX(obj2), GetY(obj2));
ObjMove_SetPosition(objEn2, GetX(obj), GetY(obj));
RenderKujiru(objBoss);
RenderKaisen(objEn2);
Obj_Delete(obj); Obj_Delete(obj2);
	MagicRing(objBoss);
	MagicRing(objEn2);
	HitSound(objBoss,60,500);
	HitSound(objEn2,60,500);
	SetArmor(objBoss, [90, 80], 180);
	SetArmor(objEn2, [90, 80], 180);
	EnemyMarker(objBoss);
	EnemyMarker(objEn2);
	
	wait(60);
	ObjMove_SetDestAtWeight(objEn, -255, 0, 8, 2);
	ObjMove_SetDestAtWeight(objEn2, -255, 0, 8, 2);
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2-100, 8, 2);
	
	Pattern;
}

task Pattern{
wait(90);
Rings;
wait(120);
loop{
Spiral;
wait(60*9);
}
}

task Spiral{
	let ran = rand(0,360);
	ascent(i in 0..18){
		ascent(j in 0..5){
		CreateLooseLaserA1(BossX, BossY, 4, ran+j*360/5+i*(2+i/4), 140, 15, SS_LASER_DBLUE, 5);
		}
		PlaySound("lensmlaser", 35, 5);
		wait(6);
	}
	ran = rand(0,360);
	wait(60);
	ascent(i in 0..18){
		ascent(j in 0..5){
		CreateLooseLaserA1(BossX, BossY, 4, ran+j*360/5-i*(2+i/4), 140, 15, SS_LASER_DBLUE, 5);
		}
		PlaySound("lensmlaser", 35, 5);
		wait(6);
	}
	wait(30);
	ascent(i in 0..16){
	let obj = CreateCurveLaserA1(BossX, BossY, 2, i*360/16, 20, 15, SLUG, 10);
	ObjCrLaser_SetTipDecrement(obj, 0);
	ObjMove_AddPatternA2(obj, 30, NO_CHANGE, NO_CHANGE, 0.2, 2, 4);
	ObjMove_AddPatternA2(obj, 60, NO_CHANGE, NO_CHANGE, -0.6, -2, 1);
	ObjMove_AddPatternA2(obj, 150, NO_CHANGE, NO_CHANGE, 0.4, -0.2, 4);
	}
	PlaySound("lensmlaser", 60, 10);
	wait(60);
	ascent(i in 0..16){
	let obj = CreateCurveLaserA1(BossX, BossY, 2, i*360/16, 20, 15, SLUG, 10);
	ObjCrLaser_SetTipDecrement(obj, 0);
	ObjMove_AddPatternA2(obj, 30, NO_CHANGE, NO_CHANGE, 0.2, -2, 4);
	ObjMove_AddPatternA2(obj, 60, NO_CHANGE, NO_CHANGE, -0.6, 2, 1);
	ObjMove_AddPatternA2(obj, 150, NO_CHANGE, NO_CHANGE, 0.4, 0.2, 4);
	}
	PlaySound("lensmlaser", 60, 10);
}

	task Pinpoint(obj){
		Angle(obj);
		Laser(obj);	
	}
	task Laser(obj){
	let las = CreateStraightLaserA1(GetX(obj), GetY(obj), ObjMove_GetAngle(obj), 700, 25, 0, SS_LASER_GREY, 999999);
	let a = 0;
	while(!Obj_IsDeleted(obj)){
	ObjRender_SetAlpha(las, a);
	ObjMove_SetPosition(las, GetX(obj), GetY(obj));
	ObjStLaser_SetAngle(las, ObjMove_GetAngle(obj));
	if(a < 122){a += 2;}
	yield;
	}
	ObjShot_FadeDelete(obj);
	}
	task Angle(obj){
	wait(60);
	loop{
	let angl = ObjMove_GetAngle(obj)%360;
	if(angl < GetAngleToPlayer(obj) + 2 && angl > GetAngleToPlayer(obj) - 2){break;}
	yield;
	}
	ObjMove_AddPatternA2(obj, 0, 25, NO_CHANGE, 0.2, 0, 10);
	}

task Rings{
loop{
let ran = rand(0,360);
ascent(i in 0..24){
FireShotA1(BossX, BossY, 3, i*360/24+ran, KNIFE_DBLUE, 15);
FireShotA1(BossX, BossY, 3, i*360/24+ran+15/2, C_BULLET_DBLUE, 35);
}
PlaySound("lensmbullet", 75, 15);
PlaySound("lensmbullet", 75, 35);
wait(60);
}
}

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());
} 