
#Title["Cha10S3"]
#Text["wat"]
#Player[DEFAULT]
#System["./system/Default_System.txt"]
#Background["./BG22hu.txt"]
#include"./Functions/Index.txt"
#include"./SetBoss.txt"
#include"./Shot/AllStarShot_Const_2.dnh"
#include"./system/Default_Effect.Txt"
#include"./BGMLoad.txt"

let objBoss;
//let objBossIyo;
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 dir=GetCurrentScriptDirectory();
let obj=ObjEnemyBossScene_Create();
let color = [276,277,278];
let color2 = [51,53,55];
let dcolor = [308,309,310];
@Initialize
{
SetBoss("Doremy",true);
//SetBossIyo("Doremy",true);
SetCommonData("Life",2);
SetCommonData("Bomb",1);
SetCommonData("LenenSpellcut",[55,55,255]);
SetCommonData("SpellBarcl",[55,55,255]);
SetCommonData("CutChar",GCSD ~ "./img/cut/ra.png");
SetCommonData("CutCharRect",[0,0,512,540]);
SetCommonData("MCircleColor",[55,55,255]);
SetCommonData("Boss",1);
//MusicPlay;
mainTask;
}

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

}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(4200);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(50);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(500000);
	}
}

let musicplayer = false;
task MusicPlay
{
	loop
	{
		let music1 = ObjSound_Create;
		music1 = ObjSound_Create;
		ObjSound_Load(music1, GetCurrentScriptDirectory ~ "LenenBGM/BOSS_Tenkai.ogg");
		ObjSound_SetSoundDivision(music1, SOUND_BGM);
		ObjSound_SetRestartEnable(music1, true);
		ObjSound_SetLoopEnable(music1, true);	
		ObjSound_SetLoopSampleCount(music1,1499633,5631073);		
		ObjSound_Play(music1);
		
		ObjSound_SetVolumeRate(music1,50);
		while(!musicplayer)
		{
	
			yield;
		}
		Obj_Delete(music1);
		while(musicplayer)
		{
			yield;
		}
	}
}

//----------------------------------------------------
task mainTask{
	//StartCountDown;
	//PlaySound("SpellStart",100,0);
	ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2,+GetStgFrameHeight/2-50,20,20);
	SizeCircle;
	Cutin("Back Storm'Daybreak Rain Storm'",15,"SHINKI",232);
	ObjEnemyBossScene_StartSpell(objScene);
	wait(220);
	DamageRateAtFrame(80,20,0);
	TShot1;
	}
	
//----------------------------------------------------
let t = 0;
let t2 = 0;

task TShot1
{
	
	//attack(5000,1);
	yao;
	/*yao2;
	yao3;*/
	//Moveto;
	//Iyo;
	//Tsu;
	//hooaka;
	//hooaka2;
	//hibby;

}

task CheckBounceManyTimes(obj,time)
{
   while(!Obj_IsDeleted(obj) && ObjMove_GetX(obj)>0 && ObjMove_GetX(obj)<GetStgFrameWidth && ObjMove_GetY(obj)>0 && ObjMove_GetY(obj)<GetStgFrameHeight){yield;}
   if(ObjMove_GetX(obj)<0 || ObjMove_GetX(obj)>GetStgFrameWidth)
   {ObjMove_SetAngle(obj,180-ObjMove_GetAngle(obj));}
   if(ObjMove_GetY(obj)<0 || ObjMove_GetY(obj)>GetStgFrameHeight-30)
   {ObjMove_SetAngle(obj,-ObjMove_GetAngle(obj));}
 
   time--;
   yield;
   if(time>0){CheckBounceManyTimes(obj,time);}
}

