#include "./shot/AllStarShot_Const.txt"
#include "./resources/BloomFX.txt"
#include "./resources/Gizmo's Sprite Library/GizmoSpriteLibrary.txt"
#include "./DLS's System.txt"

let objBoss;
let objScene = GetEnemyBossSceneObjectID();

let shot_sound = GetCurrentScriptDirectory ~ "./SFX/se_shot.wav";
let charm_sound = GetCurrentScriptDirectory ~ "./SFX/se_charm.wav";
let spell_sound = GetCurrentScriptDirectory ~ "./SFX/se_UseSpell.wav";
let explosion = GetCurrentScriptDirectory ~ "./SFX/se_explosion.wav";

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(6500);
	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(72);
	}
}

@Initialize
{
	if(GetCommonData("mode", 1) == 1)
	{
		CallWeather;
	}
	if(GetCommonData("mode", 1) == 2)
	{
		CallWeatherBackground(5);
	}

	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);

	ObjEnemy_SetDamageRate(objBoss, 0, 0);

	renderYuukaPoFV(objBoss, 1);

	LoadSound(shot_sound);
	LoadSound(charm_sound);
	LoadSound(spell_sound);
	LoadSound(explosion);

	TFinalize;
	TaskManager;
}

task TaskManager
{
	ObjMove_SetDestAtWeight(objBoss, 320, 120, 15, 6);
	RenderDown;
	BFX_ExplosionA2(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 350, GetCurrentScriptDirectory~"./img/Leaf.png", GetCurrentScriptDirectory~"./img/Ring.png", 10);
	wait(91);
	DeleteShotAll(TYPE_ALL,TYPE_IMMEDIATE);
	wait(89);
	SetSpellName("Flower Sign &quot;Flowering Garden of Sunflowers&quot;");
	SpellBG;
	PlaySE(spell_sound);
	wait(180);
	Shoot;
}

task Shoot
{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>1)
	{
		let angleT = GetAngleToPlayer(objBoss)-90;
		let obj;
		let wow = 1.2;
		loop(5)
		{
			loop(2)
			{
				obj = CreateShotA2(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 6, angleT, -0.25, 0.5, YUUKA_FLOWER, 0);
				ObjShot_SetIntersectionEnable(obj, false);
				ObjShot_SetSpellResist(obj, true);
				Explode(obj, 16, 1.5, 0.25);
				angleT+=360/2;
				PlaySE(shot_sound);
				wait(15);
		  	}
			wait(1);
		}
		ObjMove_SetDestAtWeight(objBoss, 320, 150, 15, 6);
		wait(180);
		loop(32)
		{
			obj = CreateShotA2(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), wow, angleT, -0.25, 0.5, YUUKA_FLOWER, 0);
			ObjShot_SetIntersectionEnable(obj, false);
			ObjShot_SetSpellResist(obj, true);
			Explode(obj, 12, wow/1.5, 0);
			angleT+=360/16;
			wow+=0.2;
			PlaySE(shot_sound);
			wait(15);
		}
		ObjMove_SetDestAtWeight(objBoss, 320, 240, 15, 6);
		wait(180);
		loop(8)
		{
			obj = CreateShotA2(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 10, angleT, -0.25, 0.5, YUUKA_FLOWER, 0);
			ObjShot_SetIntersectionEnable(obj, false);
			ObjShot_SetSpellResist(obj, true);
			Explode(obj, 6, 1.5, 0.25);
			angleT+=360/8;
			PlaySE(shot_sound);
		}
		wait(180);
		loop(12)
		{
			obj = CreateShotA2(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 10, angleT, -0.25, 0.5, YUUKA_FLOWER, 0);
			ObjShot_SetIntersectionEnable(obj, false);
			ObjShot_SetSpellResist(obj, true);
			Explode(obj, 6, 1.5, 0.25);
			angleT+=360/12;
			PlaySE(shot_sound);
		}
		wait(180);
		loop(16)
		{
			obj = CreateShotA2(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 10, angleT, -0.25, 0.5, YUUKA_FLOWER, 0);
			ObjShot_SetIntersectionEnable(obj, false);
			ObjShot_SetSpellResist(obj, true);
			Explode(obj, 6, 1.5, 0.25);
			angleT+=360/16;
			PlaySE(shot_sound);
		}
		ObjMove_SetDestAtWeight(objBoss, 320, 120, 15, 6);
		wait(360);
	}
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		let angleT = GetAngleToPlayer(objBoss)-90;
		let obj;
		let wow = 5;
		ObjMove_SetDestAtWeight(objBoss, 320, 150, 15, 6);
		loop(32)
		{
			obj = CreateShotA2(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), wow/4, angleT, -0.25, 0.5, YUUKA_FLOWER, 0);
			ObjShot_SetIntersectionEnable(obj, false);
			ObjShot_SetSpellResist(obj, true);
			Explode(obj, wow, 2, 0);
			angleT+=360/16;
			wow+=0.5;
			PlaySE(shot_sound);
			wait(7);
		}
	}
}

task Explode(obj, density, speed, curve)
{
	let angleT = rand(0,11);
	let ball;
	let ball2;
	wait(90);
	loop(density)
	{
		ball = CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), speed, angleT, BL_SMALL_YELLOW, 30);
		ball2 = CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), speed, angleT, BL_SMALL_RED, 30);
		ObjMove_SetAngularVelocity(ball, curve);
		ObjMove_SetAngularVelocity(ball2, -curve);
		angleT+=360/density;
	}
	PlaySE(charm_sound);
	Obj_Delete(obj);
}

task TFinalize
{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
	Obj_Delete(objBoss);
	loop(90)
	{
		DeleteShotAll(TYPE_ALL,TYPE_IMMEDIATE);
		yield;
	}
	SetAutoDeleteObject(true);
	CloseScript(GetOwnScriptID());
	return;
}

@MainLoop
{
        ObjEnemy_SetIntersectionCircleToShot(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 32);
        ObjEnemy_SetIntersectionCircleToPlayer(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 24);
	if(GetPlayerLife == -1)
	{
		RenderKnockout;
	}
        yield;
}

function GetCenterX
{
	return GetStgFrameWidth/2;
}
function GetCenterY
{
	return GetStgFrameHeight/2;
}
function wait(n)
{
	loop(n){yield;}
}