
#ScriptVersion[3]
#Title["KurojiN4"]
#Text["KurojiN4"]
#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 objScene=GetEnemyBossSceneObjectID();
let color = [0,0];
@Initialize
{
SetBoss("Doremy",false);
}

@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(4200);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(55);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(0);
	}
}

//----------------------------------------------------
task mainTask{
	StartCountDown;
	ObjMove_SetDestAtWeight(objBoss,stgx,150,10,10);
	SetCommonData("Scroll",1);
	SetCommonData("ForceLifebar",1);
	wait(180);
	DamageRateAtFrame(88,5,0);
	TShot1;
	SetCommonData("ForceLifebar",0);
	}
//----------------------------------------------------

task TShot1
{
	KurojiNon1;
	HelpYou;
}

	task HelpYou{
	while( !Obj_IsDeleted( objBoss )){ yield; }
	DeleteShotAll( TYPE_ALL, TYPE_ITEM );
	}

              task KurojiNon1{ 
              let angle = 0;
              while( !Obj_IsDeleted( objBoss )){
              let speed = 1.9;

	                                let way = 2;
                                                    let shote = 53;
		            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 );
				ObjShot_SetSpellResist( sht1, true );
				ObjRender_SetAlpha( sht1, 0 );
				PatternKurojiNon15( sht1 );
				Reflect2( sht1, 0, 0, NO_CHANGE );

				angle += 360 / way;

			}
			TMovement( 60, 5, 5 );
			PlaySound("LenenShot1",92,0);
                       		wait( 70 );

	}

   }

              task PatternKurojiNon15( obj ){ 

	                                let way = 16;
                                                    let shote = 53;
		            let delay = 10;
                                                    let speed = 4.8;
              		            let angle1 = ObjMove_GetAngle( obj );
              		            let angle2 = ObjMove_GetAngle( obj );

			loop( way ){

                      	                	let sx = ObjMove_GetX( obj );
                        		let sy = ObjMove_GetY( obj );
				
				let sht1 = TShotA2( sx, sy, speed, angle1, 0, speed, shote, delay );
				let sht2 = TShotA2( sx, sy, speed, angle2, 0, speed, shote, delay );

				ObjShot_SetSpellResist( sht1, true );
				ObjShot_SetSpellResist( sht2, true );

				StickyX( obj, sht1 );
				StickyX( obj, sht2 );

				Reflect2( sht1, 0, 0, NO_CHANGE );
				Reflect2( sht2, 0, 0, NO_CHANGE );

				YouDieMeDie( obj, sht1 );
				YouDieMeDie( obj, sht2 );

				angle1 += 45 / way;
				angle2 -= 45 / way;

			}
   }

	task YouDieMeDie( main, sab ){
	while( !Obj_IsDeleted( main )){ yield; }
	Obj_Delete( sab );
	}

	task StickyX( main, sab ){
	while( !Obj_IsDeleted( main )){
	let x = ObjMove_GetX( main );
	ObjMove_SetX( sab, x );
	yield;
	}
	}

	task Reflect2( obj, acceleration, angular, v ){
	while( !Obj_IsDeleted( obj ) && ObjMove_GetX( obj ) > 0 && ObjMove_GetX( obj ) < GetStgFrameWidth && ObjMove_GetY( obj ) > 0 ){ yield; }

   	if(ObjMove_GetX(obj)<0 || ObjMove_GetX(obj)>GetStgFrameWidth)
   	{ ObjMove_AddPatternA2( obj, 0, NO_CHANGE, 180-ObjMove_GetAngle( obj ), acceleration, angular, v ); }

	}

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

	}

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

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