task yao{
while(!Obj_IsDeleted( objBoss )){
              let angle = 90;
              			let speed = 3;
	                                	let way = 4;
                                                	let shote = 533;
                                                	let t = 0;
loop(1)
{
			let sx = ObjMove_GetX( objBoss );
            let sy = ObjMove_GetY( objBoss );
			let rx = rand(0,GetStgFrameWidth);
			let delay = 0;
			loop( way ){
                      	                	
								let sht = [1,3,4,5,7,9,12,14,15];
								
				
				ascent(i in -0..1)
				{
				//attack(5,1);
				let sht1 = TShotA1( sx, sy, speed, angle+t*11, 324, 20 );
				ObjMove_AddPatternA2( sht1, 0, 0, NO_CHANGE, 0.05, 0, 5 );
				ObjMove_AddPatternA2( sht1, 150, NO_CHANGE, NO_CHANGE, 0.1, 2, 20 );
				//spin(sht1);
				PatternMonochrome2( sht1 ,angle,5,10);
				//ObjRender_SetColor(sht2,0,0,0);
				ObjShot_SetSpellResist( sht1, true );
				//ObjShot_SetSpellResist( sht2, true );
				let seel = rand( 2, 3 );
				let ux = seel*cos( angle-t*7 );
                let uy = seel*sin( angle-t*7 );
				//Rotate( sht1, 2, 50 );
				//ObjMove_AddPatternB2( sht2, 50 , ux, uy, rand(-0.1, 0.1 ), 0, rand(-20, 20 ), 0 );
				//CheckBounceShot(sht1,0, speed, angle, 533, delay);
				Rotate( sht1, 3, 150 );
				//Rotate( sht2, -2, 200 );
				//ObjCrLaser_SetTipDecrement( sht1, 0 );
				ObjRender_SetBlendType(sht1,BLEND_ADD_ARGB);
				//SnakeWave(sht1,90,50,60);
				PlaySound("LenenShot2",92,0);
				}
				

				angle += 360 / way;
				
			}
			
			wait( 0 );
			t++;
			t2++;
			}
			wait( 100 );
			ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2+rand(-1,1)*100,GetStgFrameHeight/2-50+rand(-1,1)*20,10,10);
			wait( 50 );
			
	}
	
	}
	
task yao2{
while(!Obj_IsDeleted( objBoss )){
              let angle = 270+rand(-1,1)*50;
              			let speed = 1;
	                                	let way = 1;
                                                	let shote = 533;
loop(1)
{
			let sx = ObjMove_GetX( objBoss );
            let sy = ObjMove_GetY( objBoss );
			let rx = rand(0,GetStgFrameWidth);
			let delay = 0;
			loop( way ){
                      	                	
								let sht = [1,3,4,5,7,9,12,14,15];
								
				
				ascent(i in -2..1)
				{
				//attack(5,1);
				let sht1 = TShotA1( sx, sy-60, speed+i*1, angle+rand(-1,1)*60, 46, 10 );
				ObjMove_AddPatternA2( sht1, 0, 2, NO_CHANGE, 0.1, 0, 10 );
				//ObjMove_AddPatternA2( sht1, rand(65,100), NO_CHANGE, NO_CHANGE, 0.02, rand(-1,1)*0.3, 10 );
				//ObjMove_AddPatternA2( sht2, 20, NO_CHANGE, NO_CHANGE, 0.1, 0, 5 );
				//spin(sht1);
				//PatternMonochrome2( sht1 ,angle,5,10);
				//ObjRender_SetColor(sht2,0,0,0);
				ObjShot_SetSpellResist( sht1, true );
				let seel = rand( 2, 3 );
				let ux = seel*cos( angle-t2*13 );
                let uy = seel*sin( angle-t2*13 );
				//Rotate( sht1, 2, 50 );
				//ObjMove_AddPatternB2( sht1, 50 , ux, uy, 0, rand(0.01, 0.15 ), 0, 7 );
				//CheckBounceShot(sht1,0, speed, angle, 533, delay);
				//Rotate( sht1, 5+i*2, 50 );
				//ObjCrLaser_SetTipDecrement( sht1, 0 );
				ObjRender_SetBlendType(sht1,BLEND_ALPHA);
				//SnakeWave(sht1,90,50,60);
				PlaySound("LenenShot1",42,0);
				}
				

				angle += 360 / way;
				
			}
			
			wait( 0 );
			t2++;
			}
			wait( 1 );
			//ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2+rand(-1,1)*100,GetStgFrameHeight/2-100+rand(-1,1)*20,20,20);
			//wait( 50 );
			
	}
	
	}
	
