#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["YukariS10"]
#Text["Fantasy Border 'Boundary of Life and Death -Phantasmal Dream-', Yukari's PCB Spell Card, but harder version."]
#Player["./Hecatia/Hecatia.txt"]
#System["./system/Default_System.txt"]
#Background["./BG.txt"]
#include"./Functions/Index.txt"
#include"./SetBoss.txt"
#include"./Shot/AllStarShot_Const.dnh"
#include"./system/Default_Effect.Txt"


let objBoss;
let GCSD=GetCurrentScriptDirectory~"";
let enemy;
let bSpell=false;
let stgx=GetStgFrameWidth()/2;
let stgy=GetStgFrameHeight()/2;
let idle = true;
let atk = false;
let fog = 0;
let action = false;
let objScene=GetEnemyBossSceneObjectID();
let color = [276,277,278];
let color2 = [51,53,55];
let dcolor = [308,309,310];
@Initialize
{
SetBoss("Yukari",true);
}

@MainLoop
{
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),18);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),26);
	yield;

}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(10000);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(300);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(99000000);
	}
}

//----------------------------------------------------
task mainTask{
	StartCountDown;
	ObjRender_SetAlpha( objBoss, 255 );
	ObjMove_SetPosition( objBoss, stgx, 120 );
 	SetCommonData("ForceLifebar",0);
	wait( 150 );
	//ObjPlayer_ClearIntersection(GetPlayerObjectID);
	YukariCircle(objBoss,1,-1);
	Cutin("Fantasy Border 'Boundary of Life and Death -Phantasmal Dream-'",10,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	Sound(GCSD ~ "Butterfly.mp3");
	wait(105);
	TShot1;
	wait(120);
	DamageRateAtFrame(40,0,0);
	}
//----------------------------------------------------

task TShot1
{
	if( ObjEnemy_GetInfo( objBoss, INFO_LIFE ) <= 31 ){ DeleteShotAll( TYPE_ALL, TYPE_IMMEDIATE ); }
	attack(180);
	let r = 70;
	let angle = rand(0,80);
	let dir = 0;
	let s = 1;
	wait( 30 );
	maple;
	wait( 80 );
	Pattern;
	wait( 1000 );
	PatternMoving;

	if( ObjEnemyBossScene_GetInfo( objScene, INFO_TIMER ) <= 20 ){ 
	Pattern2;
	Pattern3;
	Pattern4;
	Pattern5;
	Pattern6;
	Pattern7;
	Pattern8;
	}
}

              task PatternMoving{
              while( !Obj_IsDeleted( objBoss )){
              	TMovement(20,4,0.8);
              	wait( 1000 );
		}
	}

	task Pattern{
                	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 10000){ yield; }
	Pattern1;

                	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 8500){ yield; }
	maple2;
	Pattern2;

                	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 7500){ yield; }
	maple2;
	Pattern3;

                	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 6000){ yield; }
	maple2;
	Pattern4;

                	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 4500){ yield; }
	maple2;
	Pattern5;

                	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 3000){ yield; }
	maple2;
	Pattern6;

                	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 1500){ yield; }
	maple2;
	Pattern7;

               	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 800){ yield; }
	maple2;
	Pattern8;

	}
	


              task Pattern1{ 
              let angle = 230;
              while( !Obj_IsDeleted( objBoss )){

	                		let way = 1;
			let speed = 1.8;
			let shote = 55;
			let delay = 20;
			loop( way ){

				let sx = ObjMove_GetX( objBoss );
				let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				let sht2 = TShotA2( sx, sy, speed, angle + 120/7, 0, speed, shote, delay );
				let sht3 = TShotA2( sx, sy, speed, angle + (120/7)*2, 0, speed, shote, delay );
				let sht4 = TShotA2( sx, sy, speed, angle + (120/7)*3, 0, speed, shote, delay );
				let sht5 = TShotA2( sx, sy, speed, angle + (120/7)*4, 0, speed, shote, delay );
				let sht6 = TShotA2( sx, sy, speed, angle + (120/7)*5, 0, speed, shote, delay );
				let sht7 = TShotA2( sx, sy, speed, angle + (120/7)*6, 0, speed, shote, delay );

                                			ObjShot_SetSpellResist( sht1, true );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

                                			ObjShot_SetSpellResist( sht2, true );
				NotifyEventAll( EV_USER + 40, [ sht2, delay ] );

                                			ObjShot_SetSpellResist( sht3, true );
				NotifyEventAll( EV_USER + 40, [ sht3, delay ] );

                                			ObjShot_SetSpellResist( sht4, true );
				NotifyEventAll( EV_USER + 40, [ sht4, delay ] );

                                			ObjShot_SetSpellResist( sht5, true );
				NotifyEventAll( EV_USER + 40, [ sht5, delay ] );

                                			ObjShot_SetSpellResist( sht6, true );
				NotifyEventAll( EV_USER + 40, [ sht6, delay ] );

                                			ObjShot_SetSpellResist( sht7, true );
				NotifyEventAll( EV_USER + 40, [ sht7, delay ] );

				angle += 360 / way;
			}
                        		angle += 14.8;
			PlaySound("LenenShot1",92,0);
                        		wait( 10 );
	}

   }

              task Pattern2{ 
              let angle = 280;
              while( !Obj_IsDeleted( objBoss )){

	                		let way = 1;
			let speed = 1.5;
			let shote = 293;
			let delay = 10;
			loop( way ){

				let sx = ObjMove_GetX( objBoss );
				let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				let sht2 = TShotA2( sx, sy, speed, angle + 50/5, 0, speed, shote, delay );
				let sht3 = TShotA2( sx, sy, speed, angle + (50/5)*2, 0, speed, shote, delay );
				let sht4 = TShotA2( sx, sy, speed, angle + (50/5)*3, 0, speed, shote, delay );
				let sht5 = TShotA2( sx, sy, speed, angle + (50/5)*4, 0, speed, shote, delay );


                                			ObjShot_SetSpellResist( sht1, true );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

                                			ObjShot_SetSpellResist( sht2, true );
				NotifyEventAll( EV_USER + 40, [ sht2, delay ] );

                                			ObjShot_SetSpellResist( sht3, true );
				NotifyEventAll( EV_USER + 40, [ sht3, delay ] );

                                			ObjShot_SetSpellResist( sht4, true );
				NotifyEventAll( EV_USER + 40, [ sht4, delay ] );

                                			ObjShot_SetSpellResist( sht5, true );
				NotifyEventAll( EV_USER + 40, [ sht5, delay ] );


				angle += 360 / way;
			}
                        		angle -= 20;
			PlaySound("LenenShot1",92,0);
                        		wait( 10 );
	}

   }

              task Pattern3{ 
              let angle = 130;
              while( !Obj_IsDeleted( objBoss )){

	                		let way = 1;
			let speed = 1.3;
			let shote = 823;
			let delay = 10;
			loop( way ){

				let sx = ObjMove_GetX( objBoss );
				let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				let sht2 = TShotA2( sx, sy, speed, angle + 18, 0, speed, shote, delay );

                                			ObjShot_SetSpellResist( sht1, true );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

                                			ObjShot_SetSpellResist( sht2, true );
				NotifyEventAll( EV_USER + 40, [ sht2, delay ] );

				angle += 360 / way;
			}
                        		angle += 25.5;
			PlaySound("LenenShot1",92,0);
                        		wait( 8 );
	}

   }

              task Pattern4{ 
              let angle = 45;
              while( !Obj_IsDeleted( objBoss )){

	                		let way = 1;
			let speed = 1.4;
			let shote = 6;
			let delay = 10;
			loop( way ){

				let sx = ObjMove_GetX( objBoss );
				let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				let sht2 = TShotA2( sx, sy, speed, angle + 18, 0, speed, shote, delay );
				let sht3 = TShotA2( sx, sy, speed, angle + 36, 0, speed, shote, delay );
				let sht4 = TShotA2( sx, sy, speed, angle + 54, 0, speed, shote, delay );

				let sht5 = TShotA2( sx, sy, speed + 0.4, angle, 0, speed, shote, delay );
				let sht6 = TShotA2( sx, sy, speed + 0.4, angle + 18, 0, speed, shote, delay );
				let sht7 = TShotA2( sx, sy, speed + 0.4, angle + 36, 0, speed, shote, delay );
				let sht8 = TShotA2( sx, sy, speed + 0.4, angle + 54, 0, speed, shote, delay );

                                			ObjShot_SetSpellResist( sht1, true );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

                                			ObjShot_SetSpellResist( sht2, true );
				NotifyEventAll( EV_USER + 40, [ sht2, delay ] );

                                			ObjShot_SetSpellResist( sht3, true );
				NotifyEventAll( EV_USER + 40, [ sht3, delay ] );

                                			ObjShot_SetSpellResist( sht4, true );
				NotifyEventAll( EV_USER + 40, [ sht4, delay ] );

                                			ObjShot_SetSpellResist( sht5, true );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

                                			ObjShot_SetSpellResist( sht6, true );
				NotifyEventAll( EV_USER + 40, [ sht2, delay ] );

                                			ObjShot_SetSpellResist( sht7, true );
				NotifyEventAll( EV_USER + 40, [ sht3, delay ] );

                                			ObjShot_SetSpellResist( sht8, true );
				NotifyEventAll( EV_USER + 40, [ sht4, delay ] );

				angle += 360 / way;
			}
                        		angle += 9;
			PlaySound("LenenShot1",92,0);
                        		wait( 11 );
	}

   }

              task Pattern5{ 
              let angle = 40;
              while( !Obj_IsDeleted( objBoss )){

	                		let way = 1;
			let speed = 2.2;
			let shote = 289;
			let delay = 10;
			loop( way ){

				let sx = ObjMove_GetX( objBoss );
				let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				let sht2 = TShotA2( sx, sy, speed, angle + (120/5)*1, 0, speed, shote, delay );
				let sht3 = TShotA2( sx, sy, speed, angle + (120/5)*2, 0, speed, shote, delay );
				let sht4 = TShotA2( sx, sy, speed, angle + (120/5)*3, 0, speed, shote, delay );
				let sht5 = TShotA2( sx, sy, speed, angle + (120/5)*4, 0, speed, shote, delay );

                                			ObjShot_SetSpellResist( sht1, true );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

                                			ObjShot_SetSpellResist( sht2, true );
				NotifyEventAll( EV_USER + 40, [ sht2, delay ] );

                                			ObjShot_SetSpellResist( sht3, true );
				NotifyEventAll( EV_USER + 40, [ sht3, delay ] );

                                			ObjShot_SetSpellResist( sht4, true );
				NotifyEventAll( EV_USER + 40, [ sht4, delay ] );

                                			ObjShot_SetSpellResist( sht5, true );
				NotifyEventAll( EV_USER + 40, [ sht5, delay ] );


				angle += 360 / way;
			}
                        		angle -= 8;
			PlaySound("LenenShot1",92,0);
                        		wait( 11 );
	}

   }

              task Pattern6{ 
              let angle = 42;
              while( !Obj_IsDeleted( objBoss )){
              let speed = 3.5;
              loop( 2 ){

	                		let way = 1;
			let shote = 287;
			let delay = 10;
			loop( way ){

				let sx = ObjMove_GetX( objBoss );
				let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				let sht2 = TShotA2( sx, sy, speed - 0, angle + (96/4)*1, 0, speed, shote, delay );
				let sht3 = TShotA2( sx, sy, speed - 0, angle + (96/4)*2, 0, speed, shote, delay );
				let sht4 = TShotA2( sx, sy, speed - 0, angle + (96/4)*3, 0, speed, shote, delay );
				let sht5 = TShotA2( sx, sy, speed - 0, angle + (96/4)*4, 0, speed, shote, delay );

                                			ObjShot_SetSpellResist( sht1, true );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

                                			ObjShot_SetSpellResist( sht2, true );
				NotifyEventAll( EV_USER + 40, [ sht2, delay ] );

                                			ObjShot_SetSpellResist( sht3, true );
				NotifyEventAll( EV_USER + 40, [ sht3, delay ] );

                                			ObjShot_SetSpellResist( sht4, true );
				NotifyEventAll( EV_USER + 40, [ sht4, delay ] );

                                			ObjShot_SetSpellResist( sht5, true );
				NotifyEventAll( EV_USER + 40, [ sht5, delay ] );


				angle += 360 / way;
			}
			speed -= 0.9;
                        		if( wait( 0 ) ){ return; }
	}
                        		angle += 32;
			PlaySound("LenenShot1",92,0);
                        		wait( 12 );
	}

   }

              task Pattern7{ 
              while( !Obj_IsDeleted( objBoss )){

              			let speed = 3.5;
	                                	let way = 24;
                                                	let shote = 39;
              			let angle = GetAngleToPlayer( objBoss ) + 360 / way / 2;
			let delay = 20;

			loop( way ){

                      	                	let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, 0.5, angle, 0.02, speed, shote, delay );

                                			ObjShot_SetSpellResist( sht1, true );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle += 360 / way;

			}
			PlaySound("LenenShot1",92,0);
                        		wait( 30 );

	}

   }

              task Pattern8{ 
              let angle = rand( 0, 360 );
              while( !Obj_IsDeleted( objBoss )){

              			let speed = 4.1;
	                                	let way = 6;
                                                	let shote = 736;
			let delay = 20;

			loop( way ){

                      	                	let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, 0.5, angle, 0.02, speed, shote, delay );

                                		ObjShot_SetSpellResist( sht1, true );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle += 360 / way;

			}
			angle -= 36;
			PlaySound("LenenShot1",92,0);
                        		wait( 5 );

	}

   }

	task StartCountDown
	{
		wait((300*60) - 50 - (10*60));
		loop(5)
		{
			PlaySound("time1",100,0);
			wait(60);
		}
		loop(5)
		{
			PlaySound("time2",100,0);
			wait(60);
		}
	}

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

task TEnd{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
		EndBoss(1);
		yield;
		CloseScript(GetOwnScriptID());
	}