#東方弾幕風[Single]
#ScriptVersion[3]
#Title["SP6"]
#Text["Oh wow cranes"]
#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);
	
	ObjMove_SetPosition(objBoss, GetCommonData("BossX", 0), GetCommonData("BossY", 0));
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2-100, 5, 4);

	Initialization;
	
	Spirits;
	
	Main;
	end;
} 

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

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(10000);}
	case(EV_REQUEST_TIMER){SetScriptResult(105);}
	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 Spirits{
let obj = Spirit(GetCommonData("BossX2", 200), GetCommonData("BossY2", 255));
let obj2 = Spirit(GetCommonData("BossX3", 300), GetCommonData("BossY3", 255));
PlaySound("spirit", 65, 0);
	ascent(i in 0..7){
	Particle(GetX(obj), GetY(obj), rand(1, 8), rand(0,360), 0.5, rand(0,360), "Cherry", [12, 255, 12], 4);
	Particle(GetX(obj2), GetY(obj2), rand(1, 8), rand(0,360), 0.5, rand(0,360), "Cherry", [12, 255, 12], 4);
	}
wait(60*2);
ObjMove_SetDestAtWeight(obj, BossX, BossY-25, 8, 2);
ObjMove_SetDestAtWeight(obj2, BossX-20, BossY-4, 8, 2);
wait(210);
SetCommonData("BossAlpha", 255);
SetCommonData("GaraiyaSwitch", 1);
PlaySound("spirit", 65, 0);
	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);
	}
Obj_Delete(obj); Obj_Delete(obj2);
}


task Main { 
wait(180);
let path = GetCurrentScriptDirectory ~ "./default_system/img/Garaiya.png";
let path2 = GetCurrentScriptDirectory ~ "./default_system/img/Garaiya.png";
SetCommonData("SP", "All");
SpellCard(180, "Ink Card &quot;The Three Headed Crane&quot;", [255, 255, 255], path, path2, 0, 0, 1);

wait(60);

KaisenShot;
wait(60*6);
let obj = Enemy(BossX, BossY);
RenderKujiru(obj);
Move(obj, BossX+170, BossY-100);
let obj2 = Enemy(BossX, BossY);
RenderKujiru(obj2);
Move(obj2, BossX-170, BossY-100);
KujiruShot(obj, 1); KujiruShot(obj2, -1);
wait(60*6);
GaraiyaShot;
}

task GaraiyaShot{
let a = 1;
loop{
	let obj = CreateShotA1(BossX, BossY, 0.5, GetAngleToPlayer(objBoss), 0, 0);
	ObjShot_SetSpellResist(obj, 1);
	ObjShot_SetIntersectionEnable(obj, 0);
	ObjShot_SetAutoDelete(obj, 0);
	Rot(obj, a);
	a = -a;
	Charge;
	PlaySound("lenlabullet", 75, 10);
wait(60*6);
}	
		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..8){
			let obj2 = FireShotA1(GetX(obj), GetY(obj), 0, 0, CL4_BULLET_GREEN, 10);
			Orb(obj, obj2, j*360/8, mult);
			Grow(obj2);
			ObjShot_SetAutoDelete(obj2, 0);
			ObjShot_SetSpellResist(obj2, 1);
		}
		
		task Grow(obj2){
		wait(60*4);
		PlaySound("warning", 60, 1);
		ObjShot_SetGraphic(obj2, SL4_BUBBLE_GREEN);
		wait(60*4);
		PlaySound("warning", 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.4*mult;
		yield;
		}
		}
	}
}

task Move(obj, X, Y){
while(!Obj_IsDeleted(obj)){
ObjMove_SetDestAtWeight(obj, X, Y, 5, 6);
yield;
}
}

task KujiruShot(obj, mult){
wait(180);
	loop{
		let ran = rand(0,360);
			ascent(j in -12..12){
				let shot = CreateLooseLaserA1(GetX(obj), GetY(obj), 1, GetAngleToPlayer(obj)+j*8*mult, 400, 15, SS_LASER_DBLUE, 10);
				ObjMove_AddPatternA2(shot, 0, NO_CHANGE, NO_CHANGE, 0.02, 0, 10);
				wait(2);
			}
		PlaySound("lenlalaser", 60, 10);
		wait(60*2);
	}
}