task yao3{
while(!Obj_IsDeleted( objBoss )){
              let angle = 90+rand(-1,1)*50;
              			let speed = 1;
	                                	let way = 1;
                                                	let shote = 533;
loop(1)
{
			let sx = ObjMove_GetX( objBoss );
            let sy = ObjMove_GetY( objBoss );
			let rx = rand(0,GetStgFrameWidth);
			let delay = 0;
			loop( way ){
                      	                	
								let sht = [1,3,4,5,7,9,12,14,15];
								
				
				ascent(i in -0..1)
				{
				//attack(5,1);
				let sht1 = TShotA1( sx, sy-60, speed+i*1, angle+rand(-1,1)*60, 46, 10 );
				ObjMove_AddPatternA2( sht1, 0, 2, NO_CHANGE, 0.05, 0, 3 );
				//ObjMove_AddPatternA2( sht1, rand(65,100), NO_CHANGE, NO_CHANGE, 0.02, rand(-1,1)*0.3, 10 );
				//ObjMove_AddPatternA2( sht2, 20, NO_CHANGE, NO_CHANGE, 0.1, 0, 5 );
				//spin(sht1);
				//PatternMonochrome2( sht1 ,angle,5,10);
				//ObjRender_SetColor(sht2,0,0,0);
				ObjShot_SetSpellResist( sht1, true );
				let seel = rand( 2, 3 );
				let ux = seel*cos( angle-t2*13 );
                let uy = seel*sin( angle-t2*13 );
				//Rotate( sht1, 2, 50 );
				//ObjMove_AddPatternB2( sht1, 50 , ux, uy, 0, rand(0.01, 0.15 ), 0, 7 );
				//CheckBounceShot(sht1,0, speed, angle, 533, delay);
				//Rotate( sht1, 5+i*2, 50 );
				//ObjCrLaser_SetTipDecrement( sht1, 0 );
				ObjRender_SetBlendType(sht1,BLEND_ALPHA);
				//SnakeWave(sht1,90,50,60);
				PlaySound("LenenShot1",42,0);
				}
				

				angle += 360 / way;
				
			}
			
			wait( 0 );
			t2++;
			}
			wait( 10 );
			//ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2+rand(-1,1)*100,GetStgFrameHeight/2-100+rand(-1,1)*20,20,20);
			//wait( 50 );
			
	}
	
	}
	
task PatternMonochrome2( obj ,angle,speed,wet){ 
wait(20);
              while( !Obj_IsDeleted( obj ) && !Obj_IsDeleted( objBoss )){

	                                let way = 1;
                                                    let shote = 259;
		            let delay = 20;

			loop( way ){
			
                                                    	let speed = 2;
			//let angle = rand( 0, 360 );
                      	                    let sx = ObjMove_GetX( obj );
                        		let sy = ObjMove_GetY( obj );
				ascent(i in 0..1)
				{
				let sht1 = TShotA1( sx, sy, speed, ObjMove_GetAngle(obj)+180+rand(-1,1)*2, shote, delay );
				ObjMove_AddPatternA2( sht1, 0, 0, NO_CHANGE, 0.02, 0, 2 );
				//PatternMonochrome3( sht1 ,rand(0,360),5,12);
				//ObjMove_AddPatternA2( sht1, 50, NO_CHANGE, angle, i/100, 0, 100 );
				//ObjRender_SetBlendType( sht1, BLEND_ALPHA );
				//ObjRender_SetColor( sht1, 0, 0, 0 );
				//ObjRender_SetBlendType(sht1,BLEND_ADD_ARGB);
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );
				}
				angle -= 360 / way;
				t++;

			}
			PlaySound("LenenShot1",62,0);
                        		if( wait( 7 ) ){ return; }

	}

   }
   
