#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["MimaSpell01"]
#Text["MimaSpell01"]
#BGM["./Novum.mp3"]
#System["./NoobSystem/Default_System2.txt"]
#Background["./NoobSystem/Default_Background_IceMountain.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 objScene;
@Initialize
{
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	ObjEnemy_SetDamageRate(objEnemy, 0, 0);
	TWork;
	TAnimate("Mima",GetCurrentScriptDirectory~"dot_mima.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(3500000);
	}
}

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

//----------------------------------------------------
task TWork
{
	yield;
	ObjMove_SetDestAtWeight(objEnemy, GetStgFrameWidth/2, 120, 10,60);
	DamageRateAtFrame(50, 25,120);
	let cutinimage = GetCurrentScriptDirectory~"null.png";
	ObjCutin_SetSpellcardS4("Dancing of Stars", cutinimage, NAZRIN, 240, 104, 104);
	wait(30);
	objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);
	ObjCutin_LaunchS3(YABUSAME, cutinimage, "Normal");
	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0)
	{
		wait(60);
		PlaySound("Charge2",100,0);
		SakuraCharge("PURPLE");
		wait(60);
		StarWave;
		wait(180);
		BorderMove(120,GetStgFrameWidth-120,90,150,10,10);
		wait(60);
	}
}

task StarWave
{
	BurstWave;
	PlaySound("BulletWave2",100,0);
	descent(n in 0..7)
	{
		PlaySound("Shot1",100,0);
		PlaySound("BulletWave",95,60);
		MiniStar(n,(n%2-0.5)*2);
		wait(10+n*5);
	}
	task MiniStar(num,type)
	{
		let color = [165,167,169,171,174,175,163];
		let randangle = rand(0,24);
		ascent(i in 0..15)
		{
			ascent(j in 0..4)
			{
				let degree = 6-num/1.5;
				let v = degree+j*degree/8;
				let obj = CreateShotA2(GetEnemyX,GetEnemyY,v,i*24+randangle+j*2.25*type,-v/60,0,color[num],6);
				ObjMove_AddPatternA2(obj,60,NO_CHANGE,ObjMove_GetAngle(obj)+180,v/150,0,v);
				Immune(obj);
			}
		}
	}
}

task BurstWave
{
	ascent(i in 0..8)
	{
		ascent(j in -0..1)
		{
			ascent(k in 0..7)
			{
				CreateShotA1(GetEnemyX,GetEnemyY,1+k/3,i*45+j*3+GetAngleToPlayer(objEnemy),743+k,8);
			}
		}
	}
}

task Immune(obj)
{
	ObjShot_SetAutoDelete(obj,false);
	wait(300);
	ObjShot_SetAutoDelete(obj,true);
}

//BorderMove(90,GetStgFrameWidth-90,90,150,10,90);

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