#東方弾幕風[Single]
#ScriptVersion[3]
#Title["SP3"]
#Text["Kujiru using their ability?"]
#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-150, 5, 4);

	Initialization;
	
	Main;
	end;
} 

task Initialization{
	RenderKujiru(objBoss);
	MagicRing(objBoss);
	//WaveCircle(true, false, true, 156);
	HitSound(objBoss,60,500);
	TimerCountdown;
	SetArmor(objBoss, [90, 80], 180);
	EnemyMarker(objBoss);
	//ColorChange;
}

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(3000);}
	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 {
} 

let aim;

task Main { 
wait(45);
let path = GetCurrentScriptDirectory ~ "./default_system/img/Kujiru.png";
let path2 = GetCurrentScriptDirectory ~ "./default_system/img/GaraiyaKujiru.png";
SetCommonData("SP", "Kujiru");
SetCommonData("StgFrameColor", [0, 126, 255]);
SpellCard(180, "Slug Revenge &quot;Salt in the Wound&quot;", [25, 25, 200], path, path2, 0, 0, 1);

let a = 1;
ascent(i in 1..4){
let obj = Enemy(BossX, BossY);
RenderKujiru(obj);
Move(obj, 65*i, 7+(i*i)*i*2);
if(i == 1){Shoot1(obj, a);}
if(i == 2){Shoot2(obj, a);}
if(i == 3){Shoot3(obj, a);}
a = -a;
let obj2 = Enemy(BossX, BossY);
RenderKujiru(obj2);
Move(obj2, -65*i, 7+(i*i)*i*2);
if(i == 1){Shoot1(obj2, a);}
if(i == 2){Shoot2(obj2, a);}
if(i == 3){Shoot3(obj2, a);}
a = -a;
PlaySound("spirit", 75, 0);
wait(15);
}

Shoot0;
loop{
wait(60*3);
//ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+rand(-100, 100), GetStgFrameHeight/2-100, 5, 4);	
}

}

task Shoot0{
wait(180*2);
let a = 1;
	loop{
		ascent(j in 0..8){
			ascent(i in 0..2){
			let obj = CreateCurveLaserA1(BossX, BossY, 1, 90+90*a+j*12*a, 18, 15, SLUG, 10);
			ObjCrLaser_SetTipDecrement(obj, 0);
			ObjMove_AddPatternA2(obj, 30, NO_CHANGE, NO_CHANGE, 0.2, -2*a, 1);
			Pinpoint(obj);
			a = -a;
			}
		PlaySound("lensmlaser", 60, 0);
		wait(10);
		}
		wait(60*6);
	}
}

task Shoot1(obj, mult){
wait(60);
	loop{
	let ran = rand(0,360);
		ascent(j in 0..12){
		FireShotA1(GetX(obj), GetY(obj), 3, ran+j*360/12, S_BUBBLE_DBLUE, 15);
		}
	PlaySound("lenlabullet", 75, 0);
	wait(120);
	}
}
task Shoot2(obj, mult){
wait(60);
let a = 0;
	loop{
		ascent(j in 0..5){
			ascent(k in -1..2){
				FireShotA1(GetX(obj), GetY(obj), 2+1*sin(k*180+3), j*360/5+k*2+a*24*mult, KNIFE_DBLUE, 25);
			}
		}
	a++;
	PlaySound("lensmbullet", 65, 0);
	wait(45);
	}
}
task Shoot3(obj, mult){
wait(180);
	loop{
	let ran = rand(0,360);
		ascent(j in -6..6){
			let shot = CreateLooseLaserA1(GetX(obj), GetY(obj), 1, GetAngleToPlayer(obj)+j*12*mult, 400, 15, SS_LASER_DBLUE, 10);
			ObjMove_AddPatternA2(shot, 0, NO_CHANGE, NO_CHANGE, 0.02, 0, 10);
			wait(2);
		}
	PlaySound("lenlalaser", 75, 10);
	wait(60*6);
	}
}

task Move(obj, X, Y){
while(!Obj_IsDeleted(obj)){
ObjMove_SetDestAtWeight(obj, BossX+X, BossY+Y, 5, 6);
yield;
}
}
	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);
	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());
} 