task PatternMonochrome3( obj ,angle,speed,wet){ 
              while( !Obj_IsDeleted( obj ) && !Obj_IsDeleted( objBoss )){

	                                let way = 3;
                                                    let shote = 65;
		            let delay = 0;

			loop( way ){
			
                                                    	//let speed = 10;
			//let angle = rand( 0, 360 );
                      	                    let sx = ObjMove_GetX( obj );
                        		let sy = ObjMove_GetY( obj );
				ascent(i in 0..1)
				{
				let sht1 = TShotA1( sx, sy, speed, angle,  shote, delay );
				ObjMove_AddPatternA2( sht1, 10, 2, NO_CHANGE, 0.0, 0, 100 );
				//ObjMove_AddPatternA2( sht1, 50, NO_CHANGE, angle, i/100, 0, 100 );
				ObjRender_SetBlendType( sht1, BLEND_ALPHA );
				//ObjRender_SetColor( sht1, 0, 0, 0 );
				//ObjRender_SetBlendType(sht1,BLEND_ADD_ARGB);
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );
				}
				angle -= 360 / way;
				t++;

			}
			PlaySound("LenenShot1",92,0);
                        		if( wait( wet+rand(1,2) ) ){ return; }

	}

   }
	
task CheckBounceShot(obj,time, speed, angle, shote, delay)
{
   while(!Obj_IsDeleted(obj) && !Obj_IsDeleted( objBoss ) && ObjMove_GetX(obj)>0 && ObjMove_GetX(obj)<GetStgFrameWidth && ObjMove_GetY(obj)>0 && ObjMove_GetY(obj)<GetStgFrameHeight-50){yield;}

   if(ObjMove_GetX(obj)<0 || ObjMove_GetX(obj)>GetStgFrameWidth)
   {
   ascent(i in 0..5)
   {
   let ux = rand( 3, 10 )*cos( 180-angle );
   let uy = rand( 3, 10 )*sin( 180-angle );
   let shtB = TShotA1( ObjRender_GetX(obj), ObjRender_GetY(obj), speed, angle, shote, 20 );
   ObjMove_AddPatternB2( shtB, 0 , ux, uy, 0, rand(0.1, 0.25 ), 50, 50 );
   spin(shtB);
   ObjShot_SetGraphic( shtB, 516);
   }
   }
   
   if( ObjMove_GetY(obj)<0 || ObjMove_GetY(obj)>GetStgFrameHeight-50 )
   {
   ascent(i in 0..1)
   {
   let ux = rand( 3, 7 )*cos( 180-angle );
   let uy = rand( 3, 7 )*sin( 180-angle );
   let shtB = TShotA1( ObjRender_GetX(obj), ObjRender_GetY(obj), speed, angle, shote, 0 );
   ObjMove_AddPatternB2( shtB, 0 , ux, uy, 0, rand(0.05, 0.35 ), 50, 50 );
   ObjShot_SetSpellResist( shtB, true );
   spin(shtB);
   ObjShot_SetGraphic( shtB, shote);
   }
   }
   
  
   
 
   time--;
   yield;
   if(time>0){CheckBounceManyTimes(obj,time);}
}

	
task spin(obj)
{
let sp = 0;
while( !Obj_IsDeleted( obj )){
ObjRender_SetAngleZ(obj,sp*12);
sp++;
wait( 1 );
}
}

task spin2(obj)
{
let sp = 0;
while( !Obj_IsDeleted( obj )){
ObjRender_SetAngleZ(obj,90+sp*12);
sp++;
wait( 1 );
}
}


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

	}

task SnakeWave(obj,angle,amplitude,omega)
{
   let count = 0;
   while(!Obj_IsDeleted(obj))
   {
         ObjMove_SetAngle(obj,angle+amplitude*sin(count*omega));
         count += 1;
         wait( 2 );
   }
}
	
	task Rotate( obj, ang, t ){
	ObjMove_SetAngularVelocity( obj, ang );
	wait( t );
	ObjMove_SetAngularVelocity( obj, 0 );
	}
	
	task RotateMT( obj, ang, ang2, t ){
	ObjMove_SetAngularVelocity( obj, ang );
	wait( t );
	ObjMove_SetAngularVelocity( obj, ang2 );
	}
	
//----------------------------------------------------

task SizeCircle
{
	ascent(i in 0..1)
	{
		//SetCommonData("CircleSize",sin(i*1.5));
		magiccircle(objBoss,10,2);
		yield;
	}
}	

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