#東方弾幕風[Single]
#ScriptVersion[3]
#Title["NS3"]
#Text["Kujiru uses Curvy [r]Lasers now"]
#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_SetPosition(objBoss, GetCommonData("BossX", 0), GetCommonData("BossY", 0));
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2-100, 5, 4);

	Initialization;
	
	Main;
	end;
} 

task Initialization{
	RenderKujiru(objBoss);
	MagicRing(objBoss);
	HitSound(objBoss,60,500);
	TimerCountdown;
	SetArmor(objBoss, [90, 80], 180);
	EnemyMarker(objBoss);
	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, 126, 255]);
}

task Main { 
wait(120);

let a = 1;
loop{
		loop(3){
		let ran = rand(-10, 10);
		ascent(i in -1..2){
			ascent(j in 0..11){
			let obj = FireShotA2(BossX, BossY, 5, ran+j*180/11+(16/2)+i*4, -0.1, 1, KNIFE_DBLUE, 10);
			}
		}
		ascent(i in 0..12){
		let obj = CreateCurveLaserA1(BossX, BossY, 5, ran+i*180/11, 18, 15, SLUG, 10);
		ObjMove_AddPatternA2(obj, 0, NO_CHANGE, NO_CHANGE, -0.2, 0, 1);
		ObjCrLaser_SetTipDecrement(obj, 0);
		Pinpoint(obj);
		a = -a;
		}
		PlaySound("lenlabullet", 75, 10);
		wait(100);
		}
		ascent(i in 0..16){
		let obj = CreateCurveLaserA1(BossX, BossY, 2, -i*180/16, 18, 15, SLUG, 10);
		ObjCrLaser_SetTipDecrement(obj, 0);
		ObjMove_AddPatternA2(obj, 30, NO_CHANGE, NO_CHANGE, 0.2, 1*a, 1);
		//ObjMove_AddPatternA2(obj, 60, NO_CHANGE, NO_CHANGE, -0.6, 1*-a, 1);
		Pinpoint(obj);
		a = -a;
		}
		PlaySound("lensmlaser", 75, 10);
		wait(270);
	}
	
	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);
	while(!Obj_IsDeleted(obj)){
	let angl = ObjMove_GetAngle(obj)%360;
	if(angl < GetAngleToPlayer(obj) + 3 && angl > GetAngleToPlayer(obj) - 3){Redirect(obj); break;}
	yield;
	}
	while(!Obj_IsDeleted(obj)){
	yield;
	}
	Obj_Delete(obj);
		task Redirect(obj){
		ObjMove_AddPatternA2(obj, 0, NO_CHANGE, NO_CHANGE, 0, 0, 10);
		ObjMove_AddPatternA2(obj, 30, 25, NO_CHANGE, 0.2, 0, 10);
		PlaySound("warning", 75, 0);
		PlaySound("lensmlaser", 60, 30);
		}
	}
}

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