#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["YukariSpell02"]
#Text["YukariSpell02"]
#BGM["./Overrate.mp3"]
#System["./NoobSystem/Default_System2.txt"]
#Background["./NoobSystem/Default_Background_IceMountain.txt"]
#Player["./Reisen/Reisen.txt"]

#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_yukari.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(3000);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(70);
	}
	case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(3500000);
	}
}

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

//----------------------------------------------------
task TWork
{
	yield;
	ObjMove_SetDestAtWeight(objEnemy, GetStgFrameWidth/2, 30, 10,60);
	DamageRateAtFrame(50, 25,300);
	let cutinimage = GetCurrentScriptDirectory~"null.png";
	ObjCutin_SetSpellcardS4("Border between Good and Evil", cutinimage, NAZRIN, 240, 104, 104);
	wait(30);
	objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);
	ObjCutin_LaunchS3(YABUSAME, cutinimage, "Normal");
	CreateLine;
	wait(60);
	PlaySound("Charge2",100,0);
	SakuraCharge("PURPLE");
	wait(60);
	YukariRedWave;
	wait(120);
	PlaySound("Charge2",100,0);
	SakuraCharge("PURPLE");
	wait(60);
	YukariBlueWave;
	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 1500){yield;}
	PlaySound("Charge2",100,0);
	SakuraCharge("PURPLE");
	wait(60);
	YukariCircleWave;
}

task YukariCircleWave
{
	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0)
	{
		PlaySound("BulletWave",100,0);
		ascent(i in 0..72)
		{
			CreateShotA2(GetEnemyX,GetEnemyY,1,i*5+GetAngleToPlayer(objEnemy),0.02,1.75,SMALL_RED+500,10);
		}
		wait(90);
		PlaySound("BulletWave",100,0);
		ascent(i in 0..72)
		{
			CreateShotA2(GetEnemyX,GetEnemyY,1,i*5+GetAngleToPlayer(objEnemy),0.02,1.75,SMALL_BLUE+500,10);
		}
		wait(90);
	}
}

task YukariRedWave
{
	let count = 0;
	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0)
	{
		PlaySound("Shot1",100,0);
		ascent(i in 0..12)
		{
			let angle = i*30+count/3+truncate(count/5)*4;
			CreateShotA2(GetEnemyX,GetEnemyY,4,angle,-4/60,2,BL_SMALL_RED+500,5);
		}
		count++;
		wait(5);
	}
}

task YukariBlueWave
{
	let count = 0;
	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0)
	{
		PlaySound("Shot1",100,0);
		ascent(i in 0..12)
		{
			let angle = i*30-count*1.5;
			CreateShotA2(GetEnemyX,GetEnemyY,4,angle,-4/60,2,BL_SMALL_BLUE+500,5);
		}
		count++;
		wait(5);
	}
}

task CreateLine
{
	let mainline = CreateStraightLaserA1(0,80,0,500,30,99999,ST_LASER_GRAY,99999);
	let count = 0;
	wait(120);
	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0)
	{
		LineLaser(count%2);
		count++;
		wait(120);
	}
	task LineLaser(c)
	{
		let lcolor = [ST_LASER_RED,ST_LASER_BLUE];
		let rc = [[128,0,0],[0,0,128]];
		let line = CreateStraightLaserA1(-30,80,0,500,10,99999,lcolor[c],0);
		ObjRender_SetColor(line,rc[c][0],rc[c][1],rc[c][2]);
		ObjMove_AddPatternA2(line,0,4,90,-4/15,0,0.75);
		ObjShot_SetIntersectionEnable(line,false);
		while(!Obj_IsDeleted(line) && ObjMove_GetY(line) < GetStgFrameHeight+1)
		{
			let shotarr = GetShotIdInCircleA2(GetEnemyX,GetEnemyY,600,TARGET_ENEMY);
			ascent(i in 0..length(shotarr))
			{
				if( (|ObjMove_GetY(line)-ObjMove_GetY(shotarr[i])|)<5) 
				{
					if(c==0)
					{
						if( (ObjShot_GetImageID(shotarr[i]) == BL_SMALL_RED+500) || (ObjShot_GetImageID(shotarr[i]) == SMALL_RED+500) )
						{
							Obj_SetVisible(shotarr[i],false);
							ObjShot_SetIntersectionEnable(shotarr[i],false);
						}
						else
						{
							Obj_SetVisible(shotarr[i],true);
							ObjShot_SetIntersectionEnable(shotarr[i],true);
						}
					}
					if(c==1)
					{
						if( (ObjShot_GetImageID(shotarr[i]) == BL_SMALL_BLUE+500) || (ObjShot_GetImageID(shotarr[i]) == SMALL_BLUE+500) )
						{
							Obj_SetVisible(shotarr[i],false);
							ObjShot_SetIntersectionEnable(shotarr[i],false);
						}
						else
						{
							Obj_SetVisible(shotarr[i],true);
							ObjShot_SetIntersectionEnable(shotarr[i],true);
						}
					}
				}
			}
			ObjShot_SetIntersectionEnable(line,false);
			yield;
		}
		Obj_Delete(line);
		
	}
}


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