
#ScriptVersion[3]
#Title["TsurubamiS1"]
#Text["TsurubamiS1"]
#Player[DEFAULT]
#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("Doremy",true);
SetCommonData("Life",1);
SetCommonData("Bomb",1);
}

@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(1200);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(90);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(10000000);
	}
}

//----------------------------------------------------
task mainTask{
	StartCountDown;
	PlaySound("SpellStart",100,0);
	ObjMove_SetDestAtWeight(objBoss,stgx,130,10,7);
	Cutin("Explosive Card 'Demon-Repelling Explosive Tag'",11,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	wait(150);
	TShot1;
	DamageRateAtFrame(13,0,0);
	wait(1200);
	}
//----------------------------------------------------

task TShot1
{
	if( ObjEnemy_GetInfo( objBoss, INFO_LIFE ) == 1 ){ DeleteShotAll( TYPE_ALL, TYPE_IMMEDIATE ); }
	SheliaCheck;
	while( !Obj_IsDeleted( objBoss )){
	Pattern1;
	wait( 260 );
	Pattern2;
	wait( 160 );
	Pattern3;
	wait( 90 );
	Pattern4;
	wait( 180 );
	Pattern5;
	wait( 300 );
	}

}

              task Pattern1{ 
              let gap = 40;
              let sx1 = GetStgFrameWidth;
              let sx2 = 0;
              loop( GetStgFrameWidth / gap + 1 ){

			let angle = 90;
              			let speed = rand( 3, 4 );
	                                	let way = 1;
                                                	let shote = 97;
			let delay = 0;

			loop( way ){

                        		let sy = -10;
				
				let sht1 = TShotA2( sx1, sy, 0, angle, 0.04, speed, shote, delay );
				let sht2 = TShotA2( sx2, sy, 0, angle, 0.04, speed, shote, delay );
				ObjShot_SetSpellResist( sht1, true );
				ObjShot_SetSpellResist( sht2, true );

				angle += 360 / way;

			}
			sx1 -= gap;
			sx2 += gap;
			PlaySound("LenenShot1",92,0);
                        		if( wait( 15 ) ){ return; }
	}
   }

              task Pattern2{ 
              let gap = 10;
              let sx1 = GetStgFrameWidth + rand( -10, 10 );
              loop( GetStgFrameWidth / gap + 1 ){

			let angle = 90;
              			let speed = 4;
	                                	let way = 1;
                                                	let shote = 97;
			let delay = 0;

			loop( way ){

                        		let sy = -10;
				
				let sht1 = TShotA2( sx1, sy, 0, angle, 0.04, speed, shote, delay );
				ObjShot_SetSpellResist( sht1, true );

				angle += 360 / way;

			}
			sx1 -= gap;
			PlaySound("LenenShot1",92,0);
                        		if( wait( 0 ) ){ return; }
	}
   }

              task Pattern3{ 
              let gap = 12;
              let sx1 = GetStgFrameWidth + rand( -10, 10 );
              loop( GetStgFrameWidth / gap + 1 ){

			let angle = 90;
              			let speed = 4;
	                                	let way = 1;
                                                	let shote = 97;
			let delay = 0;

			loop( way ){

                        		let sy = -10;
				
				let sht1 = TShotA2( sx1, sy, 0, angle, 0.04, speed, shote, delay );
				ObjMove_SetAngle( sht1, GetAngleToPlayer( sht1 ));
				ObjShot_SetSpellResist( sht1, true );

				let sht2 = TShotA2( sx1, sy, 0, angle, 0.04, speed, shote, delay );
				ObjMove_SetAngle( sht2, GetAngleToPlayer( sht2 ) + 40 );
				ObjShot_SetSpellResist( sht2, true );

				let sht3 = TShotA2( sx1, sy, 0, angle, 0.04, speed, shote, delay );
				ObjMove_SetAngle( sht3, GetAngleToPlayer( sht3 ) - 40 );
				ObjShot_SetSpellResist( sht3, true );

				angle += 360 / way;

			}
			sx1 -= gap;
			PlaySound("LenenShot1",92,0);
                        		if( wait( 3 ) ){ return; }
	}
   }

              task Pattern4{ 
              let gap = 12;
              let sx1 = rand( -10, 10 );
              loop( GetStgFrameWidth / gap + 1 ){

			let angle = 90;
              			let speed = 4;
	                                	let way = 1;
                                                	let shote = 97;
			let delay = 0;

			loop( way ){

                        		let sy = -10;
				
				let sht1 = TShotA2( sx1, sy, 0, angle, 0.04, speed, shote, delay );
				ObjMove_SetAngle( sht1, GetAngleToPlayer( sht1 ));
				ObjShot_SetSpellResist( sht1, true );

				let sht2 = TShotA2( sx1, sy, 0, angle, 0.04, speed, shote, delay );
				ObjMove_SetAngle( sht2, GetAngleToPlayer( sht2 ) + 40 );
				ObjShot_SetSpellResist( sht2, true );

				let sht3 = TShotA2( sx1, sy, 0, angle, 0.04, speed, shote, delay );
				ObjMove_SetAngle( sht3, GetAngleToPlayer( sht3 ) - 40 );
				ObjShot_SetSpellResist( sht3, true );

				angle += 360 / way;

			}
			sx1 += gap;
			PlaySound("LenenShot1",92,0);
                        		if( wait( 3 ) ){ return; }
	}
   }

              task Pattern5{ 
              loop( 55 ){

			let angle = 90;
              			let speed = 4;
	                                	let way = 1;
                                                	let shote = 97;
			let delay = 0;

			loop( way ){

              			let sx1 = rand( 0, GetStgFrameWidth );
                        		let sy = -10;
				
				let sht1 = TShotA2( sx1, sy, 0, angle, 0.04, speed, shote, delay );
				ObjShot_SetSpellResist( sht1, true );

				angle += 360 / way;

			}
			PlaySound("LenenShot1",92,0);
                        		if( wait( 5 ) ){ return; }
	}
   }

	task PatternBomb( obj, rad, roop ){
	while( GetDistance( GetPlayerX, GetPlayerY, ObjMove_GetX( obj ), ObjMove_GetY( obj ) ) > rad ){ yield; }
	PatternBomb1( obj );
	PatternBomb2( obj );
	PatternBomb3( obj, roop );
	Obj_Delete( obj );
	}


	task PatternBomb1( obj ){ 
                	loop( 1 ){

                                              let speed = 8;
	                          let way = 26;
                                              let shote = 532;
              		      let angle = rand( 0, 360 );
	                          let delay = 0;

			loop( way ){

                      	                    let sx = ObjMove_GetX( obj );
                        		let sy = ObjMove_GetY( obj );
				
				let sht1 = TShotA2( sx, sy, speed, angle, -0.35, 0, shote, delay );
				DelayDeletes( sht1, 60 );
                                			ObjShot_SetSpellResist( sht1, true );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle += 360 / way;

			}
			PlaySound("stars",92,0);

	}

   }
	task PatternBomb2( obj ){ 
                	loop( 1 ){

	                          let way = 30;
                                              let shote = 564;
	                          let delay = 0;

			loop( way ){
                                                            let speed = rand( 3, 8 );
              		      	let angle = rand( 0, 360 );
                      	                    let sx = ObjMove_GetX( obj );
                        		let sy = ObjMove_GetY( obj );
				
				let sht1 = TShotA2( sx, sy, speed, angle, -0.35, 0, shote, delay );
				DelayDeletes( sht1, 60 );
                                			ObjShot_SetSpellResist( sht1, true );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle += 360 / way;

			}
			PlaySound("stars",92,0);

	}

   }

	task PatternBomb3( obj, roop ){ 
                	loop( 1 ){

	                          let way = roop;
                                              let shote = 17;
	                          let delay = 0;

			loop( way ){
                                                            let speed = rand( 0.8, 1.6 );
              		      	let angle = rand( 0, 360 );
                      	                    let sx = ObjMove_GetX( obj );
                        		let sy = ObjMove_GetY( obj );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
                                			ObjShot_SetSpellResist( sht1, true );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle += 360 / way;

			}
	 	PlaySound("stars",92,0);
	}

   }

task DelayDeletes( obj, time ){
wait( time );
ObjShot_FadeDelete( obj );
}

             task SheliaCheck{
	while( !Obj_IsDeleted( objBoss )){	
            	let shotarray = GetShotIdInCircleA2( GetPlayerX, GetPlayerY, rand( 120, 140 ), TARGET_ALL );
             	ascent( i in 0..length( shotarray )){
             	if( ObjShot_GetImageID( shotarray[ i ] ) == 97 ){ 	
	PatternBomb1( shotarray[ i ] );
	PatternBomb2( shotarray[ i ] );
	PatternBomb3( shotarray[ i ], 4 );
	Obj_Delete( shotarray[ i ] ); }
                                                                   }
		yield;
	              }
	}

	task StartCountDown
	{
		wait((90*60) - (10*60));
		loop(10)
		{
			PlaySound("time",100,0);
			wait(60);
		}

	}


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

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