task KaisenShot{
let a = 0;
let b = 0;
loop{
	b++;
	ascent(i in 0..3){
	let c = CreateShotA1(BossX, BossY-30, 6, (GetAngleToPoint(BossX, BossY, GetCenterX, GetCenterY))+(120*sin(a*4))+i*12, DB_BULLET_GREY, 10);
	ObjRender_SetColor(c, 255, 85, 0);
	let d = CreateShotA1(BossX, BossY-30, 6, (GetAngleToPoint(BossX, BossY, GetCenterX, GetCenterY))-(120*sin(a*4))-i*12, DB_BULLET_GREY, 10);
	ObjRender_SetColor(d, 255, 85, 0);
	Curve(c, 1); Curve(d, -1);
	if(b == 4){ObjRender_SetColor(c, 255, 255, 255); ObjRender_SetColor(d, 255, 255, 255); ReflectX(d, 1); ReflectX(c, 1);}
	}
	//PlaySound(GetCurrentScriptDirectory ~ "default_system/se/smbullet.wav", 65, 0);
	a++;
	if(b == 4){b = 0;}
	PlaySound("lensmbullet", 30, 10);
	wait(2);
}

task ReflectX(obj, time){
	let count = 0;
	while(!Obj_IsDeleted(obj) && count < time){
		if(GetX(obj) < GetStageLeft){
		ObjMove_SetX(obj,GetStageLeft);
		ObjMove_AddPatternA2(obj, 0, 2, 180 - ObjMove_GetAngle(obj), 0.01, 0, 10);
		PlaySound("spirit", 45, 1);
		count++;
		}
	else{}
		if(GetX(obj) > GetStageRight){
		ObjMove_SetX(obj,GetStageRight);
		ObjMove_AddPatternA2(obj, 0, 2, 180 - ObjMove_GetAngle(obj), 0.01, 0, 10);
		PlaySound("spirit", 45, 1);
		count++;
		}
	else{}
	yield;
	}
}

task Curve(obj, mult){
	while(ObjMove_GetSpeed(obj) > 5){
	ObjMove_SetAngularVelocity(obj, 4*mult);
	wait(45/2);
	ObjMove_SetAngularVelocity(obj, -4*mult);
	wait(45/2);
	}
	ObjMove_SetAngularVelocity(obj, 0);
	}
}

task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
	StartSlow(TARGET_ALL, 25);
	ascent(i in 0..25){
	Particle(GetCommonData("BossX", 0), GetCommonData("BossY", 0), rand(1, 8), rand(0,360), 0.5, rand(0,360), "Cherry", GetCommonData("StgFrameColor", [255, 255, 255]), 4);	
	yield;
	}
	Vortex(GetCommonData("BossX", 0), GetCommonData("BossY", 0), 0.1, 0.12, 255, -25, GetCommonData("StgFrameColor", [255, 255, 255]), 6); PlaySound("explodebig",255,0);
	ascent(i in 0..25){
	Particle(GetCommonData("BossX", 0), GetCommonData("BossY", 0), rand(1, 8), rand(0,360), 0.5, rand(0,360), "Cherry", GetCommonData("StgFrameColor", [255, 255, 255]), 4);	
	yield;
	}
	Vortex(GetCommonData("BossX", 0), GetCommonData("BossY", 0), 0.1, 0.12, 255, -25, GetCommonData("StgFrameColor", [255, 255, 255]), 6); PlaySound("explodebig",255,0);
	ascent(i in 0..25){
	Particle(GetCommonData("BossX", 0), GetCommonData("BossY", 0), rand(1, 8), rand(0,360), 0.5, rand(0,360), "Cherry", GetCommonData("StgFrameColor", [255, 255, 255]), 4);	
	yield;
	}	
	NotifyEvent(GetStageID, EV_USER_STAGE, [false, false, true, true, true, true]); //smexplosion, smparticles, items, bigexplosion, bigparticles, shake+slow
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 