#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["YukaSpell01"]
#Text["YukaSpell01"]
#Background["./NoobSystem/Default_Background_IceMountain.txt"]
#BGM["./Novum.mp3"]
#System["./NoobSystem/Default_System2.txt"]
#Player[DEFAULT]

#include"./Shot/AllStarShot_Const.dnh"
#include"./NoobSystem/Default_Effect.txt"
#include"./Function/Basic.txt"
#include"./Function/SoundFunctions.txt"
#include"./Function/EffectFunctions.txt"
#include"./Animations.txt"
#include"./Cutin/Cutin.txt"

let objEnemy;
let cx = GetStgFrameWidth/2;
let ct = GetStgFrameHeight/2;
let cswap = false;
let cstart = false;
let bossbullet = false;
let objScene;
@Initialize
{
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	ObjEnemy_SetDamageRate(objEnemy, 0, 0);
	TWork;
	TAnimate("Yuka",GetCurrentScriptDirectory~"dot_yuka.png");
	TEnd;
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
}

@MainLoop
{
	ObjEnemy_SetIntersectionCircleToPlayer(objEnemy,ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),18);
	ObjEnemy_SetIntersectionCircleToShot(objEnemy,ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),24);
	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(2000);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);
	}
	case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(3000000);
	}
}

//----------------------------------------------------

task TWork
{
	yield;
	ObjMove_SetDestAtWeight(objEnemy, GetStgFrameWidth/2, 120, 10,10);
	DamageRateAtFrame(50, 25,120);
	let cutinimage = GetCurrentScriptDirectory~"null.png";
	ObjCutin_SetSpellcardS4("Dual Spark", cutinimage, NAZRIN, 240, 104, 104);
	wait(30);
	objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);
	ObjCutin_LaunchS3(YABUSAME, cutinimage, "Normal");
	wait(60);
	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0)
	{
	PlaySound("Charge3",100,0);
	SakuraCharge2("YELLOW");
	TAction(360,5);
	DualSpark;
	wait(420);
	BorderMove(90,GetStgFrameWidth-90,90,150,10,5);
	wait(120);
	DamageRateAtFrame(60, 25,0);
	}
}

task DualSpark
{
	let angle = GetPointAngle(GetPlayerX,GetPlayerY,GetEnemyX,GetEnemyY+20);
	ascent(i in -3..4)
	{
		PreLaser(angle+i*7);
	}
	wait(120);
	PlaySound("Laser7",100,0);
	Spark(1);
	Spark(-1);
	ScreenShake(250);
	wait(60);
	YellowWave;
	task YellowWave
	{
		let color = [19,31,30,27,24,23,21];
		ascent(n in 0..10)
		{
			ascent(i in 0..15)
			{
				CreateShotA1(GetEnemyX,GetEnemyY+20,3.5,i*24+n*17,color[n%7],0);
				CreateShotA1(GetEnemyX,GetEnemyY+20,2,i*24-n*17,color[6-n%7],0);
				CreateShotA1(GetEnemyX,GetEnemyY+20,1,i*24-n*7,color[6-n%7],0);
			}
			wait(20);
		}
	}
	task PreLaser(angle)
	{
		let laser = CreateStraightLaserA1(GetEnemyX,GetEnemyY+20,angle,0,30,0,1016,180);
		ascent(i in 0..60)
		{
			ObjLaser_SetLength(laser,i*10);
			yield;
		}
	}
	task Spark(w)
	{
		let color = [1042,1048,1047,1046,1045,1044,1043];
		ascent(i in 15..55)
		{
			ascent(j in -2..3)
			{
				CreateLooseLaserA1(GetEnemyX,GetEnemyY+20,15,angle+j*6+(i/1.75)*w,200,100,color[i%7],30);
			}
			wait(5);
		}
	}
}

				task ScreenShake(time){
				loop(time/2){
				Set2DCameraFocusX(Get2DCameraX + rand(-3, 3));
				Set2DCameraFocusY(Get2DCameraY + rand(-3, 3));
				yield;
				Reset2DCamera;
				yield;
				}
				Reset2DCamera;
			}

//----------------------------------------------------
task TEnd
{
	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0)
	{
		yield;
	}

	let ex = ObjMove_GetX(objEnemy);
	let ey = ObjMove_GetY(objEnemy);
	TExplosionA(ex, ey, 10, 0.6);
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	Obj_Delete(objEnemy);
	if(ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT) +ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT) == 0)
	{
		AddScore(ObjEnemyBossScene_GetInfo(objScene,INFO_SPELL_SCORE));
	}
	loop(30)
	{
		DeleteShotAll(TYPE_ALL, TYPE_IMMEDIATE);
		yield;
	}

	CloseScript(GetOwnScriptID());
}
