
#ScriptVersion[3]
#Title["KurojiS2"]
#Text["KurojiS2"]
#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",2);
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(1250);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(60000000);
	}
}

//----------------------------------------------------
task mainTask{
	StartCountDown;
	PlaySound("SpellStart",100,0);
	ObjMove_SetDestAtWeight(objBoss,stgx,stgy,10,7);
	Cutin("DNA 'Chromosomal Inversion'",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	wait(120);
	DamageRateAtFrame(26,5,0);
	TShot1;
	}
//----------------------------------------------------

task TShot1
{
	if( ObjEnemy_GetInfo( objBoss, INFO_LIFE ) == 1 ){ DeleteShotAll( TYPE_ALL, TYPE_IMMEDIATE ); }
	FlipCheck;
	Virus;

}

              task Virus{ 
              while( !Obj_IsDeleted( objBoss )){
              ascent(i in 0..75){

			let shote = 51;
                                                	let speed = 6;
	                                	let way = 1;
              			let angle1 = GetAngleToPlayer( objBoss );
			let delay = 10;
			let sx = ObjMove_GetX( objBoss );
			let sy = ObjMove_GetY( objBoss );

			loop( way ){
				
				let sht1 = TShotA2( sx, sy, speed, angle1, 0, speed, shote, delay );
				let sht2 = TShotA2( sx, sy, speed, angle1, 0, speed, shote, delay );
				ConfusedWave( sht1, angle1 + 140 + 180, 60, 20, i );
				ConfusedWave( sht2, angle1 - 140 + 180, -60, 20, i );

				let sht3 = TShotA2( sx, sy, speed, angle1 - 240, 0, speed, shote, delay );
				let sht4 = TShotA2( sx, sy, speed, angle1 - 240, 0, speed, shote, delay );
				ConfusedWave( sht3, angle1 + 140 + 180, -60, 20, i );
				ConfusedWave( sht4, angle1 - 140 + 180, 60, 20, i );

				let sht5 = TShotA2( sx, sy, speed, angle1, 0, speed, shote, delay );
				let sht6 = TShotA2( sx, sy, speed, angle1, 0, speed, shote, delay );
				ConfusedWave( sht5, angle1 + 60 + 180, 60, 20, i );
				ConfusedWave( sht6, angle1 - 60 + 180, -60, 20, i );

				let sht7 = TShotA2( sx, sy, speed, angle1 - 240, 0, speed, shote, delay );
				let sht8 = TShotA2( sx, sy, speed, angle1 - 240, 0, speed, shote, delay );
				ConfusedWave( sht7, angle1 + 60 + 180, -60, 20, i );
				ConfusedWave( sht8, angle1 - 60 + 180, 60, 20, i );


				angle1 += 360 / way;

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

	}
                        		wait( 200 );

	}
}


task ConfusedWave(obj,angle,amplitude,omega,n)
{
   let count = 0;
   while(!Obj_IsDeleted(obj) && n<75)
   {
         ObjMove_SetAngle(obj,angle+amplitude*sin(count*omega));
         n += 1;
         count += 1;
         wait( 2 );
   }
}

task FlipCheck{
wait( 150 );
while(!Obj_IsDeleted( objBoss )){
	
PlaySound("LenenBulletWave",92,0);
let shotarray = GetShotIdInCircleA2( GetPlayerX, GetPlayerY, 1000, TARGET_ALL );
let a = 0;
let ang;


ascent( i in 0..length( shotarray )){

     ang = ObjMove_GetAngle( shotarray [ i ] );
     let r = [ -ang, ang ];
     let spe = ObjMove_GetSpeed( shotarray[ i ] );
     let anz = ObjRender_GetAngleZ( shotarray[ i ] );

if( ObjShot_GetImageID( shotarray[ i ] ) == 51 ){ 
     let x;
     let y;
     if( ObjMove_GetY( shotarray[ i ] ) < stgy ){ y = stgy*2 - ObjMove_GetY( shotarray[ i ] );  
				      ObjRender_SetAngleZ( shotarray[ i ], -ang + 90 );
				      ObjShot_SetGraphic( shotarray[ i ], 49 );}
     if( ObjMove_GetX( shotarray[ i ] ) < stgx ){ x = stgx*2 - ObjMove_GetX( shotarray[ i ] );  
				      ObjRender_SetAngleZ( shotarray[ i ], -ang + 90 );
				      ObjShot_SetGraphic( shotarray[ i ], 49 );}
     if( ObjMove_GetY( shotarray[ i ] ) > stgy ){ y = stgy*2 - ObjMove_GetY( shotarray[ i ] );  
				      ObjRender_SetAngleZ( shotarray[ i ], -ang + 90 );
				      ObjShot_SetGraphic( shotarray[ i ], 49 );}
     if( ObjMove_GetX( shotarray[ i ] ) > stgx ){ x = stgx*2 - ObjMove_GetX( shotarray[ i ] );  
				      ObjRender_SetAngleZ( shotarray[ i ], -ang + 90 );
				      ObjShot_SetGraphic( shotarray[ i ], 49 );}
     ObjMove_SetDestAtFrame( shotarray[ i ], x, y, 60 ); 
     Continue( shotarray[ i ], 60, 0.9, -ang , 0, 0.9, 53 );}

                                                                   }
		wait( 350 );
	              }
	}

	function GetDotAngle(x1,y1,x2,y2){
	let angle=atan2(y1-y2,x1-x2);
	return angle;

}
task Continue( obj, t, speed1, angle, acc, speed2, shote ){
wait( t );
PlaySound("LenenBulletWave",92,0);
ObjMove_AddPatternA3( obj, 0, speed1, angle, acc, 0, speed2, shote );
ObjRender_SetAngleZ( obj, 0 );

}

	task StartCountDown
	{
		wait((60*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());
	}